RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.robot.internal.disco.drops; 00002 00003 import rlpark.plugin.robot.internal.sync.LiteByteBuffer; 00004 00005 00006 00007 public class DropString extends DropData { 00008 00009 private String value; 00010 00011 public DropString(String label) { 00012 this(label, "", false, 0); 00013 } 00014 00015 public DropString(String label, String name) { 00016 this(label, name, true, -1); 00017 } 00018 00019 public DropString(String label, String value, boolean readonly, int index) { 00020 super(label, readonly, index); 00021 this.value = value; 00022 } 00023 00024 @Override 00025 public DropData clone(String label, int index) { 00026 return new DropString(label, value, readOnly, index); 00027 } 00028 00029 public boolean checkString(LiteByteBuffer buffer) { 00030 if (buffer.getInt(0) != value.length()) 00031 return false; 00032 byte[] charName = new byte[value.length()]; 00033 for (int i = 0; i < value.length(); i++) 00034 charName[i] = buffer.get(i + DropData.IntSize); 00035 return value.equals(new String(charName)); 00036 } 00037 00038 static public String getData(LiteByteBuffer buffer, int index) { 00039 final int stringSize = buffer.capacity(); 00040 byte[] byteName = new byte[stringSize]; 00041 for (int i = 0; i < stringSize; i++) 00042 byteName[i] = buffer.get(i); 00043 return new String(byteName); 00044 } 00045 00046 @Override 00047 public void putData(LiteByteBuffer buffer) { 00048 buffer.putInt(value.length()); 00049 for (byte b : value.getBytes()) 00050 buffer.put(b); 00051 } 00052 00053 @Override 00054 public int size() { 00055 return value.length() * DropData.CharSize + DropData.IntSize; 00056 } 00057 00058 public String value() { 00059 return value; 00060 } 00061 00062 public void set(String value) { 00063 this.value = value; 00064 } 00065 00066 public String get() { 00067 return value; 00068 } 00069 }