RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.robot.internal.disco.drops; 00002 00003 00004 import java.util.Arrays; 00005 00006 import rlpark.plugin.robot.internal.sync.LiteByteBuffer; 00007 00008 00009 public class Drop { 00010 private final DropData[] dropDatas; 00011 private final DropString dropName; 00012 private final DropTime dropTime; 00013 00014 public Drop(String name, DropData... dropData) { 00015 assert name != null; 00016 dropName = new DropString("Name", name); 00017 dropDatas = new DropData[dropData.length]; 00018 DropData dropTime = null; 00019 int byteIndex = 0; 00020 for (int i = 0; i < dropData.length; i++) { 00021 DropData cloned = dropData[i].clone(byteIndex); 00022 dropDatas[i] = cloned; 00023 if (cloned.label.equals(DropTime.TIMELABEL)) { 00024 assert dropTime == null; 00025 dropTime = cloned; 00026 } 00027 byteIndex += cloned.size(); 00028 } 00029 this.dropTime = (DropTime) dropTime; 00030 } 00031 00032 public int dataSize() { 00033 int sum = 0; 00034 for (DropData data : dropDatas) 00035 sum += data.size(); 00036 return sum; 00037 } 00038 00039 public void putData(LiteByteBuffer buffer) { 00040 dropName.putData(buffer); 00041 buffer.putInt(dataSize()); 00042 for (DropData data : dropDatas) 00043 data.putData(buffer); 00044 } 00045 00046 @Override 00047 public String toString() { 00048 String[] values = new String[dropDatas.length]; 00049 for (int i = 0; i < values.length; i++) 00050 values[i] = dropDatas[i].toString(); 00051 return dropName.value() + ": " + Arrays.toString(values); 00052 } 00053 00054 public String name() { 00055 return dropName.value(); 00056 } 00057 00058 public long time() { 00059 return dropTime.time(); 00060 } 00061 00062 public DropData[] dropDatas() { 00063 return dropDatas; 00064 } 00065 00066 public void setTime(long time) { 00067 dropTime.set(time); 00068 } 00069 00070 public DropData drop(String label) { 00071 for (DropData drop : dropDatas) 00072 if (drop.label.equals(label)) 00073 return drop; 00074 return null; 00075 } 00076 00077 public int headerSize() { 00078 return dropName.size() + DropData.IntSize; 00079 } 00080 00081 public int packetSize() { 00082 return headerSize() + dataSize(); 00083 } 00084 00085 public int indexOf(String label) { 00086 int index = 0; 00087 for (DropData dropData : dropDatas) { 00088 if (dropData.label.equals(label)) 00089 return index; 00090 index += dropData.size(); 00091 } 00092 return index; 00093 } 00094 }