Skip to content
Permalink
Browse files

hexStringFromInts always 2 charaters

  • Loading branch information...
icklesteve committed Jul 31, 2019
1 parent 80dab7e commit 9ac93506dbb69edbea058e5f4d663377d3fd3d5e
@@ -744,7 +744,7 @@ public String getParameterHexString() {
if (getParameters()==null) {
return "";
} else {
return jmri.util.StringUtil.hexStringFromInts(getParameters()).substring(2);
return jmri.util.StringUtil.hexStringFromInts(getParameters()).replaceAll("\\s","").substring(2);
}
}

@@ -759,7 +759,7 @@ public String getNvHexString() {
if ( getNvArray() == null ) {
return "";
} else {
return jmri.util.StringUtil.hexStringFromInts(getNvArray()).substring(2);
return jmri.util.StringUtil.hexStringFromInts(getNvArray()).replaceAll("\\s","").substring(2);
}
}

@@ -150,7 +150,7 @@ public String getEvVarString(){
*/
public String getHexEvVarString() {
if (getEvVarArray()!=null){
return StringUtil.hexStringFromInts(getEvVarArray());
return StringUtil.hexStringFromInts(getEvVarArray()).replaceAll("\\s","");
}
return "";
}
@@ -173,13 +173,13 @@ static public String hexStringFromBytes(@Nonnull byte[] bytes) {
}

/**
* Convert an array of integers into a single hex. string.
* Each element is displayed consecutively, no spaces.
* Convert an array of integers into a single spaced hex. string.
* Each int value will receive 2 hex characters.
* <p>
* eg. int[]{1,2,3,10} will return String "0102030A"
* eg. int[]{-1} will return "FFFFFFFF"
* eg. int[]{256} will return "100"
* eg. int[]{257} will return "101"
* eg. int[]{1,2,3,10} will return "01 02 03 0A "
* eg. int[]{-1} will return "FF "
* eg. int[]{256} will return "00 "
* eg. int[]{257} will return "01 "
*
* @param v the array of integers. Can be zero length, but must not be null.
* @return the formatted String or an empty String
@@ -189,7 +189,8 @@ static public String hexStringFromBytes(@Nonnull byte[] bytes) {
static public String hexStringFromInts(@Nonnull int[] v) {
StringBuilder retval = new StringBuilder();
for (int e : v) {
retval.append(String.format("%02X", e));
retval.append(twoHexFromInt(e));
retval.append(" ");
}
return retval.toString();
}
@@ -59,14 +59,11 @@ public void testEventHexString(){

CbusNodeEvent t = new CbusNodeEvent(0,7,256,-1,4);

Assert.assertEquals("4 Ev Vars Unset","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",t.getHexEvVarString());
Assert.assertEquals("4 Ev Vars Unset","FFFFFFFF",t.getHexEvVarString());
t.setEvArr(new int[]{0,0,0,0});
Assert.assertEquals("4 Ev Vars 0000","00000000",t.getHexEvVarString());
t.setEvArr(new int[]{1,2,3,4});
Assert.assertEquals("4 Ev Vars 1234","01020304",t.getHexEvVarString());
t.setEvArr(new int[]{10,256,255,123});
Assert.assertEquals("4 Ev Vars larger","0A100FF7B",t.getHexEvVarString());

t.setEvArr(null);
Assert.assertEquals("4 Ev Vars null","",t.getHexEvVarString());

@@ -468,11 +468,11 @@ public void testHexStringFromBytes(){
@Test
public void testHexStringFromInts(){
Assert.assertEquals("Zero Length Array", "", StringUtil.hexStringFromInts(new int[] {}) );
Assert.assertEquals("-1", "FFFFFFFF", StringUtil.hexStringFromInts(new int[] {-1}) );
Assert.assertEquals("0", "00", StringUtil.hexStringFromInts(new int[] {0}) );
Assert.assertEquals("0,1", "0001", StringUtil.hexStringFromInts(new int[] {0,1}) );
Assert.assertEquals("45,123,129,217", "2D7B81D9", StringUtil.hexStringFromInts(new int[] {45,123,129,217}) );
Assert.assertEquals("255,256,257", "FF100101", StringUtil.hexStringFromInts(new int[] {255,256,257}) );
Assert.assertEquals("-1", "FF ", StringUtil.hexStringFromInts(new int[] {-1}) );
Assert.assertEquals("0", "00 ", StringUtil.hexStringFromInts(new int[] {0}) );
Assert.assertEquals("0,1", "00 01 ", StringUtil.hexStringFromInts(new int[] {0,1}) );
Assert.assertEquals("45,123,129,217", "2D 7B 81 D9 ", StringUtil.hexStringFromInts(new int[] {45,123,129,217}) );
Assert.assertEquals("255,256,257", "FF 00 01 ", StringUtil.hexStringFromInts(new int[] {255,256,257}) );
}

// The minimal setup for log4J

0 comments on commit 9ac9350

Please sign in to comment.
You can’t perform that action at this time.