52 lines
1.3 KiB
Java
52 lines
1.3 KiB
Java
package de.ph87.electro.circuit.dto;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
|
import de.ph87.electro.circuit.part.Orientation;
|
|
import de.ph87.electro.circuit.part.Part;
|
|
import de.ph87.electro.circuit.part.impl.*;
|
|
import lombok.Getter;
|
|
import lombok.NoArgsConstructor;
|
|
import lombok.ToString;
|
|
|
|
import java.util.List;
|
|
|
|
@Getter
|
|
@ToString
|
|
@NoArgsConstructor
|
|
@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS)
|
|
public class PartDto {
|
|
|
|
private String uuid;
|
|
|
|
private String name;
|
|
|
|
private int x;
|
|
|
|
private int y;
|
|
|
|
private Orientation orientation;
|
|
|
|
private List<JunctionDto> junctions;
|
|
|
|
protected PartDto(final Part part) {
|
|
this.uuid = part.getUuid();
|
|
this.name = part.getName();
|
|
this.x = part.getX();
|
|
this.y = part.getY();
|
|
this.orientation = part.getOrientation();
|
|
this.junctions = part.getJunctions().stream().map(JunctionDto::new).toList();
|
|
}
|
|
|
|
public static PartDto of(final Part abstractPart) {
|
|
return switch (abstractPart) {
|
|
case final PartBattery part -> new PartBatteryDto(part);
|
|
case final PartLight part -> new PartLightDto(part);
|
|
case final PartSwitch1x1 part -> new PartSwitch1x1Dto(part);
|
|
case final PartSwitch1x2 part -> new PartSwitch1x2Dto(part);
|
|
case final PartSwitchCross part -> new PartSwitchCrossDto(part);
|
|
case null, default -> throw new RuntimeException();
|
|
};
|
|
}
|
|
|
|
}
|