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

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

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

public class GeometricPolyLineTransformImpl implements GeometricTransform<GeometricPolyLine> {

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

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

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