package com.fdkankan.dxf.parse.transformation.impl;

import com.fdkankan.dxf.parse.model.GeometricModel;
import com.fdkankan.dxf.parse.model.entities.GeometricLine;
import com.fdkankan.dxf.parse.transformation.GeometricTransform;

import java.util.ArrayList;
import java.util.List;

public class GeometricLineTransformImpl implements GeometricTransform<GeometricLine> {

    /**
     * 实例对象
     */
    private static GeometricTransform geometricTransform;


    /**
     * 采用单例模式
     *
     * @return 返回实例对象
     */
    public static GeometricTransform getSingleInstance() {
        if (geometricTransform == null) {
            synchronized (GeometricLineTransformImpl.class) {
                if (geometricTransform == null) {
                    geometricTransform = new GeometricLineTransformImpl();
                }
            }
        }
        return geometricTransform;
    }

    /**
     * 几何线的转换
     *
     * @param objectList 转换的数据
     * @return List<GeometricLine>
     */
    @Override
    public List<GeometricLine> transform(List<GeometricModel> objectList) {
        List<GeometricLine> lineList = new ArrayList<>();;
        if (!(objectList == null || objectList.isEmpty())) {
            for (GeometricModel object : objectList) {
                if (object instanceof GeometricLine) {
                    lineList.add((GeometricLine) object);
                }
            }
        }
        return lineList;
    }
}
