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 DropArray extends DropData { 00010 final private DropData[] dropDatas; 00011 private final int size; 00012 private final String[] suffixes; 00013 private final DropData prototype; 00014 00015 public DropArray(String label, int nbData) { 00016 this(label, getSuffixes(nbData)); 00017 } 00018 00019 public DropArray(DropData prototype, String label, int nbData) { 00020 this(prototype, label, -1, getSuffixes(nbData)); 00021 } 00022 00023 public DropArray(String label, String... suffixes) { 00024 this(new DropInteger(""), label, -1, suffixes); 00025 } 00026 00027 public DropArray(DropData prototype, String label, String... suffixes) { 00028 this(prototype, label, -1, suffixes); 00029 } 00030 00031 public DropArray(DropData prototype, String label, int index, String... suffixes) { 00032 super(label, false, index); 00033 assert suffixes.length > 0; 00034 assert prototype != null; 00035 this.prototype = prototype; 00036 dropDatas = new DropData[suffixes.length]; 00037 int sum = 0; 00038 for (int i = 0; i < suffixes.length; i++) { 00039 int byteIndex = index != -1 ? sum + index : -1; 00040 DropData data = prototype.clone(label + suffixes[i], byteIndex); 00041 dropDatas[i] = data; 00042 sum += data.size(); 00043 } 00044 size = sum; 00045 this.suffixes = suffixes; 00046 } 00047 00048 @Override 00049 public DropData clone(String label, int index) { 00050 return new DropArray(prototype, label, index, suffixes); 00051 } 00052 00053 @Override 00054 public void putData(LiteByteBuffer buffer) { 00055 for (DropData data : dropDatas) 00056 data.putData(buffer); 00057 } 00058 00059 @Override 00060 public int size() { 00061 return size; 00062 } 00063 00064 private static String[] getSuffixes(int nbData) { 00065 String[] suffixes = new String[nbData]; 00066 for (int i = 0; i < suffixes.length; i++) 00067 suffixes[i] = String.format("%d", i); 00068 return suffixes; 00069 } 00070 00071 @Override 00072 public String toString() { 00073 String[] values = new String[dropDatas.length]; 00074 for (int i = 0; i < values.length; i++) 00075 values[i] = dropDatas[i].toString(); 00076 return label + ": " + Arrays.toString(values); 00077 } 00078 00079 public DropData[] dropDatas() { 00080 return dropDatas; 00081 } 00082 }