something for lab 6... i want to sleep
This commit is contained in:
parent
9c4cdb512f
commit
c958114545
@ -1,4 +1,55 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ExtentionDrawingLoco {
|
||||
public static DrawingLocomotive CreateDrawingLocomotive(String info, char separatorForObject, int width, int height)
|
||||
{
|
||||
String[] strs = info.split(String.valueOf(separatorForObject));
|
||||
|
||||
if(strs.length == 3){
|
||||
return new DrawingLocomotive(
|
||||
Integer.parseInt(strs[0]),
|
||||
Integer.parseInt(strs[1]),
|
||||
Color.getColor(strs[2]),
|
||||
width,
|
||||
height
|
||||
);
|
||||
}
|
||||
|
||||
if(strs.length == 6){
|
||||
return new DrawingElectricLocomotive(
|
||||
Integer.parseInt(strs[0]),
|
||||
Integer.parseInt(strs[1]),
|
||||
Color.getColor(strs[2]),
|
||||
Color.getColor(strs[3]),
|
||||
strs[4].equals(true),
|
||||
strs[5].equals(true),
|
||||
width,
|
||||
height
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String GetDataForSave(DrawingLocomotive drawingLoco, char separatorForObject)
|
||||
{
|
||||
var loco = drawingLoco.EntityLocomotive;
|
||||
if (loco == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String str = loco.Speed + separatorForObject + loco.Weight + separatorForObject + loco.BodyColor.toString();
|
||||
if (!(loco instanceof EntityElectricLocomotive electroLoco))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
return str + separatorForObject + electroLoco.AdditionalColor.toString() + separatorForObject +
|
||||
electroLoco.Horns + separatorForObject + electroLoco.SeifBatteries;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ public class LocomotiveGenericCollection<T extends DrawingLocomotive,U extends I
|
||||
_collection = new SetGeneric<T>(width*height);
|
||||
}
|
||||
|
||||
public Iterable<T> GetLocomotives(){
|
||||
return _collection.GetEnumerator();
|
||||
}
|
||||
|
||||
/// Перегрузка оператора сложения
|
||||
//да емае, почему в яве все по-другому?...
|
||||
public int AddOverload(T obj){
|
||||
|
@ -1,53 +1,66 @@
|
||||
package ProjectElectricLocomotive;
|
||||
|
||||
import javax.xml.crypto.dsig.keyinfo.KeyValue;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class LocomotivesGenericStorage {
|
||||
|
||||
public final char _separatorForKeyValue = '|';
|
||||
public final char _separatorRecords = ';';
|
||||
public final char _separatorForObject = ':';
|
||||
final HashMap<String, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotiveStorage;
|
||||
public List<String> Keys()
|
||||
{
|
||||
|
||||
public List<String> Keys() {
|
||||
return _locomotiveStorage.keySet().stream().toList();
|
||||
}
|
||||
|
||||
private final int _pictureWidth;
|
||||
private final int _pictureHeight;
|
||||
|
||||
public LocomotivesGenericStorage(int pictureWidth, int pictureHeight) {
|
||||
_locomotiveStorage = new HashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(String name)
|
||||
{
|
||||
if (!(_locomotiveStorage.containsKey(name)))
|
||||
{
|
||||
public void AddSet(String name) {
|
||||
if (!(_locomotiveStorage.containsKey(name))) {
|
||||
_locomotiveStorage.put(name, new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
|
||||
public void DelSet(String name)
|
||||
{
|
||||
if (_locomotiveStorage.keySet().contains(name))
|
||||
{
|
||||
public void DelSet(String name) {
|
||||
if (_locomotiveStorage.keySet().contains(name)) {
|
||||
_locomotiveStorage.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> get(String ind)
|
||||
{
|
||||
if (_locomotiveStorage.keySet().contains(ind))
|
||||
{
|
||||
return _locomotiveStorage.get(ind);
|
||||
}
|
||||
return null;
|
||||
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> get(String ind) {
|
||||
if (_locomotiveStorage.keySet().contains(ind)) {
|
||||
return _locomotiveStorage.get(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawingObjectLocomotive get(String name, int ind)
|
||||
{
|
||||
if (_locomotiveStorage.keySet().contains(ind))
|
||||
{
|
||||
public DrawingObjectLocomotive get(String name, int ind) {
|
||||
if (_locomotiveStorage.keySet().contains(ind)) {
|
||||
return _locomotiveStorage.get(name).GetU(ind);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean SaveData(String filename) {
|
||||
if (new File(filename).exists()) {
|
||||
new File(filename).delete();
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
// for(KeyValue<String, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> record : _locomotiveStorage)
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user