target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testIsNumericArray(){ VDouble vDouble = VDouble.of(7.7, Alarm.none(), Time.now(), Display.none()); assertFalse(VTypeHelper.isNumericArray(vDouble)); VDoubleArray doubleArray = VDoubleArray.of(ArrayDouble.of(7.7, 8.8), Alarm.none(), Time.now(), Display.none()); assertTrue(VTypeHelper.isNumericArray(doubleArray)); VEnumArray enumArray = VEnumArray.of(ArrayInteger.of(0, 1), EnumDisplay.of("a", "b"), Alarm.none(), Time.now()); assertTrue(VTypeHelper.isNumericArray(enumArray)); }
|
public static boolean isNumericArray(final VType value) { return value instanceof VNumberArray || value instanceof VEnumArray; }
|
VTypeHelper { public static boolean isNumericArray(final VType value) { return value instanceof VNumberArray || value instanceof VEnumArray; } }
|
VTypeHelper { public static boolean isNumericArray(final VType value) { return value instanceof VNumberArray || value instanceof VEnumArray; } }
|
VTypeHelper { public static boolean isNumericArray(final VType value) { return value instanceof VNumberArray || value instanceof VEnumArray; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static boolean isNumericArray(final VType value) { return value instanceof VNumberArray || value instanceof VEnumArray; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testGetArraySize(){ VDoubleArray doubleArray = VDoubleArray.of(ArrayDouble.of(7.7, 8.8), Alarm.none(), Time.now(), Display.none()); assertEquals(2, VTypeHelper.getArraySize(doubleArray)); VEnumArray enumArray = VEnumArray.of(ArrayInteger.of(0, 1), EnumDisplay.of("a", "b"), Alarm.none(), Time.now()); assertEquals(2, VTypeHelper.getArraySize(enumArray)); VStringArray stringArray = VStringArray.of(Arrays.asList("a","b"), Alarm.none(), Time.now()); assertEquals(2, VTypeHelper.getArraySize(stringArray)); }
|
public static int getArraySize(final VType value) { final ListInteger sizes; if (value instanceof VNumberArray) { sizes = ((VNumberArray) value).getSizes(); } else if (value instanceof VEnumArray) { sizes = ((VEnumArray) value).getSizes(); } else if (value instanceof VStringArray) { sizes = ((VStringArray) value).getSizes(); } else { return 0; } return sizes.size() > 0 ? sizes.getInt(0) : 0; }
|
VTypeHelper { public static int getArraySize(final VType value) { final ListInteger sizes; if (value instanceof VNumberArray) { sizes = ((VNumberArray) value).getSizes(); } else if (value instanceof VEnumArray) { sizes = ((VEnumArray) value).getSizes(); } else if (value instanceof VStringArray) { sizes = ((VStringArray) value).getSizes(); } else { return 0; } return sizes.size() > 0 ? sizes.getInt(0) : 0; } }
|
VTypeHelper { public static int getArraySize(final VType value) { final ListInteger sizes; if (value instanceof VNumberArray) { sizes = ((VNumberArray) value).getSizes(); } else if (value instanceof VEnumArray) { sizes = ((VEnumArray) value).getSizes(); } else if (value instanceof VStringArray) { sizes = ((VStringArray) value).getSizes(); } else { return 0; } return sizes.size() > 0 ? sizes.getInt(0) : 0; } }
|
VTypeHelper { public static int getArraySize(final VType value) { final ListInteger sizes; if (value instanceof VNumberArray) { sizes = ((VNumberArray) value).getSizes(); } else if (value instanceof VEnumArray) { sizes = ((VEnumArray) value).getSizes(); } else if (value instanceof VStringArray) { sizes = ((VStringArray) value).getSizes(); } else { return 0; } return sizes.size() > 0 ? sizes.getInt(0) : 0; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static int getArraySize(final VType value) { final ListInteger sizes; if (value instanceof VNumberArray) { sizes = ((VNumberArray) value).getSizes(); } else if (value instanceof VEnumArray) { sizes = ((VEnumArray) value).getSizes(); } else if (value instanceof VStringArray) { sizes = ((VStringArray) value).getSizes(); } else { return 0; } return sizes.size() > 0 ? sizes.getInt(0) : 0; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testGetLatestTimeOf(){ Instant now = Instant.now(); Time t1 = Time.of(Instant.EPOCH); Time t2 = Time.of(now); VInt i1 = VInt.of(1, Alarm.none(), t1, Display.none()); VInt i2 = VInt.of(2, Alarm.none(), t2, Display.none()); assertEquals(t2, VTypeHelper.lastestTimeOf(i1, i2)); assertEquals(t2, VTypeHelper.lastestTimeOf(i2, i1)); }
|
public static Time lastestTimeOf(final VType a, final VType b) { final Time ta = Time.timeOf(a); final Time tb = Time.timeOf(b); if (ta.getTimestamp().isAfter(tb.getTimestamp())) { return ta; } return tb; }
|
VTypeHelper { public static Time lastestTimeOf(final VType a, final VType b) { final Time ta = Time.timeOf(a); final Time tb = Time.timeOf(b); if (ta.getTimestamp().isAfter(tb.getTimestamp())) { return ta; } return tb; } }
|
VTypeHelper { public static Time lastestTimeOf(final VType a, final VType b) { final Time ta = Time.timeOf(a); final Time tb = Time.timeOf(b); if (ta.getTimestamp().isAfter(tb.getTimestamp())) { return ta; } return tb; } }
|
VTypeHelper { public static Time lastestTimeOf(final VType a, final VType b) { final Time ta = Time.timeOf(a); final Time tb = Time.timeOf(b); if (ta.getTimestamp().isAfter(tb.getTimestamp())) { return ta; } return tb; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static Time lastestTimeOf(final VType a, final VType b) { final Time ta = Time.timeOf(a); final Time tb = Time.timeOf(b); if (ta.getTimestamp().isAfter(tb.getTimestamp())) { return ta; } return tb; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testGetTimestamp() throws Exception{ Instant epoch = Instant.EPOCH; Time t = Time.of(epoch); VInt i1 = VInt.of(1, Alarm.none(), t, Display.none()); assertEquals(epoch, VTypeHelper.getTimestamp(i1)); t = Time.nowInvalid(); i1 = VInt.of(1, Alarm.none(), t, Display.none()); Instant now = Instant.now(); Thread.sleep(2); assertTrue(VTypeHelper.getTimestamp(i1).isAfter(now)); }
|
final public static Instant getTimestamp(final VType value) { final Time time = Time.timeOf(value); if (time != null && time.isValid()) { return time.getTimestamp(); } return Instant.now(); }
|
VTypeHelper { final public static Instant getTimestamp(final VType value) { final Time time = Time.timeOf(value); if (time != null && time.isValid()) { return time.getTimestamp(); } return Instant.now(); } }
|
VTypeHelper { final public static Instant getTimestamp(final VType value) { final Time time = Time.timeOf(value); if (time != null && time.isValid()) { return time.getTimestamp(); } return Instant.now(); } }
|
VTypeHelper { final public static Instant getTimestamp(final VType value) { final Time time = Time.timeOf(value); if (time != null && time.isValid()) { return time.getTimestamp(); } return Instant.now(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { final public static Instant getTimestamp(final VType value) { final Time time = Time.timeOf(value); if (time != null && time.isValid()) { return time.getTimestamp(); } return Instant.now(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testTransformTimestamp(){ Instant instant = Instant.now(); VInt intValue = VInt.of(7, Alarm.none(), Time.of(Instant.EPOCH), Display.none()); intValue = (VInt)VTypeHelper.transformTimestamp(intValue, instant); assertEquals(instant, intValue.getTime().getTimestamp()); VDouble doubleValue = VDouble.of(7.7, Alarm.none(), Time.of(Instant.EPOCH), Display.none()); doubleValue = (VDouble)VTypeHelper.transformTimestamp(doubleValue, instant); assertEquals(instant, doubleValue.getTime().getTimestamp()); VString stringValue = VString.of("test", Alarm.none(), Time.of(Instant.EPOCH)); stringValue = (VString)VTypeHelper.transformTimestamp(stringValue, instant); assertEquals(instant, stringValue.getTime().getTimestamp()); VEnum enumValue = VEnum.of(7, EnumDisplay.of("a", "b"), Alarm.none(), Time.now()); enumValue = (VEnum)VTypeHelper.transformTimestamp(enumValue, instant); assertEquals(instant, enumValue.getTime().getTimestamp()); VDoubleArray doubleArray = VDoubleArray.of(ArrayDouble.of(7.7, 8.8), Alarm.none(), Time.now(), Display.none()); doubleArray = (VDoubleArray)VTypeHelper.transformTimestamp(doubleArray, instant); assertEquals(instant, doubleArray.getTime().getTimestamp()); VEnumArray enumArray = VEnumArray.of(ArrayInteger.of(0, 1), EnumDisplay.of("a", "b"), Alarm.none(), Time.now()); assertNull(VTypeHelper.transformTimestamp(enumArray, instant)); }
|
public static VType transformTimestamp(final VType value, final Instant time) { if (value instanceof VDouble) { final VDouble number = (VDouble) value; return VDouble.of(number.getValue().doubleValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VNumber) { final VNumber number = (VNumber) value; return VInt.of(number.getValue().intValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VString) { final VString string = (VString) value; return VString.of(string.getValue(), string.getAlarm(), Time.of(time)); } if (value instanceof VDoubleArray) { final VDoubleArray number = (VDoubleArray) value; return VDoubleArray.of(number.getData(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VEnum) { final VEnum labelled = (VEnum) value; return VEnum.of(labelled.getIndex(), labelled.getDisplay(), labelled.getAlarm(), Time.of(time)); } return null; }
|
VTypeHelper { public static VType transformTimestamp(final VType value, final Instant time) { if (value instanceof VDouble) { final VDouble number = (VDouble) value; return VDouble.of(number.getValue().doubleValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VNumber) { final VNumber number = (VNumber) value; return VInt.of(number.getValue().intValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VString) { final VString string = (VString) value; return VString.of(string.getValue(), string.getAlarm(), Time.of(time)); } if (value instanceof VDoubleArray) { final VDoubleArray number = (VDoubleArray) value; return VDoubleArray.of(number.getData(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VEnum) { final VEnum labelled = (VEnum) value; return VEnum.of(labelled.getIndex(), labelled.getDisplay(), labelled.getAlarm(), Time.of(time)); } return null; } }
|
VTypeHelper { public static VType transformTimestamp(final VType value, final Instant time) { if (value instanceof VDouble) { final VDouble number = (VDouble) value; return VDouble.of(number.getValue().doubleValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VNumber) { final VNumber number = (VNumber) value; return VInt.of(number.getValue().intValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VString) { final VString string = (VString) value; return VString.of(string.getValue(), string.getAlarm(), Time.of(time)); } if (value instanceof VDoubleArray) { final VDoubleArray number = (VDoubleArray) value; return VDoubleArray.of(number.getData(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VEnum) { final VEnum labelled = (VEnum) value; return VEnum.of(labelled.getIndex(), labelled.getDisplay(), labelled.getAlarm(), Time.of(time)); } return null; } }
|
VTypeHelper { public static VType transformTimestamp(final VType value, final Instant time) { if (value instanceof VDouble) { final VDouble number = (VDouble) value; return VDouble.of(number.getValue().doubleValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VNumber) { final VNumber number = (VNumber) value; return VInt.of(number.getValue().intValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VString) { final VString string = (VString) value; return VString.of(string.getValue(), string.getAlarm(), Time.of(time)); } if (value instanceof VDoubleArray) { final VDoubleArray number = (VDoubleArray) value; return VDoubleArray.of(number.getData(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VEnum) { final VEnum labelled = (VEnum) value; return VEnum.of(labelled.getIndex(), labelled.getDisplay(), labelled.getAlarm(), Time.of(time)); } return null; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static VType transformTimestamp(final VType value, final Instant time) { if (value instanceof VDouble) { final VDouble number = (VDouble) value; return VDouble.of(number.getValue().doubleValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VNumber) { final VNumber number = (VNumber) value; return VInt.of(number.getValue().intValue(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VString) { final VString string = (VString) value; return VString.of(string.getValue(), string.getAlarm(), Time.of(time)); } if (value instanceof VDoubleArray) { final VDoubleArray number = (VDoubleArray) value; return VDoubleArray.of(number.getData(), number.getAlarm(), Time.of(time), number.getDisplay()); } if (value instanceof VEnum) { final VEnum labelled = (VEnum) value; return VEnum.of(labelled.getIndex(), labelled.getDisplay(), labelled.getAlarm(), Time.of(time)); } return null; } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testGetScalarValueString() { assertEquals("[1]", SnapshotDataConverter.getScalarValueString(Integer.valueOf(1))); assertEquals("[1.1]", SnapshotDataConverter.getScalarValueString(Double.valueOf(1.1))); String string = SnapshotDataConverter.getScalarValueString("string"); assertEquals("[\"string\"]", string); }
|
protected static String getScalarValueString(Object value) { ObjectMapper objectMapper = new ObjectMapper(); Object[] valueArray = {value}; try { return objectMapper.writeValueAsString(valueArray); } catch (JsonProcessingException e) { throw new PVConversionException(String.format("Unable to write scalar value \"%s\" as JSON string", value.toString())); } }
|
SnapshotDataConverter { protected static String getScalarValueString(Object value) { ObjectMapper objectMapper = new ObjectMapper(); Object[] valueArray = {value}; try { return objectMapper.writeValueAsString(valueArray); } catch (JsonProcessingException e) { throw new PVConversionException(String.format("Unable to write scalar value \"%s\" as JSON string", value.toString())); } } }
|
SnapshotDataConverter { protected static String getScalarValueString(Object value) { ObjectMapper objectMapper = new ObjectMapper(); Object[] valueArray = {value}; try { return objectMapper.writeValueAsString(valueArray); } catch (JsonProcessingException e) { throw new PVConversionException(String.format("Unable to write scalar value \"%s\" as JSON string", value.toString())); } } private SnapshotDataConverter(); }
|
SnapshotDataConverter { protected static String getScalarValueString(Object value) { ObjectMapper objectMapper = new ObjectMapper(); Object[] valueArray = {value}; try { return objectMapper.writeValueAsString(valueArray); } catch (JsonProcessingException e) { throw new PVConversionException(String.format("Unable to write scalar value \"%s\" as JSON string", value.toString())); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { protected static String getScalarValueString(Object value) { ObjectMapper objectMapper = new ObjectMapper(); Object[] valueArray = {value}; try { return objectMapper.writeValueAsString(valueArray); } catch (JsonProcessingException e) { throw new PVConversionException(String.format("Unable to write scalar value \"%s\" as JSON string", value.toString())); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test public void highestAlarmOf() { VType arg1 = VInt.of(0, Alarm.none(), Time.now(), Display.none()); VType arg2 = VInt.of(0, Alarm.lolo(), Time.now(), Display.none()); Alarm alarm = VTypeHelper.highestAlarmOf(arg1, arg2); assertTrue("Failed to correctly calculate highest alarm expected LOLO, got : " + alarm, Alarm.lolo().equals(alarm)); }
|
public static Alarm highestAlarmOf(final VType a, VType b) { return Alarm.highestAlarmOf(java.util.List.of(a, b), false); }
|
VTypeHelper { public static Alarm highestAlarmOf(final VType a, VType b) { return Alarm.highestAlarmOf(java.util.List.of(a, b), false); } }
|
VTypeHelper { public static Alarm highestAlarmOf(final VType a, VType b) { return Alarm.highestAlarmOf(java.util.List.of(a, b), false); } }
|
VTypeHelper { public static Alarm highestAlarmOf(final VType a, VType b) { return Alarm.highestAlarmOf(java.util.List.of(a, b), false); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static Alarm highestAlarmOf(final VType a, VType b) { return Alarm.highestAlarmOf(java.util.List.of(a, b), false); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatArrayNumbersArrayZeroLength(){ ListInteger listInteger = ArrayInteger.of(); Array array = VNumberArray.of(listInteger, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VIntArray", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatArrayZeroMax(){ ListInteger listInteger = ArrayInteger.of(1, 2, 3, 4, 5); Array array = VNumberArray.of(listInteger, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 0); assertEquals("VIntArray", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatArrayNegativeMax(){ ListInteger listInteger = ArrayInteger.of(1, 2, 3, 4, 5); Array array = VNumberArray.of(listInteger, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, -1); assertEquals("VIntArray[1, 2, 3, 4, 5]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatArrayWithSizes(){ ListInteger sizes = ArrayInteger.of(2, 3); ListInteger listInteger = ArrayInteger.of(11, 12, 21, 22, 31, 32); Array array = VNumberArray.of(listInteger, sizes, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VIntArray[11, 12, 21,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VIntArray[11, 12, 21, 22, 31, 32]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatIntArray(){ ListInteger listInteger = ArrayInteger.of(-1, 2, 3, 4, 5); Array array = VIntArray.of(listInteger, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VIntArray[-1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VIntArray[-1, 2, 3, 4, 5]", string); ListUInteger listUInteger = ArrayUInteger.of(1, 2, 3, 4, 5); array = VUIntArray.of(listUInteger, Alarm.none(), Time.now(), Display.none()); string = VTypeHelper.formatArray(array, 3); assertEquals("VUIntArray[1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VUIntArray[1, 2, 3, 4, 5]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatLongArray(){ ListLong list = ArrayLong.of(-1L, 2L, 3L, 4L, 5L); Array array = VLongArray.of(list, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VLongArray[-1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VLongArray[-1, 2, 3, 4, 5]", string); ListULong listU = ArrayULong.of(1L, 2L, 3L, 4L, 5L); array = VUIntArray.of(listU, Alarm.none(), Time.now(), Display.none()); string = VTypeHelper.formatArray(array, 3); assertEquals("VULongArray[1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VULongArray[1, 2, 3, 4, 5]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatShortArray(){ ListShort list = ArrayShort.of((short)-1, (short)2, (short)3, (short)4, (short)5); Array array = VShortArray.of(list, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VShortArray[-1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VShortArray[-1, 2, 3, 4, 5]", string); ListUShort listU = ArrayUShort.of((short)1, (short)2, (short)3, (short)4, (short)5); array = VUShortArray.of(listU, Alarm.none(), Time.now(), Display.none()); string = VTypeHelper.formatArray(array, 3); assertEquals("VUShortArray[1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VUShortArray[1, 2, 3, 4, 5]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatByteArray(){ ListByte list = ArrayByte.of((byte)-1, (byte)2, (byte)3, (byte)4, (byte)5); Array array = VByteArray.of(list, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VByteArray[-1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VByteArray[-1, 2, 3, 4, 5]", string); ListUByte listU = ArrayUByte.of((byte)1, (byte)2, (byte)3, (byte)4, (byte)5); array = VUShortArray.of(listU, Alarm.none(), Time.now(), Display.none()); string = VTypeHelper.formatArray(array, 3); assertEquals("VUByteArray[1, 2, 3,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VUByteArray[1, 2, 3, 4, 5]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatBooleanArray(){ ListBoolean list = ArrayBoolean.of(true, true, false, false ,false); Array array = VBooleanArray.of(list, Alarm.none(), Time.now()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VBooleanArray[true, true, false,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VBooleanArray[true, true, false, false, false]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testGetArrayValueString() { VNumberArray vNumberArray = VByteArray.of(CollectionNumbers.toListByte((byte) 1, (byte) 2), alarm, time, display); assertEquals("[1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VUByteArray.of(CollectionNumbers.toListUByte((byte) 1, (byte) 2), alarm, time, display); assertEquals("[1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VShortArray.of(CollectionNumbers.toListShort((short) -1, (short) 2), alarm, time, display); assertEquals("[-1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VUShortArray.of(CollectionNumbers.toListUShort((short) 1, (short) 2), alarm, time, display); assertEquals("[1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VIntArray.of(CollectionNumbers.toListInt(-1, 2), alarm, time, display); assertEquals("[-1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VUIntArray.of(CollectionNumbers.toListUInt(1, 2), alarm, time, display); assertEquals("[1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VLongArray.of(CollectionNumbers.toListLong(-1L, 2L), alarm, time, display); assertEquals("[-1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VULongArray.of(CollectionNumbers.toListULong(1L, 2L), alarm, time, display); assertEquals("[1,2]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VFloatArray.of(CollectionNumbers.toListFloat(1.2f, 2.1f), alarm, time, display); assertEquals("[1.2,2.1]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); vNumberArray = VDoubleArray.of(CollectionNumbers.toListDouble(1.2, 2.1), alarm, time, display); assertEquals("[1.2,2.1]", SnapshotDataConverter.getNumberArrayValueString(vNumberArray)); }
|
protected static String getNumberArrayValueString(VNumberArray vNumberArray) { List<Object> valueList = new ArrayList<>(); if(vNumberArray instanceof VByteArray || vNumberArray instanceof VUByteArray || vNumberArray instanceof VShortArray || vNumberArray instanceof VUShortArray || vNumberArray instanceof VIntArray || vNumberArray instanceof VUIntArray || vNumberArray instanceof VLongArray || vNumberArray instanceof VULongArray) { IteratorNumber iterator = vNumberArray.getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextLong()); } } else if(vNumberArray instanceof VFloatArray) { IteratorFloat iterator = ((VFloatArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextFloat()); } } else if(vNumberArray instanceof VDoubleArray) { IteratorDouble iterator = ((VDoubleArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextDouble()); } } else { throw new PVConversionException(String.format("Unable to create JSON string for array type %s", vNumberArray.getClass().getCanonicalName())); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(valueList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write array values as JSON string"); } }
|
SnapshotDataConverter { protected static String getNumberArrayValueString(VNumberArray vNumberArray) { List<Object> valueList = new ArrayList<>(); if(vNumberArray instanceof VByteArray || vNumberArray instanceof VUByteArray || vNumberArray instanceof VShortArray || vNumberArray instanceof VUShortArray || vNumberArray instanceof VIntArray || vNumberArray instanceof VUIntArray || vNumberArray instanceof VLongArray || vNumberArray instanceof VULongArray) { IteratorNumber iterator = vNumberArray.getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextLong()); } } else if(vNumberArray instanceof VFloatArray) { IteratorFloat iterator = ((VFloatArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextFloat()); } } else if(vNumberArray instanceof VDoubleArray) { IteratorDouble iterator = ((VDoubleArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextDouble()); } } else { throw new PVConversionException(String.format("Unable to create JSON string for array type %s", vNumberArray.getClass().getCanonicalName())); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(valueList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write array values as JSON string"); } } }
|
SnapshotDataConverter { protected static String getNumberArrayValueString(VNumberArray vNumberArray) { List<Object> valueList = new ArrayList<>(); if(vNumberArray instanceof VByteArray || vNumberArray instanceof VUByteArray || vNumberArray instanceof VShortArray || vNumberArray instanceof VUShortArray || vNumberArray instanceof VIntArray || vNumberArray instanceof VUIntArray || vNumberArray instanceof VLongArray || vNumberArray instanceof VULongArray) { IteratorNumber iterator = vNumberArray.getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextLong()); } } else if(vNumberArray instanceof VFloatArray) { IteratorFloat iterator = ((VFloatArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextFloat()); } } else if(vNumberArray instanceof VDoubleArray) { IteratorDouble iterator = ((VDoubleArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextDouble()); } } else { throw new PVConversionException(String.format("Unable to create JSON string for array type %s", vNumberArray.getClass().getCanonicalName())); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(valueList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write array values as JSON string"); } } private SnapshotDataConverter(); }
|
SnapshotDataConverter { protected static String getNumberArrayValueString(VNumberArray vNumberArray) { List<Object> valueList = new ArrayList<>(); if(vNumberArray instanceof VByteArray || vNumberArray instanceof VUByteArray || vNumberArray instanceof VShortArray || vNumberArray instanceof VUShortArray || vNumberArray instanceof VIntArray || vNumberArray instanceof VUIntArray || vNumberArray instanceof VLongArray || vNumberArray instanceof VULongArray) { IteratorNumber iterator = vNumberArray.getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextLong()); } } else if(vNumberArray instanceof VFloatArray) { IteratorFloat iterator = ((VFloatArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextFloat()); } } else if(vNumberArray instanceof VDoubleArray) { IteratorDouble iterator = ((VDoubleArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextDouble()); } } else { throw new PVConversionException(String.format("Unable to create JSON string for array type %s", vNumberArray.getClass().getCanonicalName())); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(valueList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write array values as JSON string"); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { protected static String getNumberArrayValueString(VNumberArray vNumberArray) { List<Object> valueList = new ArrayList<>(); if(vNumberArray instanceof VByteArray || vNumberArray instanceof VUByteArray || vNumberArray instanceof VShortArray || vNumberArray instanceof VUShortArray || vNumberArray instanceof VIntArray || vNumberArray instanceof VUIntArray || vNumberArray instanceof VLongArray || vNumberArray instanceof VULongArray) { IteratorNumber iterator = vNumberArray.getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextLong()); } } else if(vNumberArray instanceof VFloatArray) { IteratorFloat iterator = ((VFloatArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextFloat()); } } else if(vNumberArray instanceof VDoubleArray) { IteratorDouble iterator = ((VDoubleArray)vNumberArray).getData().iterator(); while(iterator.hasNext()) { valueList.add(iterator.nextDouble()); } } else { throw new PVConversionException(String.format("Unable to create JSON string for array type %s", vNumberArray.getClass().getCanonicalName())); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(valueList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write array values as JSON string"); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test public void testFormatDoubleArray(){ ListDouble list = ArrayDouble.of(-1d, 0.27, 3.0f, 4.0f, 5.0f); Array array = VDoubleArray.of(list, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VDoubleArray[-1.0, 0.27, 3.0,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VDoubleArray[-1.0, 0.27, 3.0, 4.0, 5.0]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatFloatArray(){ ListFloat list = ArrayFloat.of(-1f, 0.27f, 3.0f, 4.0f, 5.0f); Array array = VDoubleArray.of(list, Alarm.none(), Time.now(), Display.none()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VFloatArray[-1.0, 0.27, 3.0,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VFloatArray[-1.0, 0.27, 3.0, 4.0, 5.0]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatStringArray(){ Array array = VStringArray.of(Arrays.asList("a", "b", "c", "d", "e"), Alarm.none(), Time.now()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VStringArray[a, b, c,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VStringArray[a, b, c, d, e]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testFormatEnumArray(){ ListInteger listInteger = ArrayInteger.of(0, 1, 2, 3, 4); Array array = VEnumArray.of(listInteger, EnumDisplay.of("a", "b", "c", "d", "e"), Alarm.none(), Time.now()); String string = VTypeHelper.formatArray(array, 3); assertEquals("VEnumArray[a, b, c,...", string); string = VTypeHelper.formatArray(array, 10); assertEquals("VEnumArray[a, b, c, d, e]", string); }
|
public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
VTypeHelper { public static String formatArray(Array array, int maxElements) { StringBuilder builder = new StringBuilder(); builder.append(VType.typeOf(array).getSimpleName()); if (maxElements < 0) { builder.append(array.getData().toString()); return builder.toString(); } else if (maxElements == 0) { return builder.toString(); } ListInteger sizes = array.getSizes(); int sizesSize = sizes.size(); int totalElements = 1; for (int i = 0; i < sizesSize; i++) { totalElements *= sizes.getInt(i); } if (totalElements == 0) { return builder.toString(); } int numberOfElementsToFormat = Math.min(totalElements, maxElements); builder.append("["); if ((array instanceof VIntArray) || (array instanceof VUIntArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getInt(i)).append(", "); } builder.append(listNumber.getInt(numberOfElementsToFormat - 1)); } else if ((array instanceof VLongArray) || (array instanceof VULongArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getLong(i)).append(", "); } builder.append(listNumber.getLong(numberOfElementsToFormat - 1)); } else if ((array instanceof VShortArray) || (array instanceof VUShortArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getShort(i)).append(", "); } builder.append(listNumber.getShort(numberOfElementsToFormat - 1)); } else if ((array instanceof VByteArray) || (array instanceof VUByteArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getByte(i)).append(", "); } builder.append(listNumber.getByte(numberOfElementsToFormat - 1)); } else if ((array instanceof VDoubleArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getDouble(i)).append(", "); } builder.append(listNumber.getDouble(numberOfElementsToFormat - 1)); } else if ((array instanceof VFloatArray)) { VNumberArray numberArray = (VNumberArray) array; ListNumber listNumber = numberArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listNumber.getFloat(i)).append(", "); } builder.append(listNumber.getFloat(numberOfElementsToFormat - 1)); } else if ((array instanceof VBooleanArray)) { VBooleanArray booleanArray = (VBooleanArray) array; ListBoolean listBoolean = booleanArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listBoolean.getBoolean(i)).append(", "); } builder.append(listBoolean.getBoolean(numberOfElementsToFormat - 1)); } else if (array instanceof VStringArray) { VStringArray stringArray = (VStringArray) array; List<String> listString = stringArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } else if (array instanceof VEnumArray) { VEnumArray enumArray = (VEnumArray) array; List<String> listString = enumArray.getData(); for (int i = 0; i < numberOfElementsToFormat - 1; i++) { builder.append(listString.get(i)).append(", "); } builder.append(listString.get(numberOfElementsToFormat - 1)); } if (numberOfElementsToFormat < totalElements) { builder.append(",..."); } else { builder.append("]"); } return builder.toString(); } final static double toDouble(final VType value); static double[] toDoubles(final VType value); static String toString(final VType value); static double toDouble(final VType value, final int index); static boolean isNumericArray(final VType value); static int getArraySize(final VType value); static Alarm highestAlarmOf(final VType a, VType b); static Time lastestTimeOf(final VType a, final VType b); final static Instant getTimestamp(final VType value); static VType transformTimestamp(final VType value,
final Instant time); static VType transformTimestampToNow(final VType value); static boolean isDisconnected(final VType value); static AlarmSeverity getSeverity(final VType value); static String formatArray(Array array, int maxElements); }
|
@Test public void testGetDimensionString() { VNumberArray vNumberArray = VIntArray.of(CollectionNumbers.toListInt(1, 2, 3, 4, 5, 6), CollectionNumbers.toListInt(1, 2, 3), alarm, time, display); vNumberArray.getSizes(); assertEquals("[1,2,3]", SnapshotDataConverter.getDimensionString(vNumberArray)); vNumberArray = VIntArray.of(CollectionNumbers.toListInt(1, 2, 3), CollectionNumbers.toListInt(1, 2), alarm, time, display); vNumberArray.getSizes(); assertEquals("[1,2]", SnapshotDataConverter.getDimensionString(vNumberArray)); vNumberArray = VIntArray.of(CollectionNumbers.toListInt(1), CollectionNumbers.toListInt(1), alarm, time, display); vNumberArray.getSizes(); assertEquals("[1]", SnapshotDataConverter.getDimensionString(vNumberArray)); }
|
protected static String getDimensionString(VNumberArray vNumberArray) { ListInteger sizes = vNumberArray.getSizes(); List<Integer> sizesAsIntList = new ArrayList<>(); for(int i = 0; i < sizes.size(); i++) { sizesAsIntList.add(sizes.getInt(i)); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(sizesAsIntList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write sizes of number array as JSON string"); } }
|
SnapshotDataConverter { protected static String getDimensionString(VNumberArray vNumberArray) { ListInteger sizes = vNumberArray.getSizes(); List<Integer> sizesAsIntList = new ArrayList<>(); for(int i = 0; i < sizes.size(); i++) { sizesAsIntList.add(sizes.getInt(i)); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(sizesAsIntList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write sizes of number array as JSON string"); } } }
|
SnapshotDataConverter { protected static String getDimensionString(VNumberArray vNumberArray) { ListInteger sizes = vNumberArray.getSizes(); List<Integer> sizesAsIntList = new ArrayList<>(); for(int i = 0; i < sizes.size(); i++) { sizesAsIntList.add(sizes.getInt(i)); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(sizesAsIntList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write sizes of number array as JSON string"); } } private SnapshotDataConverter(); }
|
SnapshotDataConverter { protected static String getDimensionString(VNumberArray vNumberArray) { ListInteger sizes = vNumberArray.getSizes(); List<Integer> sizesAsIntList = new ArrayList<>(); for(int i = 0; i < sizes.size(); i++) { sizesAsIntList.add(sizes.getInt(i)); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(sizesAsIntList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write sizes of number array as JSON string"); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { protected static String getDimensionString(VNumberArray vNumberArray) { ListInteger sizes = vNumberArray.getSizes(); List<Integer> sizesAsIntList = new ArrayList<>(); for(int i = 0; i < sizes.size(); i++) { sizesAsIntList.add(sizes.getInt(i)); } ObjectMapper objectMapper = new ObjectMapper(); try { return objectMapper.writeValueAsString(sizesAsIntList); } catch (JsonProcessingException e) { throw new PVConversionException("Unable to write sizes of number array as JSON string"); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test public void testDesrializeSizes() { ListInteger sizes = SnapshotDataConverter.toSizes(SnapshotPv.builder().sizes("[1,2]").build()); assertEquals(2, sizes.size()); assertEquals(1, sizes.getInt(0)); }
|
protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } private SnapshotDataConverter(); }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test(expected = PVConversionException.class) public void testDeserializeBadSizes() { SnapshotDataConverter.toSizes(SnapshotPv.builder().sizes("[1,2").build()); }
|
protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } private SnapshotDataConverter(); }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { protected static ListInteger toSizes(SnapshotPv snapshotPv) { ObjectMapper objectMapper = new ObjectMapper(); try { int[] sizes = objectMapper.readValue(snapshotPv.getSizes(), int[].class); return CollectionNumbers.toListInt(sizes); } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert string %s to int array", snapshotPv.getSizes())); } } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test(expected = IllegalArgumentException.class) public void testCreateConfigurationNoParent() { services.createNode("x", configFromClient); }
|
@Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testToVType() { SnapshotPv snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.BYTE) .sizes(SnapshotDataConverter.SCALAR_AS_JSON).time(1000L).timens(7000).value("[1]").build(); VByte vByte = (VByte) SnapshotDataConverter.toVType(snapshotPv); assertEquals(1, vByte.getValue().byteValue()); assertEquals(1000L, vByte.getTime().getTimestamp().getEpochSecond()); assertEquals(7000, vByte.getTime().getTimestamp().getNano()); assertEquals(AlarmSeverity.NONE, vByte.getAlarm().getSeverity()); assertEquals(AlarmStatus.NONE, vByte.getAlarm().getStatus()); assertEquals("name", vByte.getAlarm().getName()); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.UBYTE) .sizes(SnapshotDataConverter.SCALAR_AS_JSON).time(1000L).timens(7000).value("[1]").build(); VUByte vUByte = (VUByte) SnapshotDataConverter.toVType(snapshotPv); assertEquals(1, vUByte.getValue().byteValue()); assertEquals(1000L, vUByte.getTime().getTimestamp().getEpochSecond()); assertEquals(7000, vUByte.getTime().getTimestamp().getNano()); assertEquals(AlarmSeverity.NONE, vUByte.getAlarm().getSeverity()); assertEquals(AlarmStatus.NONE, vUByte.getAlarm().getStatus()); assertEquals("name", vUByte.getAlarm().getName()); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.BYTE).sizes("[1,2,3]").time(1000L) .timens(7000).value("[1,2,3,4,5,6]").build(); VByteArray vByteArray = (VByteArray) SnapshotDataConverter.toVType(snapshotPv); assertEquals(6, vByteArray.getData().size()); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.UBYTE).sizes("[1,2,3]").time(1000L) .timens(7000).value("[1,2,3,4,5,6]").build(); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VUByteArray); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.INTEGER) .sizes(SnapshotDataConverter.SCALAR_AS_JSON).time(1000L).timens(7000).value("[1]").build(); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VInt); snapshotPv.setDataType(SnapshotPvDataType.UINTEGER); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VUInt); snapshotPv.setDataType(SnapshotPvDataType.SHORT); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VShort); snapshotPv.setDataType(SnapshotPvDataType.USHORT); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VUShort); snapshotPv.setDataType(SnapshotPvDataType.LONG); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VLong); snapshotPv.setDataType(SnapshotPvDataType.ULONG); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VULong); snapshotPv.setDataType(SnapshotPvDataType.FLOAT); snapshotPv.setValue("[1.1]"); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VFloat); snapshotPv.setDataType(SnapshotPvDataType.DOUBLE); snapshotPv.setValue("[1.1]"); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VDouble); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.SHORT).sizes("[1,2,3]").time(1000L) .timens(7000).value("[1,2,3,4,5,6]").build(); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VShortArray); snapshotPv.setDataType(SnapshotPvDataType.USHORT); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VUShortArray); snapshotPv.setDataType(SnapshotPvDataType.INTEGER); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VIntArray); snapshotPv.setDataType(SnapshotPvDataType.UINTEGER); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VUIntArray); snapshotPv.setDataType(SnapshotPvDataType.LONG); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VLongArray); snapshotPv.setDataType(SnapshotPvDataType.ULONG); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VULongArray); snapshotPv.setDataType(SnapshotPvDataType.FLOAT); snapshotPv.setValue("[1.1, 2.2]"); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VFloatArray); snapshotPv.setDataType(SnapshotPvDataType.DOUBLE); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VDoubleArray); snapshotPv.setDataType(SnapshotPvDataType.STRING); snapshotPv.setSizes(SnapshotDataConverter.SCALAR_AS_JSON); snapshotPv.setValue("[\"string\"]"); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VString); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.STRING).sizes("[1,2,3]").time(1000L) .timens(7000).value("[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\"]").build(); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VStringArray); snapshotPv = SnapshotPv.builder().alarmName("name").alarmStatus(AlarmStatus.NONE) .alarmSeverity(AlarmSeverity.NONE).dataType(SnapshotPvDataType.ENUM).sizes("[1]").time(1000L) .timens(7000).value("[1,[\"a\",\"b\",\"c\"]]").build(); assertTrue(SnapshotDataConverter.toVType(snapshotPv) instanceof VEnum); }
|
public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } private SnapshotDataConverter(); }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test public void jsonTest() throws Exception { VLongArray vIntArray = VLongArray.of(new ArrayLong(CollectionNumbers.toListLong(-1, 2, 3)), alarm, time, display); String json1 = org.epics.vtype.json.VTypeToJson.toJson(vIntArray).toString(); VULongArray vULongArray = VULongArray.of(new ArrayULong(CollectionNumbers.toListULong(1, 2, 3)), alarm, time, display); VTypeToJson.toJson(vULongArray).toString(); VLongArray deserialized1 = (VLongArray) VTypeToJson .toVType(Json.createReader(new ByteArrayInputStream(json1.getBytes())).readObject()); assertEquals(-1, deserialized1.getData().getLong(0)); }
|
public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } private SnapshotDataConverter(); }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { public static VType toVType(SnapshotPv snapshotPv) { if(snapshotPv.getValue() == null) { return null; } ObjectMapper objectMapper = new ObjectMapper(); boolean isScalar = SCALAR_AS_JSON.equals(snapshotPv.getSizes()); ListInteger sizes = toSizes(snapshotPv); Alarm alarm = toAlarm(snapshotPv); Time time = toTime(snapshotPv); Display display = Display.none(); try { switch(snapshotPv.getDataType()) { case BYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListByte(values), sizes, alarm, time, display); } } case UBYTE:{ byte[] values = objectMapper.readValue(snapshotPv.getValue(), byte[].class); if(isScalar) { return VUByte.of(values[0], alarm, time, display); } else { return VByteArray.of(CollectionNumbers.toListUByte(values), sizes, alarm, time, display); } } case SHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VShort.of(values[0], alarm, time, display); } else { return VShortArray.of(CollectionNumbers.toListShort(values), sizes, alarm, time, display); } } case USHORT:{ short[] values = objectMapper.readValue(snapshotPv.getValue(), short[].class); if(isScalar) { return VUShort.of(values[0], alarm, time, display); } else { return VUShortArray.of(CollectionNumbers.toListUShort(values), sizes, alarm, time, display); } } case INTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VInt.of(values[0], alarm, time, display); } else { return VIntArray.of(CollectionNumbers.toListInt(values), sizes, alarm, time, display); } } case UINTEGER:{ int[] values = objectMapper.readValue(snapshotPv.getValue(), int[].class); if(isScalar) { return VUInt.of(values[0], alarm, time, display); } else { return VUIntArray.of(CollectionNumbers.toListUInt(values), sizes, alarm, time, display); } } case LONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VLong.of(values[0], alarm, time, display); } else { return VLongArray.of(CollectionNumbers.toListLong(values), sizes, alarm, time, display); } } case ULONG:{ long[] values = objectMapper.readValue(snapshotPv.getValue(), long[].class); if(isScalar) { return VULong.of(values[0], alarm, time, display); } else { return VULongArray.of(CollectionNumbers.toListULong(values), sizes, alarm, time, display); } } case FLOAT:{ float[] values = objectMapper.readValue(snapshotPv.getValue(), float[].class); if(isScalar) { return VFloat.of(values[0], alarm, time, display); } else { return VFloatArray.of(CollectionNumbers.toListFloat(values), sizes, alarm, time, display); } } case DOUBLE:{ double[] values = objectMapper.readValue(snapshotPv.getValue(), double[].class); if(isScalar) { return VDouble.of(values[0], alarm, time, display); } else { return VDoubleArray.of(CollectionNumbers.toListDouble(values), sizes, alarm, time, display); } } case STRING:{ String[] values = objectMapper.readValue(snapshotPv.getValue(), String[].class); if(isScalar) { return VString.of(values[0], alarm, time); } else { return VStringArray.of(Arrays.asList(values), sizes, alarm, time); } } case ENUM:{ Object[] values = objectMapper.readValue(snapshotPv.getValue(), Object[].class); if (values.length == 2) { int index = (int) values[0]; List<String> choices = (List<String>) values[1]; EnumDisplay enumDisplay = EnumDisplay.of(choices); if (isScalar) { return VEnum.of(index, enumDisplay, alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else if (values.length == 1) { if (isScalar) { return VEnum.of(0, EnumDisplay.of((String) values[0]), alarm, time); } else { throw new PVConversionException("VEnumArray not supported"); } } else { throw new PVConversionException("Wrong data size! VEnum DB data has been corrupted!"); } } } } catch (Exception e) { throw new PVConversionException(String.format("Unable to convert to VType, cause: %s", e.getMessage())); } throw new PVConversionException(String.format("Cannot convert to PVType from internal type %s", snapshotPv.getDataType())); } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test public void testFromSnapshotPv() { SnapshotPv snapshotPv = SnapshotPv.builder().alarmName("name").alarmSeverity(AlarmSeverity.NONE).alarmStatus(AlarmStatus.NONE) .snapshotId(2).dataType(SnapshotPvDataType.LONG).time(1000L).timens(7000).value("[1]").sizes("[1]").configPv(ConfigPv.builder().id(1).build()).build(); SnapshotPv readback = SnapshotPv.builder().alarmName("name").alarmSeverity(AlarmSeverity.NONE).alarmStatus(AlarmStatus.NONE) .snapshotId(2).dataType(SnapshotPvDataType.LONG).time(1000L).timens(7000).value("[1]").sizes("[1]").configPv(ConfigPv.builder().id(1).build()).build(); SnapshotItem snapshotItem = SnapshotDataConverter.fromSnapshotPv(snapshotPv, readback); assertEquals(2, snapshotItem.getSnapshotId()); assertEquals(1, snapshotItem.getConfigPv().getId()); assertNotNull(snapshotItem.getReadbackValue()); snapshotPv = SnapshotPv.builder().snapshotId(1).configPv(ConfigPv.builder().id(1).build()).build(); snapshotItem = SnapshotDataConverter.fromSnapshotPv(snapshotPv, readback); assertNull(snapshotItem.getValue()); snapshotItem = SnapshotDataConverter.fromSnapshotPv(snapshotPv, null); assertNull(snapshotItem.getReadbackValue()); }
|
public static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback) { if(snapshotPv == null) { return null; } SnapshotItem snapshotItem = SnapshotItem.builder() .configPv(snapshotPv.getConfigPv()) .snapshotId(snapshotPv.getSnapshotId()) .build(); if(snapshotPv.getValue() != null) { snapshotItem.setValue(toVType(snapshotPv)); } if(readback != null) { snapshotItem.setReadbackValue(toVType(readback)); } return snapshotItem; }
|
SnapshotDataConverter { public static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback) { if(snapshotPv == null) { return null; } SnapshotItem snapshotItem = SnapshotItem.builder() .configPv(snapshotPv.getConfigPv()) .snapshotId(snapshotPv.getSnapshotId()) .build(); if(snapshotPv.getValue() != null) { snapshotItem.setValue(toVType(snapshotPv)); } if(readback != null) { snapshotItem.setReadbackValue(toVType(readback)); } return snapshotItem; } }
|
SnapshotDataConverter { public static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback) { if(snapshotPv == null) { return null; } SnapshotItem snapshotItem = SnapshotItem.builder() .configPv(snapshotPv.getConfigPv()) .snapshotId(snapshotPv.getSnapshotId()) .build(); if(snapshotPv.getValue() != null) { snapshotItem.setValue(toVType(snapshotPv)); } if(readback != null) { snapshotItem.setReadbackValue(toVType(readback)); } return snapshotItem; } private SnapshotDataConverter(); }
|
SnapshotDataConverter { public static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback) { if(snapshotPv == null) { return null; } SnapshotItem snapshotItem = SnapshotItem.builder() .configPv(snapshotPv.getConfigPv()) .snapshotId(snapshotPv.getSnapshotId()) .build(); if(snapshotPv.getValue() != null) { snapshotItem.setValue(toVType(snapshotPv)); } if(readback != null) { snapshotItem.setReadbackValue(toVType(readback)); } return snapshotItem; } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
SnapshotDataConverter { public static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback) { if(snapshotPv == null) { return null; } SnapshotItem snapshotItem = SnapshotItem.builder() .configPv(snapshotPv.getConfigPv()) .snapshotId(snapshotPv.getSnapshotId()) .build(); if(snapshotPv.getValue() != null) { snapshotItem.setValue(toVType(snapshotPv)); } if(readback != null) { snapshotItem.setReadbackValue(toVType(readback)); } return snapshotItem; } private SnapshotDataConverter(); static SnapshotItem fromSnapshotPv(SnapshotPv snapshotPv, SnapshotPv readback); static SnapshotPv fromVType(VType vType); static VType toVType(SnapshotPv snapshotPv); }
|
@Test public void testRowMapper() throws Exception { ResultSet resultSet = Mockito.mock(ResultSet.class); when(resultSet.getInt("id")).thenReturn(1); when(resultSet.getString("name")).thenReturn("name"); when(resultSet.getTimestamp("created")).thenReturn(new Timestamp(System.currentTimeMillis())); when(resultSet.getTimestamp("last_modified")).thenReturn(new Timestamp(System.currentTimeMillis())); when(resultSet.getString("username")).thenReturn("username"); when(resultSet.getString("type")).thenReturn(NodeType.FOLDER.toString()); assertTrue(new NodeRowMapper().mapRow(resultSet, 0) instanceof Node); }
|
@Override public Node mapRow(ResultSet resultSet, int rowIndex) throws SQLException { return Node.builder() .id(resultSet.getInt("id")) .nodeType(NodeType.valueOf(resultSet.getString("type"))) .created(resultSet.getTimestamp("created")) .lastModified(resultSet.getTimestamp("last_modified")) .name(resultSet.getString("name")) .userName(resultSet.getString("username")) .uniqueId(resultSet.getString("unique_id")) .build(); }
|
NodeRowMapper implements RowMapper<Node> { @Override public Node mapRow(ResultSet resultSet, int rowIndex) throws SQLException { return Node.builder() .id(resultSet.getInt("id")) .nodeType(NodeType.valueOf(resultSet.getString("type"))) .created(resultSet.getTimestamp("created")) .lastModified(resultSet.getTimestamp("last_modified")) .name(resultSet.getString("name")) .userName(resultSet.getString("username")) .uniqueId(resultSet.getString("unique_id")) .build(); } }
|
NodeRowMapper implements RowMapper<Node> { @Override public Node mapRow(ResultSet resultSet, int rowIndex) throws SQLException { return Node.builder() .id(resultSet.getInt("id")) .nodeType(NodeType.valueOf(resultSet.getString("type"))) .created(resultSet.getTimestamp("created")) .lastModified(resultSet.getTimestamp("last_modified")) .name(resultSet.getString("name")) .userName(resultSet.getString("username")) .uniqueId(resultSet.getString("unique_id")) .build(); } }
|
NodeRowMapper implements RowMapper<Node> { @Override public Node mapRow(ResultSet resultSet, int rowIndex) throws SQLException { return Node.builder() .id(resultSet.getInt("id")) .nodeType(NodeType.valueOf(resultSet.getString("type"))) .created(resultSet.getTimestamp("created")) .lastModified(resultSet.getTimestamp("last_modified")) .name(resultSet.getString("name")) .userName(resultSet.getString("username")) .uniqueId(resultSet.getString("unique_id")) .build(); } @Override Node mapRow(ResultSet resultSet, int rowIndex); }
|
NodeRowMapper implements RowMapper<Node> { @Override public Node mapRow(ResultSet resultSet, int rowIndex) throws SQLException { return Node.builder() .id(resultSet.getInt("id")) .nodeType(NodeType.valueOf(resultSet.getString("type"))) .created(resultSet.getTimestamp("created")) .lastModified(resultSet.getTimestamp("last_modified")) .name(resultSet.getString("name")) .userName(resultSet.getString("username")) .uniqueId(resultSet.getString("unique_id")) .build(); } @Override Node mapRow(ResultSet resultSet, int rowIndex); }
|
@Test public void testSnapshotPvRowMapperNullReadback() throws Exception{ ResultSet resultSet = Mockito.mock(ResultSet.class); when(resultSet.getInt("snapshot_node_id")).thenReturn(1); when(resultSet.getBoolean("fetch_status")).thenReturn(true); when(resultSet.getString("severity")).thenReturn("NONE"); when(resultSet.getString("status")).thenReturn("NONE"); when(resultSet.getLong("time")).thenReturn(777L); when(resultSet.getInt("timens")).thenReturn(1); when(resultSet.getString("value")).thenReturn("[7]"); when(resultSet.getString("sizes")).thenReturn("[1]"); when(resultSet.getString("data_type")).thenReturn("INTEGER"); when(resultSet.getString("name")).thenReturn("pvname"); when(resultSet.getString("readback_name")).thenReturn("pvname"); when(resultSet.getString("provider")).thenReturn("ca"); assertTrue(new SnapshotPvRowMapper().mapRow(resultSet, 0) instanceof SnapshotPv); }
|
@Override public SnapshotPv mapRow(ResultSet resultSet, int rowIndex) throws SQLException { ConfigPv configPv = new ConfigPvRowMapper().mapRow(resultSet, rowIndex); return SnapshotPv.builder() .configPv(configPv) .snapshotId(resultSet.getInt("snapshot_node_id")) .alarmSeverity(resultSet.getString("severity") == null ? null : AlarmSeverity.valueOf(resultSet.getString("severity"))) .alarmStatus(resultSet.getString("status") == null ? null : AlarmStatus.valueOf(resultSet.getString("status"))) .time(resultSet.getLong("time")) .timens(resultSet.getInt("timens")) .value(resultSet.getString("value")) .sizes(resultSet.getString("sizes")) .dataType(resultSet.getString("data_type") == null ? null : SnapshotPvDataType.valueOf(resultSet.getString("data_type"))) .build(); }
|
SnapshotPvRowMapper implements RowMapper<SnapshotPv> { @Override public SnapshotPv mapRow(ResultSet resultSet, int rowIndex) throws SQLException { ConfigPv configPv = new ConfigPvRowMapper().mapRow(resultSet, rowIndex); return SnapshotPv.builder() .configPv(configPv) .snapshotId(resultSet.getInt("snapshot_node_id")) .alarmSeverity(resultSet.getString("severity") == null ? null : AlarmSeverity.valueOf(resultSet.getString("severity"))) .alarmStatus(resultSet.getString("status") == null ? null : AlarmStatus.valueOf(resultSet.getString("status"))) .time(resultSet.getLong("time")) .timens(resultSet.getInt("timens")) .value(resultSet.getString("value")) .sizes(resultSet.getString("sizes")) .dataType(resultSet.getString("data_type") == null ? null : SnapshotPvDataType.valueOf(resultSet.getString("data_type"))) .build(); } }
|
SnapshotPvRowMapper implements RowMapper<SnapshotPv> { @Override public SnapshotPv mapRow(ResultSet resultSet, int rowIndex) throws SQLException { ConfigPv configPv = new ConfigPvRowMapper().mapRow(resultSet, rowIndex); return SnapshotPv.builder() .configPv(configPv) .snapshotId(resultSet.getInt("snapshot_node_id")) .alarmSeverity(resultSet.getString("severity") == null ? null : AlarmSeverity.valueOf(resultSet.getString("severity"))) .alarmStatus(resultSet.getString("status") == null ? null : AlarmStatus.valueOf(resultSet.getString("status"))) .time(resultSet.getLong("time")) .timens(resultSet.getInt("timens")) .value(resultSet.getString("value")) .sizes(resultSet.getString("sizes")) .dataType(resultSet.getString("data_type") == null ? null : SnapshotPvDataType.valueOf(resultSet.getString("data_type"))) .build(); } }
|
SnapshotPvRowMapper implements RowMapper<SnapshotPv> { @Override public SnapshotPv mapRow(ResultSet resultSet, int rowIndex) throws SQLException { ConfigPv configPv = new ConfigPvRowMapper().mapRow(resultSet, rowIndex); return SnapshotPv.builder() .configPv(configPv) .snapshotId(resultSet.getInt("snapshot_node_id")) .alarmSeverity(resultSet.getString("severity") == null ? null : AlarmSeverity.valueOf(resultSet.getString("severity"))) .alarmStatus(resultSet.getString("status") == null ? null : AlarmStatus.valueOf(resultSet.getString("status"))) .time(resultSet.getLong("time")) .timens(resultSet.getInt("timens")) .value(resultSet.getString("value")) .sizes(resultSet.getString("sizes")) .dataType(resultSet.getString("data_type") == null ? null : SnapshotPvDataType.valueOf(resultSet.getString("data_type"))) .build(); } @Override SnapshotPv mapRow(ResultSet resultSet, int rowIndex); }
|
SnapshotPvRowMapper implements RowMapper<SnapshotPv> { @Override public SnapshotPv mapRow(ResultSet resultSet, int rowIndex) throws SQLException { ConfigPv configPv = new ConfigPvRowMapper().mapRow(resultSet, rowIndex); return SnapshotPv.builder() .configPv(configPv) .snapshotId(resultSet.getInt("snapshot_node_id")) .alarmSeverity(resultSet.getString("severity") == null ? null : AlarmSeverity.valueOf(resultSet.getString("severity"))) .alarmStatus(resultSet.getString("status") == null ? null : AlarmStatus.valueOf(resultSet.getString("status"))) .time(resultSet.getLong("time")) .timens(resultSet.getInt("timens")) .value(resultSet.getString("value")) .sizes(resultSet.getString("sizes")) .dataType(resultSet.getString("data_type") == null ? null : SnapshotPvDataType.valueOf(resultSet.getString("data_type"))) .build(); } @Override SnapshotPv mapRow(ResultSet resultSet, int rowIndex); }
|
@Test public void testGetSnapshot() throws Exception{ Mockito.reset(services); when(services.getSnapshot("b")).thenReturn(snapshot); MockHttpServletRequestBuilder request = get("/snapshot/b"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
@Test public void testGetNonExistingSnapshot() throws Exception{ when(services.getSnapshot("c")).thenThrow(new SnapshotNotFoundException("askdmdsf")); MockHttpServletRequestBuilder request = get("/snapshot/c"); mockMvc.perform(request).andExpect(status().isNotFound()); }
|
@GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
@Test public void testNonExistingSnapshot() throws Exception{ when(services.getSnapshot("x")).thenThrow(new SnapshotNotFoundException("lasdfk")); MockHttpServletRequestBuilder request = get("/snapshot/x").contentType(JSON); mockMvc.perform(request).andExpect(status().isNotFound()); }
|
@GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}") public Node getSnapshot(@PathVariable String uniqueNodeId) { return services.getSnapshot(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
@Test public void testGetSnapshotItems() throws Exception{ SnapshotItem si = SnapshotItem.builder() .configPv(ConfigPv.builder().id(1).pvName("pvName").build()) .snapshotId(2) .build(); when(services.getSnapshotItems("si")).thenReturn(Arrays.asList(si)); MockHttpServletRequestBuilder request = get("/snapshot/si/items"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<SnapshotItem>>() { }); }
|
@GetMapping("/snapshot/{uniqueNodeId}/items") public List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId) { return services.getSnapshotItems(uniqueNodeId); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}/items") public List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId) { return services.getSnapshotItems(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}/items") public List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId) { return services.getSnapshotItems(uniqueNodeId); } }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}/items") public List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId) { return services.getSnapshotItems(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
SnapshotController extends BaseController { @GetMapping("/snapshot/{uniqueNodeId}/items") public List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId) { return services.getSnapshotItems(uniqueNodeId); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
@Test public void testSaveSnapshot() throws Exception{ Mockito.reset(services); List<SnapshotItem> snapshotItems = Arrays.asList(SnapshotItem.builder().build()); when(services.saveSnapshot(Mockito.anyString(), Mockito.argThat(new ArgumentMatcher<List<SnapshotItem>>() { @Override public boolean matches(List<SnapshotItem> o) { return true; } }), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(Node.builder().build()); MockHttpServletRequestBuilder request = put("/snapshot/configid").param("snapshotName", "a").param("comment", "c").param("userName", "u"); mockMvc.perform(request).andExpect(status().isBadRequest()); request = put("/snapshot/configid") .contentType(JSON) .content(objectMapper.writeValueAsString(snapshotItems)) .param("snapshotName", "a").param("comment", "c").param("userName", "u"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@PutMapping("/snapshot/{configUniqueId}") public Node saveSnapshot(@PathVariable String configUniqueId, @RequestParam(required = true) String snapshotName, @RequestParam(required = true) String userName, @RequestParam(required = true) String comment, @RequestBody(required = true) List<SnapshotItem> snapshotItems) { if(snapshotName.length() == 0 || userName.length() == 0 || comment.length() == 0) { throw new IllegalArgumentException("Snapshot name, user name and comment must be of non-zero length"); } return services.saveSnapshot(configUniqueId, snapshotItems, snapshotName, userName, comment); }
|
SnapshotController extends BaseController { @PutMapping("/snapshot/{configUniqueId}") public Node saveSnapshot(@PathVariable String configUniqueId, @RequestParam(required = true) String snapshotName, @RequestParam(required = true) String userName, @RequestParam(required = true) String comment, @RequestBody(required = true) List<SnapshotItem> snapshotItems) { if(snapshotName.length() == 0 || userName.length() == 0 || comment.length() == 0) { throw new IllegalArgumentException("Snapshot name, user name and comment must be of non-zero length"); } return services.saveSnapshot(configUniqueId, snapshotItems, snapshotName, userName, comment); } }
|
SnapshotController extends BaseController { @PutMapping("/snapshot/{configUniqueId}") public Node saveSnapshot(@PathVariable String configUniqueId, @RequestParam(required = true) String snapshotName, @RequestParam(required = true) String userName, @RequestParam(required = true) String comment, @RequestBody(required = true) List<SnapshotItem> snapshotItems) { if(snapshotName.length() == 0 || userName.length() == 0 || comment.length() == 0) { throw new IllegalArgumentException("Snapshot name, user name and comment must be of non-zero length"); } return services.saveSnapshot(configUniqueId, snapshotItems, snapshotName, userName, comment); } }
|
SnapshotController extends BaseController { @PutMapping("/snapshot/{configUniqueId}") public Node saveSnapshot(@PathVariable String configUniqueId, @RequestParam(required = true) String snapshotName, @RequestParam(required = true) String userName, @RequestParam(required = true) String comment, @RequestBody(required = true) List<SnapshotItem> snapshotItems) { if(snapshotName.length() == 0 || userName.length() == 0 || comment.length() == 0) { throw new IllegalArgumentException("Snapshot name, user name and comment must be of non-zero length"); } return services.saveSnapshot(configUniqueId, snapshotItems, snapshotName, userName, comment); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
SnapshotController extends BaseController { @PutMapping("/snapshot/{configUniqueId}") public Node saveSnapshot(@PathVariable String configUniqueId, @RequestParam(required = true) String snapshotName, @RequestParam(required = true) String userName, @RequestParam(required = true) String comment, @RequestBody(required = true) List<SnapshotItem> snapshotItems) { if(snapshotName.length() == 0 || userName.length() == 0 || comment.length() == 0) { throw new IllegalArgumentException("Snapshot name, user name and comment must be of non-zero length"); } return services.saveSnapshot(configUniqueId, snapshotItems, snapshotName, userName, comment); } @GetMapping("/snapshot/{uniqueNodeId}") Node getSnapshot(@PathVariable String uniqueNodeId); @GetMapping("/snapshot/{uniqueNodeId}/items") List<SnapshotItem> getSnapshotItems(@PathVariable String uniqueNodeId); @PutMapping("/snapshot/{configUniqueId}") Node saveSnapshot(@PathVariable String configUniqueId,
@RequestParam(required = true) String snapshotName,
@RequestParam(required = true) String userName,
@RequestParam(required = true) String comment,
@RequestBody(required = true) List<SnapshotItem> snapshotItems); }
|
@Test public void testGetConfigNotNull() { when(nodeDAO.getNode("a")).thenReturn(configFromClient); Node config = services.getNode("a"); assertEquals(1, config.getId()); }
|
@Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testGetRootNode() throws Exception { when(services.getRootNode()).thenReturn(rootNode); MockHttpServletRequestBuilder request = get("/root").contentType(JSON); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); String s = result.getResponse().getContentAsString(); objectMapper.readValue(s, Node.class); }
|
@GetMapping("/root") public Node getRootNode() { return services.getRootNode(); }
|
ConfigurationController extends BaseController { @GetMapping("/root") public Node getRootNode() { return services.getRootNode(); } }
|
ConfigurationController extends BaseController { @GetMapping("/root") public Node getRootNode() { return services.getRootNode(); } }
|
ConfigurationController extends BaseController { @GetMapping("/root") public Node getRootNode() { return services.getRootNode(); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/root") public Node getRootNode() { return services.getRootNode(); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testCreateFolder() throws Exception { when(services.createNode("p", folderFromClient)).thenReturn(folderFromClient); MockHttpServletRequestBuilder request = put("/node/p").contentType(JSON) .content(objectMapper.writeValueAsString(folderFromClient)); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); String s = result.getResponse().getContentAsString(); objectMapper.readValue(s, Node.class); }
|
@PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testCreateFolderParentIdDoesNotExist() throws Exception { when(services.createNode("p", folderFromClient)) .thenThrow(new IllegalArgumentException("Parent folder does not exist")); MockHttpServletRequestBuilder request = put("/node/p").contentType(JSON) .content(objectMapper.writeValueAsString(folderFromClient)); mockMvc.perform(request).andExpect(status().isBadRequest()); }
|
@PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testCreateConfig() throws Exception { reset(services); Node config = Node.builder().nodeType(NodeType.CONFIGURATION).name("config").uniqueId("hhh") .userName("user").build(); when(services.createNode("p", config)).thenAnswer(new Answer<Node>() { public Node answer(InvocationOnMock invocation) throws Throwable { return config1; } }); MockHttpServletRequestBuilder request = put("/node/p").contentType(JSON).content(objectMapper.writeValueAsString(config)); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PutMapping("/node/{parentsUniqueId}") public Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node) { if(node.getUserName() == null || node.getUserName().isEmpty()) { throw new IllegalArgumentException("User name must be non-null and of non-zero length"); } if(node.getName() == null || node.getName().isEmpty()) { throw new IllegalArgumentException("Node name must be non-null and of non-zero length"); } return services.createNode(parentsUniqueId, node); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetChildNodes() throws Exception{ reset(services); when(services.getChildNodes("p")).thenAnswer(new Answer<List<Node>>() { public List<Node> answer(InvocationOnMock invocation) throws Throwable { return Arrays.asList(config1); } }); MockHttpServletRequestBuilder request = get("/node/p/children").contentType(JSON); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); List<Node> childNodes = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<Node>>() { }); assertEquals(1, childNodes.size()); }
|
@GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetChildNodesNonExistingNode() throws Exception{ reset(services); when(services.getChildNodes("non-existing")).thenThrow(NodeNotFoundException.class); MockHttpServletRequestBuilder request = get("/node/non-existing/children").contentType(JSON); mockMvc.perform(request).andExpect(status().isNotFound()); }
|
@GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}/children") public List<Node> getChildNodes(@PathVariable final String uniqueNodeId) { return services.getChildNodes(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetNonExistingConfig() throws Exception { when(services.getNode("x")).thenThrow(new NodeNotFoundException("lasdfk")); MockHttpServletRequestBuilder request = get("/node/x").contentType(JSON); mockMvc.perform(request).andExpect(status().isNotFound()); }
|
@GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetSnapshots() throws Exception { when(services.getSnapshots("s")).thenReturn(Arrays.asList(snapshot)); MockHttpServletRequestBuilder request = get("/config/s/snapshots").contentType(JSON); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<Node>>() { }); reset(services); }
|
@GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetSnapshotsForNonExistingConfig() throws Exception { when(services.getSnapshots("x")).thenThrow(new NodeNotFoundException("lasdfk")); MockHttpServletRequestBuilder request = get("/config/x/snapshots").contentType(JSON); mockMvc.perform(request).andExpect(status().isNotFound()); }
|
@GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/snapshots") public List<Node> getSnapshots(@PathVariable String uniqueNodeId) { return services.getSnapshots(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testDeleteFolder() throws Exception { MockHttpServletRequestBuilder request = delete("/node/a"); mockMvc.perform(request).andExpect(status().isOk()); doThrow(new IllegalArgumentException()).when(services).deleteNode("a"); request = delete("/node/a"); mockMvc.perform(request).andExpect(status().isBadRequest()); }
|
@DeleteMapping("/node/{uniqueNodeId}") public void deleteNode(@PathVariable final String uniqueNodeId) { services.deleteNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @DeleteMapping("/node/{uniqueNodeId}") public void deleteNode(@PathVariable final String uniqueNodeId) { services.deleteNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @DeleteMapping("/node/{uniqueNodeId}") public void deleteNode(@PathVariable final String uniqueNodeId) { services.deleteNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @DeleteMapping("/node/{uniqueNodeId}") public void deleteNode(@PathVariable final String uniqueNodeId) { services.deleteNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @DeleteMapping("/node/{uniqueNodeId}") public void deleteNode(@PathVariable final String uniqueNodeId) { services.deleteNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetSnapshots() { services.getSnapshots(anyString()); verify(nodeDAO, times(1)).getSnapshots(anyString()); reset(nodeDAO); }
|
@Override public List<Node> getSnapshots(String configUniqueId) { logger.info("Obtaining snapshot for config id={}", configUniqueId); return nodeDAO.getSnapshots(configUniqueId); }
|
Services implements IServices { @Override public List<Node> getSnapshots(String configUniqueId) { logger.info("Obtaining snapshot for config id={}", configUniqueId); return nodeDAO.getSnapshots(configUniqueId); } }
|
Services implements IServices { @Override public List<Node> getSnapshots(String configUniqueId) { logger.info("Obtaining snapshot for config id={}", configUniqueId); return nodeDAO.getSnapshots(configUniqueId); } }
|
Services implements IServices { @Override public List<Node> getSnapshots(String configUniqueId) { logger.info("Obtaining snapshot for config id={}", configUniqueId); return nodeDAO.getSnapshots(configUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public List<Node> getSnapshots(String configUniqueId) { logger.info("Obtaining snapshot for config id={}", configUniqueId); return nodeDAO.getSnapshots(configUniqueId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testGetFolder() throws Exception { when(services.getNode("q")).thenReturn(Node.builder().id(1).uniqueId("q").build()); MockHttpServletRequestBuilder request = get("/node/q"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetConfiguration() throws Exception { Mockito.reset(services); when(services.getNode("a")).thenReturn(Node.builder().build()); MockHttpServletRequestBuilder request = get("/node/a"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetNonExistingConfiguration() throws Exception { Mockito.reset(services); when(services.getNode("a")).thenThrow(NodeNotFoundException.class); MockHttpServletRequestBuilder request = get("/node/a"); mockMvc.perform(request).andExpect(status().isNotFound()); }
|
@GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetNonExistingFolder() throws Exception { Mockito.reset(services); when(services.getNode("a")).thenThrow(NodeNotFoundException.class); MockHttpServletRequestBuilder request = get("/node/a"); mockMvc.perform(request).andExpect(status().isNotFound()); when(services.getNode("b")).thenThrow(IllegalArgumentException.class); request = get("/node/b"); mockMvc.perform(request).andExpect(status().isBadRequest()); }
|
@GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testMoveNode() throws Exception { when(services.moveNode("a", "b", "username")).thenReturn(Node.builder().id(2).uniqueId("a").build()); MockHttpServletRequestBuilder request = post("/node/a").param("to", "b").param("username", "username"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@PostMapping("/node/{uniqueNodeId}") public Node moveNode(@PathVariable String uniqueNodeId, @RequestParam(value = "to", required = true) String to, @RequestParam(value = "username", required = true) String userName) { return services.moveNode(uniqueNodeId, to, userName); }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}") public Node moveNode(@PathVariable String uniqueNodeId, @RequestParam(value = "to", required = true) String to, @RequestParam(value = "username", required = true) String userName) { return services.moveNode(uniqueNodeId, to, userName); } }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}") public Node moveNode(@PathVariable String uniqueNodeId, @RequestParam(value = "to", required = true) String to, @RequestParam(value = "username", required = true) String userName) { return services.moveNode(uniqueNodeId, to, userName); } }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}") public Node moveNode(@PathVariable String uniqueNodeId, @RequestParam(value = "to", required = true) String to, @RequestParam(value = "username", required = true) String userName) { return services.moveNode(uniqueNodeId, to, userName); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}") public Node moveNode(@PathVariable String uniqueNodeId, @RequestParam(value = "to", required = true) String to, @RequestParam(value = "username", required = true) String userName) { return services.moveNode(uniqueNodeId, to, userName); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testUpdateConfig() throws Exception { Node config = Node.builder().nodeType(NodeType.CONFIGURATION).userName("myusername").id(0).build(); List<ConfigPv> configPvList = Arrays.asList(ConfigPv.builder().id(1).pvName("name").build()); UpdateConfigHolder holder = UpdateConfigHolder.builder().config(config).configPvList(configPvList).build(); when(services.updateConfiguration(holder.getConfig(), holder.getConfigPvList())).thenReturn(config); MockHttpServletRequestBuilder request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testUpdateConfigBadConfigPv() throws Exception { Node config = Node.builder().nodeType(NodeType.CONFIGURATION).id(0).build(); UpdateConfigHolder holder = UpdateConfigHolder.builder().build(); MockHttpServletRequestBuilder request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); mockMvc.perform(request).andExpect(status().isBadRequest()); holder.setConfig(config); request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); mockMvc.perform(request).andExpect(status().isBadRequest()); List<ConfigPv> configPvList = Arrays.asList(ConfigPv.builder().build()); holder.setConfigPvList(configPvList); when(services.updateConfiguration(holder.getConfig(), holder.getConfigPvList())).thenReturn(config); request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); mockMvc.perform(request).andExpect(status().isBadRequest()); request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); mockMvc.perform(request).andExpect(status().isBadRequest()); config.setUserName(""); request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); mockMvc.perform(request).andExpect(status().isBadRequest()); configPvList = Arrays.asList(ConfigPv.builder().pvName("").build()); holder.setConfigPvList(configPvList); request = post("/config/a/update").contentType(JSON) .content(objectMapper.writeValueAsString(holder)); mockMvc.perform(request).andExpect(status().isBadRequest()); }
|
@PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PostMapping("/config/{uniqueNodeId}/update") public ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId, @RequestBody UpdateConfigHolder updateConfigHolder) { if(updateConfigHolder.getConfig() == null) { throw new IllegalArgumentException("Cannot update a null configuration"); } else if(updateConfigHolder.getConfigPvList() == null) { throw new IllegalArgumentException("Cannot update a configration with a null config PV list"); } else if(updateConfigHolder.getConfig().getUserName() == null || updateConfigHolder.getConfig().getUserName().isEmpty()) { throw new IllegalArgumentException("Will not update a configuration where user name is null or empty"); } for(ConfigPv configPv : updateConfigHolder.getConfigPvList()) { if(configPv.getPvName() == null || configPv.getPvName().isEmpty()) { throw new IllegalArgumentException("Cannot update configuration, encountered a null or empty PV name"); } } return new ResponseEntity<>(services.updateConfiguration(updateConfigHolder.getConfig(), updateConfigHolder.getConfigPvList()), HttpStatus.OK); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetFolderIllegalArgument() throws Exception { when(services.getNode("a")).thenThrow(IllegalArgumentException.class); MockHttpServletRequestBuilder request = get("/node/a"); mockMvc.perform(request).andExpect(status().isBadRequest()); }
|
@GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/node/{uniqueNodeId}") public Node getNode(@PathVariable final String uniqueNodeId) { return services.getNode(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testUpdateNode() throws Exception { Node node = Node.builder().name("foo").uniqueId("a").build(); when(services.updateNode(node, false)).thenReturn(node); MockHttpServletRequestBuilder request = post("/node/a/update") .param("customTimeForMigration", "false") .contentType(JSON) .content(objectMapper.writeValueAsString(node)); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), Node.class); }
|
@PostMapping("/node/{uniqueNodeId}/update") public Node updateNode(@PathVariable String uniqueNodeId, @RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration, @RequestBody Node nodeToUpdate) { return services.updateNode(nodeToUpdate, Boolean.valueOf(customTimeForMigration)); }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}/update") public Node updateNode(@PathVariable String uniqueNodeId, @RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration, @RequestBody Node nodeToUpdate) { return services.updateNode(nodeToUpdate, Boolean.valueOf(customTimeForMigration)); } }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}/update") public Node updateNode(@PathVariable String uniqueNodeId, @RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration, @RequestBody Node nodeToUpdate) { return services.updateNode(nodeToUpdate, Boolean.valueOf(customTimeForMigration)); } }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}/update") public Node updateNode(@PathVariable String uniqueNodeId, @RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration, @RequestBody Node nodeToUpdate) { return services.updateNode(nodeToUpdate, Boolean.valueOf(customTimeForMigration)); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @PostMapping("/node/{uniqueNodeId}/update") public Node updateNode(@PathVariable String uniqueNodeId, @RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration, @RequestBody Node nodeToUpdate) { return services.updateNode(nodeToUpdate, Boolean.valueOf(customTimeForMigration)); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetConfigPvs() throws Exception{ ConfigPv configPv = ConfigPv.builder() .id(1) .pvName("pvname") .build(); when(services.getConfigPvs("cpv")).thenReturn(Arrays.asList(configPv)); MockHttpServletRequestBuilder request = get("/config/cpv/items"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentType(JSON)) .andReturn(); objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<ConfigPv>>() { }); }
|
@GetMapping("/config/{uniqueNodeId}/items") public List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId) { return services.getConfigPvs(uniqueNodeId); }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/items") public List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId) { return services.getConfigPvs(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/items") public List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId) { return services.getConfigPvs(uniqueNodeId); } }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/items") public List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId) { return services.getConfigPvs(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/config/{uniqueNodeId}/items") public List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId) { return services.getConfigPvs(uniqueNodeId); } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetSnapshotNotFound() { when(nodeDAO.getSnapshot("s")).thenReturn(null); try { services.getSnapshot("s"); fail("Exception expected here"); } catch (Exception e) { } reset(nodeDAO); }
|
@Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testGetFromPath() throws Exception{ when(services.getFromPath("/a/b/c")).thenReturn(null); MockHttpServletRequestBuilder request = get("/path?path=/a/b/c"); mockMvc.perform(request).andExpect(status().isNotFound()); request = get("/path"); mockMvc.perform(request).andExpect(status().isBadRequest()); Node node = Node.builder().name("name").uniqueId("uniqueId").build(); when(services.getFromPath("/a/b/c")).thenReturn(Arrays.asList(node)); request = get("/path?path=/a/b/c"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); List<Node> nodes = objectMapper.readValue(result.getResponse().getContentAsString(), new TypeReference<List<Node>>() { }); assertEquals(1, nodes.size()); }
|
@GetMapping("/path") public List<Node> getFromPath(@RequestParam(value = "path") String path){ List<Node> nodes = services.getFromPath(path); if(nodes == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return nodes; }
|
ConfigurationController extends BaseController { @GetMapping("/path") public List<Node> getFromPath(@RequestParam(value = "path") String path){ List<Node> nodes = services.getFromPath(path); if(nodes == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return nodes; } }
|
ConfigurationController extends BaseController { @GetMapping("/path") public List<Node> getFromPath(@RequestParam(value = "path") String path){ List<Node> nodes = services.getFromPath(path); if(nodes == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return nodes; } }
|
ConfigurationController extends BaseController { @GetMapping("/path") public List<Node> getFromPath(@RequestParam(value = "path") String path){ List<Node> nodes = services.getFromPath(path); if(nodes == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return nodes; } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/path") public List<Node> getFromPath(@RequestParam(value = "path") String path){ List<Node> nodes = services.getFromPath(path); if(nodes == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return nodes; } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void testGetFullPath() throws Exception{ when(services.getFullPath("nonexisting")).thenReturn(null); MockHttpServletRequestBuilder request = get("/path/nonexsiting"); mockMvc.perform(request).andExpect(status().isNotFound()); when(services.getFullPath("existing")).thenReturn("/a/b/c"); request = get("/path/existing"); MvcResult result = mockMvc.perform(request).andExpect(status().isOk()).andReturn(); assertEquals("/a/b/c", result.getResponse().getContentAsString()); }
|
@GetMapping("/path/{uniqueNodeId}") public String getFullPath(@PathVariable String uniqueNodeId){ String fullPath = services.getFullPath(uniqueNodeId); if(fullPath == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return fullPath; }
|
ConfigurationController extends BaseController { @GetMapping("/path/{uniqueNodeId}") public String getFullPath(@PathVariable String uniqueNodeId){ String fullPath = services.getFullPath(uniqueNodeId); if(fullPath == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return fullPath; } }
|
ConfigurationController extends BaseController { @GetMapping("/path/{uniqueNodeId}") public String getFullPath(@PathVariable String uniqueNodeId){ String fullPath = services.getFullPath(uniqueNodeId); if(fullPath == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return fullPath; } }
|
ConfigurationController extends BaseController { @GetMapping("/path/{uniqueNodeId}") public String getFullPath(@PathVariable String uniqueNodeId){ String fullPath = services.getFullPath(uniqueNodeId); if(fullPath == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return fullPath; } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
ConfigurationController extends BaseController { @GetMapping("/path/{uniqueNodeId}") public String getFullPath(@PathVariable String uniqueNodeId){ String fullPath = services.getFullPath(uniqueNodeId); if(fullPath == null){ throw new ResponseStatusException(HttpStatus.NOT_FOUND); } return fullPath; } @PutMapping("/node/{parentsUniqueId}") Node createNode(@PathVariable String parentsUniqueId, @RequestBody final Node node); @GetMapping("/node/{uniqueNodeId}") Node getNode(@PathVariable final String uniqueNodeId); @GetMapping("/root") Node getRootNode(); @GetMapping("/node/{uniqueNodeId}/parent") Node getParentNode(@PathVariable String uniqueNodeId); @GetMapping("/node/{uniqueNodeId}/children") List<Node> getChildNodes(@PathVariable final String uniqueNodeId); @PostMapping("/config/{uniqueNodeId}/update") ResponseEntity<Node> updateConfiguration(@PathVariable String uniqueNodeId,
@RequestBody UpdateConfigHolder updateConfigHolder); @DeleteMapping("/node/{uniqueNodeId}") void deleteNode(@PathVariable final String uniqueNodeId); @GetMapping("/config/{uniqueNodeId}/snapshots") List<Node> getSnapshots(@PathVariable String uniqueNodeId); @PostMapping("/node/{uniqueNodeId}") Node moveNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "to", required = true) String to,
@RequestParam(value = "username", required = true) String userName); @PostMapping("/node/{uniqueNodeId}/update") Node updateNode(@PathVariable String uniqueNodeId,
@RequestParam(value = "customTimeForMigration", required = true) String customTimeForMigration,
@RequestBody Node nodeToUpdate); @GetMapping("/config/{uniqueNodeId}/items") List<ConfigPv> getConfigPvs(@PathVariable String uniqueNodeId); @GetMapping("/path/{uniqueNodeId}") String getFullPath(@PathVariable String uniqueNodeId); @GetMapping("/path") List<Node> getFromPath(@RequestParam(value = "path") String path); }
|
@Test public void decodeSeverity() { assertEquals(SeverityLevel.INVALID, SeverityLevelHelper.decodeSeverity(null)); VInt intValue = VInt.of(7, Alarm.disconnected(), Time.now(), Display.none()); SeverityLevel severityLevel = SeverityLevelHelper.decodeSeverity(intValue); assertEquals(SeverityLevel.INVALID, severityLevel); intValue = VInt.of(7, Alarm.none(), Time.now(), Display.none()); severityLevel = SeverityLevelHelper.decodeSeverity(intValue); assertEquals(SeverityLevel.OK, severityLevel); intValue = VInt.of(7, Alarm.lolo(), Time.now(), Display.none()); severityLevel = SeverityLevelHelper.decodeSeverity(intValue); assertEquals(SeverityLevel.MAJOR, severityLevel); intValue = VInt.of(7, Alarm.hihi(), Time.now(), Display.none()); severityLevel = SeverityLevelHelper.decodeSeverity(intValue); assertEquals(SeverityLevel.MAJOR, severityLevel); intValue = VInt.of(7, Alarm.low(), Time.now(), Display.none()); severityLevel = SeverityLevelHelper.decodeSeverity(intValue); assertEquals(SeverityLevel.MINOR, severityLevel); intValue = VInt.of(7, Alarm.high(), Time.now(), Display.none()); severityLevel = SeverityLevelHelper.decodeSeverity(intValue); assertEquals(SeverityLevel.MINOR, severityLevel); }
|
final public static SeverityLevel decodeSeverity(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm == null) return SeverityLevel.OK; switch (alarm.getSeverity()) { case NONE: return SeverityLevel.OK; case MINOR: return SeverityLevel.MINOR; case MAJOR: return SeverityLevel.MAJOR; case INVALID: return SeverityLevel.INVALID; default: return SeverityLevel.UNDEFINED; } }
|
SeverityLevelHelper { final public static SeverityLevel decodeSeverity(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm == null) return SeverityLevel.OK; switch (alarm.getSeverity()) { case NONE: return SeverityLevel.OK; case MINOR: return SeverityLevel.MINOR; case MAJOR: return SeverityLevel.MAJOR; case INVALID: return SeverityLevel.INVALID; default: return SeverityLevel.UNDEFINED; } } }
|
SeverityLevelHelper { final public static SeverityLevel decodeSeverity(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm == null) return SeverityLevel.OK; switch (alarm.getSeverity()) { case NONE: return SeverityLevel.OK; case MINOR: return SeverityLevel.MINOR; case MAJOR: return SeverityLevel.MAJOR; case INVALID: return SeverityLevel.INVALID; default: return SeverityLevel.UNDEFINED; } } }
|
SeverityLevelHelper { final public static SeverityLevel decodeSeverity(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm == null) return SeverityLevel.OK; switch (alarm.getSeverity()) { case NONE: return SeverityLevel.OK; case MINOR: return SeverityLevel.MINOR; case MAJOR: return SeverityLevel.MAJOR; case INVALID: return SeverityLevel.INVALID; default: return SeverityLevel.UNDEFINED; } } final static SeverityLevel decodeSeverity(final VType value); final static String getStatusMessage(final VType value); }
|
SeverityLevelHelper { final public static SeverityLevel decodeSeverity(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm == null) return SeverityLevel.OK; switch (alarm.getSeverity()) { case NONE: return SeverityLevel.OK; case MINOR: return SeverityLevel.MINOR; case MAJOR: return SeverityLevel.MAJOR; case INVALID: return SeverityLevel.INVALID; default: return SeverityLevel.UNDEFINED; } } final static SeverityLevel decodeSeverity(final VType value); final static String getStatusMessage(final VType value); }
|
@Test public void getStatusMessage() { VInt intValue = VInt.of(7, Alarm.disconnected(), Time.now(), Display.none()); String statusMessage = SeverityLevelHelper.getStatusMessage(intValue); assertEquals("Disconnected", statusMessage); intValue = VInt.of(7, Alarm.none(), Time.now(), Display.none()); statusMessage = SeverityLevelHelper.getStatusMessage(intValue); assertEquals("None", statusMessage); intValue = VInt.of(7, Alarm.lolo(), Time.now(), Display.none()); statusMessage = SeverityLevelHelper.getStatusMessage(intValue); assertEquals("LOLO", statusMessage); intValue = VInt.of(7, Alarm.hihi(), Time.now(), Display.none()); statusMessage = SeverityLevelHelper.getStatusMessage(intValue); assertEquals("HIHI", statusMessage); intValue = VInt.of(7, Alarm.low(), Time.now(), Display.none()); statusMessage = SeverityLevelHelper.getStatusMessage(intValue); assertEquals("LOW", statusMessage); intValue = VInt.of(7, Alarm.high(), Time.now(), Display.none()); statusMessage = SeverityLevelHelper.getStatusMessage(intValue); assertEquals("HIGH", statusMessage); }
|
final public static String getStatusMessage(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm != null) return alarm.getName(); return SeverityLevel.OK.toString(); }
|
SeverityLevelHelper { final public static String getStatusMessage(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm != null) return alarm.getName(); return SeverityLevel.OK.toString(); } }
|
SeverityLevelHelper { final public static String getStatusMessage(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm != null) return alarm.getName(); return SeverityLevel.OK.toString(); } }
|
SeverityLevelHelper { final public static String getStatusMessage(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm != null) return alarm.getName(); return SeverityLevel.OK.toString(); } final static SeverityLevel decodeSeverity(final VType value); final static String getStatusMessage(final VType value); }
|
SeverityLevelHelper { final public static String getStatusMessage(final VType value) { final Alarm alarm = Alarm.alarmOf(value); if (alarm != null) return alarm.getName(); return SeverityLevel.OK.toString(); } final static SeverityLevel decodeSeverity(final VType value); final static String getStatusMessage(final VType value); }
|
@Test public void getValue() { VDouble vDouble = VDouble.of(7.7, Alarm.none(), Time.now(), Display.none()); PlotSample plotSample = new PlotSample(new AtomicInteger(0), "source", vDouble, "info"); double result = plotSample.getValue(); assertEquals(7.7, result, 0); VDoubleArray vDoubleArray = VDoubleArray.of(ArrayDouble.of(7.7, 8.8, 9.9), Alarm.none(), Time.now(), Display.none()); plotSample = new PlotSample(new AtomicInteger(1), "source", vDoubleArray, "info"); result = plotSample.getValue(); assertEquals(8.8, result, 0); }
|
@Override public double getValue() { return org.phoebus.core.vtypes.VTypeHelper.toDouble(value, waveform_index.get()); }
|
PlotSample implements PlotDataItem<Instant> { @Override public double getValue() { return org.phoebus.core.vtypes.VTypeHelper.toDouble(value, waveform_index.get()); } }
|
PlotSample implements PlotDataItem<Instant> { @Override public double getValue() { return org.phoebus.core.vtypes.VTypeHelper.toDouble(value, waveform_index.get()); } PlotSample(final AtomicInteger waveform_index, final String source, final VType value, final String info); PlotSample(final AtomicInteger waveform_index, final String source, final VType value); PlotSample(final String source, final VType value); PlotSample(final String source, final String info); PlotSample(final double x, final double y); }
|
PlotSample implements PlotDataItem<Instant> { @Override public double getValue() { return org.phoebus.core.vtypes.VTypeHelper.toDouble(value, waveform_index.get()); } PlotSample(final AtomicInteger waveform_index, final String source, final VType value, final String info); PlotSample(final AtomicInteger waveform_index, final String source, final VType value); PlotSample(final String source, final VType value); PlotSample(final String source, final String info); PlotSample(final double x, final double y); String getSource(); VType getVType(); @Override Instant getPosition(); @Override double getValue(); @Override double getStdDev(); @Override double getMin(); @Override double getMax(); @Override String getInfo(); @Override String toString(); }
|
PlotSample implements PlotDataItem<Instant> { @Override public double getValue() { return org.phoebus.core.vtypes.VTypeHelper.toDouble(value, waveform_index.get()); } PlotSample(final AtomicInteger waveform_index, final String source, final VType value, final String info); PlotSample(final AtomicInteger waveform_index, final String source, final VType value); PlotSample(final String source, final VType value); PlotSample(final String source, final String info); PlotSample(final double x, final double y); String getSource(); VType getVType(); @Override Instant getPosition(); @Override double getValue(); @Override double getStdDev(); @Override double getMin(); @Override double getMax(); @Override String getInfo(); @Override String toString(); }
|
@Test public void testSingle() throws Exception { List<String> names = DroppedPVNameParser.parseDroppedPVs("SomePVName"); assertThat(names, equalTo(List.of("SomePVName"))); names = DroppedPVNameParser.parseDroppedPVs("loc: assertThat(names, equalTo(List.of("loc: names = DroppedPVNameParser.parseDroppedPVs("loc: assertThat(names, equalTo(List.of("loc: names = DroppedPVNameParser.parseDroppedPVs("loc: assertThat(names, equalTo(List.of("loc: }
|
public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
@Test public void testNewline() throws Exception { List<String> names = DroppedPVNameParser.parseDroppedPVs("pv1\npv2"); assertThat(names, equalTo(List.of("pv1", "pv2"))); names = DroppedPVNameParser.parseDroppedPVs("pv1\r\npv2"); assertThat(names, equalTo(List.of("pv1", "pv2"))); names = DroppedPVNameParser.parseDroppedPVs("pv1\rpv2"); assertThat(names, equalTo(List.of("pv1", "pv2"))); names = DroppedPVNameParser.parseDroppedPVs("[ pv1\npv2 ] "); assertThat(names, equalTo(List.of("pv1", "pv2"))); }
|
public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
@Test public void testTab() throws Exception { List<String> names = DroppedPVNameParser.parseDroppedPVs("pv1\tpv2"); assertThat(names, equalTo(List.of("pv1", "pv2"))); names = DroppedPVNameParser.parseDroppedPVs(" pv1 \t pv2 \t pv3"); assertThat(names, equalTo(List.of("pv1", "pv2", "pv3"))); }
|
public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
@Test public void testComma() throws Exception { List<String> names = DroppedPVNameParser.parseDroppedPVs("pv1,pv2"); assertThat(names, equalTo(List.of("pv1", "pv2"))); names = DroppedPVNameParser.parseDroppedPVs(" pv1, pv2 , pv3"); assertThat(names, equalTo(List.of("pv1", "pv2", "pv3"))); names = DroppedPVNameParser.parseDroppedPVs(" pv1, loc: assertThat(names, equalTo(List.of("pv1", "loc: names = DroppedPVNameParser.parseDroppedPVs(" pv1, sim: assertThat(names, equalTo(List.of("pv1", "sim: names = DroppedPVNameParser.parseDroppedPVs(" pv1, loc: assertThat(names, equalTo(List.of("pv1", "loc: names = DroppedPVNameParser.parseDroppedPVs(" pv1; pv2 ; pv3"); assertThat(names, equalTo(List.of("pv1", "pv2", "pv3"))); }
|
public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
@Test public void testSpace() throws Exception { List<String> names = DroppedPVNameParser.parseDroppedPVs("pv1 pv2"); assertThat(names, equalTo(List.of("pv1", "pv2"))); names = DroppedPVNameParser.parseDroppedPVs("pv1 sim: assertThat(names, equalTo(List.of("pv1", "sim: names = DroppedPVNameParser.parseDroppedPVs(" pv1 loc: assertThat(names, equalTo(List.of("pv1", "loc: }
|
public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
DroppedPVNameParser { public static List<String> parseDroppedPVs(String text) throws Exception { text = text.trim(); if (text.startsWith("[") && text.endsWith("]")) text = text.substring(1, text.length()-2); final List<String> names = new ArrayList<>(); final int len = text.length(); int start = 0, pos = 0; while (pos < len) { final char c = text.charAt(pos); if (c == '"') pos = locateClosingQuote(text, pos+1); else if (c == '(') pos = locateClosingBrace(text, pos+1); else if ("\r\n\t,; ".indexOf(c) >= 0) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); start = ++pos; } else ++pos; } if (pos > start) { final String name = text.substring(start, pos).trim(); if (! name.isEmpty()) names.add(name); } return names; } static List<String> parseDroppedPVs(String text); }
|
@Test public void testGetSnapshot() { when(nodeDAO.getSnapshot("s")).thenReturn(mock(Node.class)); Node snapshot = services.getSnapshot("s"); assertNotNull(snapshot); reset(nodeDAO); }
|
@Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public Node getSnapshot(String snapshotUniqueId) { Node snapshot = nodeDAO.getSnapshot(snapshotUniqueId); if (snapshot == null) { String message = String.format("Snapshot with id=%s not found", snapshotUniqueId); logger.error(message); throw new SnapshotNotFoundException(message); } logger.info("Retrieved snapshot id={}", snapshotUniqueId); return snapshot; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testRoundUp() throws Exception { final Instant orig = Instant.from(TimestampFormats.SECONDS_FORMAT.parse("2012-01-19 12:23:14")); String text = TimestampFormats.SECONDS_FORMAT.format(orig); System.out.println(text); assertThat(text, equalTo("2012-01-19 12:23:14")); Instant time; time = TimestampHelper.roundUp(orig, 10); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-19 12:23:20")); time = TimestampHelper.roundUp(orig, TimeDuration.ofSeconds(30)); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-19 12:23:30")); time = TimestampHelper.roundUp(orig, 60); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-19 12:24:00")); time = TimestampHelper.roundUp(orig, TimeDuration.ofHours(1.0)); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-19 13:00:00")); time = TimestampHelper.roundUp(orig, 2L*60*60); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-19 14:00:00")); assertThat(24L*60*60, equalTo(TimestampHelper.SECS_PER_DAY)); time = TimestampHelper.roundUp(orig, TimestampHelper.SECS_PER_DAY); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-20 00:00:00")); time = TimestampHelper.roundUp(orig, 3*TimestampHelper.SECS_PER_DAY); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-22 00:00:00")); time = TimestampHelper.roundUp(orig, 13*TimestampHelper.SECS_PER_DAY); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-02-01 00:00:00")); assertThat(24L*60*60, equalTo(TimestampHelper.SECS_PER_DAY)); time = TimestampHelper.roundUp(orig, (3*TimestampHelper.SECS_PER_DAY)/2); text = TimestampFormats.SECONDS_FORMAT.format(time); System.out.println(text); assertThat(text, equalTo("2012-01-20 12:00:00")); }
|
public static Instant roundUp(final Instant time, final Duration duration) { return roundUp(time, duration.getSeconds()); }
|
TimestampHelper { public static Instant roundUp(final Instant time, final Duration duration) { return roundUp(time, duration.getSeconds()); } }
|
TimestampHelper { public static Instant roundUp(final Instant time, final Duration duration) { return roundUp(time, duration.getSeconds()); } }
|
TimestampHelper { public static Instant roundUp(final Instant time, final Duration duration) { return roundUp(time, duration.getSeconds()); } static Instant roundUp(final Instant time, final Duration duration); static Instant roundUp(final Instant time, final long seconds); static Timestamp toSQLTimestamp(Instant start); static Instant fromSQLTimestamp(Timestamp timestamp); }
|
TimestampHelper { public static Instant roundUp(final Instant time, final Duration duration) { return roundUp(time, duration.getSeconds()); } static Instant roundUp(final Instant time, final Duration duration); static Instant roundUp(final Instant time, final long seconds); static Timestamp toSQLTimestamp(Instant start); static Instant fromSQLTimestamp(Timestamp timestamp); final static long SECS_PER_HOUR; final static long SECS_PER_MINUTE; final static long SECS_PER_DAY; }
|
@Test public void testConverter() throws Exception { EdmModel.reloadEdmColorFile("colors.list", getClass().getResourceAsStream("/colors.list")); final File edl = new File(getClass().getResource("/Maintenance_12hr.edl").getFile()); final EdmConverter converter = new EdmConverter(edl, null); final ByteArrayOutputStream buf = new ByteArrayOutputStream(); final ModelWriter writer = new ModelWriter(buf); writer.writeModel(converter.getDisplayModel()); writer.close(); System.out.println(buf.toString()); }
|
public DisplayModel getDisplayModel() { return model; }
|
EdmConverter { public DisplayModel getDisplayModel() { return model; } }
|
EdmConverter { public DisplayModel getDisplayModel() { return model; } EdmConverter(final File input, final AssetLocator asset_locator); }
|
EdmConverter { public DisplayModel getDisplayModel() { return model; } EdmConverter(final File input, final AssetLocator asset_locator); DisplayModel getDisplayModel(); void write(final File output); int nextGroup(); void downloadAsset(final String asset); Collection<String> getIncludedDisplays(); Collection<String> getLinkedDisplays(); void addPositionOffset(final int x, final int y); int getOffsetX(); int getOffsetY(); void convertWidget(final Widget parent, final EdmEntity edm); void correctChildWidgets(final Widget parent); void addIncludedDisplay(final String included_display); void addLinkedDisplay(final String linked_display); }
|
EdmConverter { public DisplayModel getDisplayModel() { return model; } EdmConverter(final File input, final AssetLocator asset_locator); DisplayModel getDisplayModel(); void write(final File output); int nextGroup(); void downloadAsset(final String asset); Collection<String> getIncludedDisplays(); Collection<String> getLinkedDisplays(); void addPositionOffset(final int x, final int y); int getOffsetX(); int getOffsetY(); void convertWidget(final Widget parent, final EdmEntity edm); void correctChildWidgets(final Widget parent); void addIncludedDisplay(final String included_display); void addLinkedDisplay(final String linked_display); }
|
@Test public void testCache() throws Exception { final Cache<String> cache = new Cache<>(Duration.ofSeconds(2)); final CountDownLatch set_A = new CountDownLatch(1); final AtomicReference<String> A = new AtomicReference<>(); final ExecutorService pool = Executors.newCachedThreadPool(); pool.submit(() -> { final String key = "A"; logger.fine("> Requesting " + key + " for 1st time ..."); A.set(cache.getCachedOrNew(key, this::createEntry)); set_A.countDown(); logger.fine("< Got initial" + key); return null; }); pool.submit(() -> { final String key = "B"; logger.fine("> Requesting " + key + "..."); cache.getCachedOrNew(key, this::createEntry); logger.fine("< Got " + key); return null; }); pool.submit(() -> { final String key = "A"; logger.fine("> Requesting " + key + " again (cached)..."); cache.getCachedOrNew(key, this::createEntry); logger.fine("< Got cached " + key); return null; }); String A2 = cache.getCachedOrNew("A", this::createEntry); assertThat(A2, equalTo("Entry for A")); set_A.await(); assertThat(A2, sameInstance(A.get())); logger.fine("Allowing to expire"); TimeUnit.SECONDS.sleep(3); A2 = cache.getCachedOrNew("A", this::createEntry); assertThat(A2, not(sameInstance(A.get()))); logger.fine("Waiting for cache cleanup"); TimeUnit.SECONDS.sleep(6); final Collection<String> keys = cache.getKeys(); logger.fine("Remaining entries: " + keys); assertThat(keys.size(), equalTo(0)); }
|
public Cache(final Duration timeout) { this.timeout = timeout; }
|
Cache { public Cache(final Duration timeout) { this.timeout = timeout; } }
|
Cache { public Cache(final Duration timeout) { this.timeout = timeout; } Cache(final Duration timeout); }
|
Cache { public Cache(final Duration timeout) { this.timeout = timeout; } Cache(final Duration timeout); T getCachedOrNew(final String key, final CreateEntry<String, T> creator); Collection<String> getKeys(); void clear(); }
|
Cache { public Cache(final Duration timeout) { this.timeout = timeout; } Cache(final Duration timeout); T getCachedOrNew(final String key, final CreateEntry<String, T> creator); Collection<String> getKeys(); void clear(); }
|
@Test public void testParse() { assertThat(Version.parse("2.0.1").getMajor(), equalTo(2)); assertThat(Version.parse("2.0.1").getMinor(), equalTo(0)); assertThat(Version.parse("2.0.1").getPatch(), equalTo(1)); }
|
public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } Version(final int major, final int minor, final int patch); }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } Version(final int major, final int minor, final int patch); static Version parse(final String version); int getMajor(); int getMinor(); int getPatch(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final Version other); @Override String toString(); }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } Version(final int major, final int minor, final int patch); static Version parse(final String version); int getMajor(); int getMinor(); int getPatch(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final Version other); @Override String toString(); }
|
@Test public void testError() { try { Version.parse("2"); fail("Didn't detect invalid version"); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage(), containsString("Invalid version string")); } try { Version.parse("2.1.2.3"); fail("Didn't detect invalid version"); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage(), containsString("Invalid version string")); } }
|
public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } Version(final int major, final int minor, final int patch); }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } Version(final int major, final int minor, final int patch); static Version parse(final String version); int getMajor(); int getMinor(); int getPatch(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final Version other); @Override String toString(); }
|
Version implements Comparable<Version> { public static Version parse(final String version) { Matcher matcher = VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); matcher = SHORT_VERSION_PATTERN.matcher(version); if (matcher.matches()) return new Version(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), 0); throw new IllegalArgumentException("Invalid version string '" + version + "'"); } Version(final int major, final int minor, final int patch); static Version parse(final String version); int getMajor(); int getMinor(); int getPatch(); @Override int hashCode(); @Override boolean equals(final Object obj); @Override int compareTo(final Version other); @Override String toString(); }
|
@Test public void testConverter() throws Exception { final String filename = ConverterTest.class.getResource("/Main_XXXX.adl").getFile(); if (filename.isEmpty()) throw new Exception("Cannot obtain test file"); final File output = File.createTempFile("Main_XXX", ".bob"); output.deleteOnExit(); new Converter(new File(filename), output); final BufferedReader dump = new BufferedReader(new FileReader(output)); dump.lines().forEach(System.out::println); dump.close(); final ModelReader reader = new ModelReader(new FileInputStream(output)); final DisplayModel model = reader.readModel(); testCalcRule(model); }
|
public Converter(final File input, final File output) throws Exception { logger.log(Level.INFO, "Convert " + input + " -> " + output); final ADLWidget root = ParserADL.getNextElement(input); colorMap = getColorMap(root); logger.log(Level.FINE, "Color map: " + Arrays.toString(colorMap)); initializeDisplayModel(input.getName(), root); logger.log(Level.FINE, "Display '" + display.getName() + "' size " + display.propWidth().getValue() + " x " + display.propHeight().getValue()); convertChildren(root.getObjects(), display, colorMap); logger.log(Level.FINE, "Writing " + output); final ModelWriter writer = new ModelWriter(new FileOutputStream(output)); writer.writeModel(display); writer.close(); }
|
Converter { public Converter(final File input, final File output) throws Exception { logger.log(Level.INFO, "Convert " + input + " -> " + output); final ADLWidget root = ParserADL.getNextElement(input); colorMap = getColorMap(root); logger.log(Level.FINE, "Color map: " + Arrays.toString(colorMap)); initializeDisplayModel(input.getName(), root); logger.log(Level.FINE, "Display '" + display.getName() + "' size " + display.propWidth().getValue() + " x " + display.propHeight().getValue()); convertChildren(root.getObjects(), display, colorMap); logger.log(Level.FINE, "Writing " + output); final ModelWriter writer = new ModelWriter(new FileOutputStream(output)); writer.writeModel(display); writer.close(); } }
|
Converter { public Converter(final File input, final File output) throws Exception { logger.log(Level.INFO, "Convert " + input + " -> " + output); final ADLWidget root = ParserADL.getNextElement(input); colorMap = getColorMap(root); logger.log(Level.FINE, "Color map: " + Arrays.toString(colorMap)); initializeDisplayModel(input.getName(), root); logger.log(Level.FINE, "Display '" + display.getName() + "' size " + display.propWidth().getValue() + " x " + display.propHeight().getValue()); convertChildren(root.getObjects(), display, colorMap); logger.log(Level.FINE, "Writing " + output); final ModelWriter writer = new ModelWriter(new FileOutputStream(output)); writer.writeModel(display); writer.close(); } Converter(final File input, final File output); }
|
Converter { public Converter(final File input, final File output) throws Exception { logger.log(Level.INFO, "Convert " + input + " -> " + output); final ADLWidget root = ParserADL.getNextElement(input); colorMap = getColorMap(root); logger.log(Level.FINE, "Color map: " + Arrays.toString(colorMap)); initializeDisplayModel(input.getName(), root); logger.log(Level.FINE, "Display '" + display.getName() + "' size " + display.propWidth().getValue() + " x " + display.propHeight().getValue()); convertChildren(root.getObjects(), display, colorMap); logger.log(Level.FINE, "Writing " + output); final ModelWriter writer = new ModelWriter(new FileOutputStream(output)); writer.writeModel(display); writer.close(); } Converter(final File input, final File output); static void convertChildren(final List<ADLWidget> childWidgets, final Widget parentModel, final WidgetColor[] colorMap); static void main(final String[] original_args); }
|
Converter { public Converter(final File input, final File output) throws Exception { logger.log(Level.INFO, "Convert " + input + " -> " + output); final ADLWidget root = ParserADL.getNextElement(input); colorMap = getColorMap(root); logger.log(Level.FINE, "Color map: " + Arrays.toString(colorMap)); initializeDisplayModel(input.getName(), root); logger.log(Level.FINE, "Display '" + display.getName() + "' size " + display.propWidth().getValue() + " x " + display.propHeight().getValue()); convertChildren(root.getObjects(), display, colorMap); logger.log(Level.FINE, "Writing " + output); final ModelWriter writer = new ModelWriter(new FileOutputStream(output)); writer.writeModel(display); writer.close(); } Converter(final File input, final File output); static void convertChildren(final List<ADLWidget> childWidgets, final Widget parentModel, final WidgetColor[] colorMap); static void main(final String[] original_args); static final Logger logger; }
|
@Test public void testRGB() { assertThat(JFXUtil.webRGB(new WidgetColor(15, 255, 0)), equalTo("#0FFF00")); assertThat(JFXUtil.webRGB(new WidgetColor(0, 16, 255)), equalTo("#0010FF")); }
|
public static String webRGB(final WidgetColor color) { return webRGBCache.computeIfAbsent(color, col -> { if (col.getAlpha() < 255) return "rgba(" + col.getRed() + ',' + col.getGreen() + ',' + col.getBlue() + ',' + col.getAlpha()/255f + ')'; else return String.format((Locale) null, "#%02X%02X%02X", col.getRed(), col.getGreen(), col.getBlue()); }); }
|
JFXUtil extends org.phoebus.ui.javafx.JFXUtil { public static String webRGB(final WidgetColor color) { return webRGBCache.computeIfAbsent(color, col -> { if (col.getAlpha() < 255) return "rgba(" + col.getRed() + ',' + col.getGreen() + ',' + col.getBlue() + ',' + col.getAlpha()/255f + ')'; else return String.format((Locale) null, "#%02X%02X%02X", col.getRed(), col.getGreen(), col.getBlue()); }); } }
|
JFXUtil extends org.phoebus.ui.javafx.JFXUtil { public static String webRGB(final WidgetColor color) { return webRGBCache.computeIfAbsent(color, col -> { if (col.getAlpha() < 255) return "rgba(" + col.getRed() + ',' + col.getGreen() + ',' + col.getBlue() + ',' + col.getAlpha()/255f + ')'; else return String.format((Locale) null, "#%02X%02X%02X", col.getRed(), col.getGreen(), col.getBlue()); }); } }
|
JFXUtil extends org.phoebus.ui.javafx.JFXUtil { public static String webRGB(final WidgetColor color) { return webRGBCache.computeIfAbsent(color, col -> { if (col.getAlpha() < 255) return "rgba(" + col.getRed() + ',' + col.getGreen() + ',' + col.getBlue() + ',' + col.getAlpha()/255f + ')'; else return String.format((Locale) null, "#%02X%02X%02X", col.getRed(), col.getGreen(), col.getBlue()); }); } static Color convert(final WidgetColor color); static String webRGB(final WidgetColor color); static StringBuilder appendWebRGB(final StringBuilder buf, final WidgetColor color); static String shadedStyle(final WidgetColor color); static WidgetColor convert(final Color color); static Font convert(final WidgetFont font); static String cssFont(final String prefix, final Font font); static ImageView getIcon(final String name); static Pos computePos(final HorizontalAlignment horiz, final VerticalAlignment vert); }
|
JFXUtil extends org.phoebus.ui.javafx.JFXUtil { public static String webRGB(final WidgetColor color) { return webRGBCache.computeIfAbsent(color, col -> { if (col.getAlpha() < 255) return "rgba(" + col.getRed() + ',' + col.getGreen() + ',' + col.getBlue() + ',' + col.getAlpha()/255f + ')'; else return String.format((Locale) null, "#%02X%02X%02X", col.getRed(), col.getGreen(), col.getBlue()); }); } static Color convert(final WidgetColor color); static String webRGB(final WidgetColor color); static StringBuilder appendWebRGB(final StringBuilder buf, final WidgetColor color); static String shadedStyle(final WidgetColor color); static WidgetColor convert(final Color color); static Font convert(final WidgetFont font); static String cssFont(final String prefix, final Font font); static ImageView getIcon(final String name); static Pos computePos(final HorizontalAlignment horiz, final VerticalAlignment vert); }
|
@Test public void testSVGHelper(){ try { Image image = SVGHelper.loadSVG(getPath("interlock.svg"), 400d, 400d); assertTrue(image.getHeight() > 0); assertTrue(image.getWidth() > 0); } catch (Exception e) { fail(e.getMessage()); } }
|
public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
@Test public void testSVGHelperPngFile(){ String path = null; try { path = getPath("interlock.png"); } catch (Exception e) { fail(e.getMessage()); return; } assertNull(SVGHelper.loadSVG(path, 400d, 400d)); }
|
public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
@Test public void testSVGHelperJpgFile(){ String path = null; try { path = getPath("interlock.jpg"); } catch (Exception e) { fail(e.getMessage()); return; } assertNull(SVGHelper.loadSVG(path, 400d, 400d)); }
|
public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
@Test(expected = IllegalArgumentException.class) public void createNewFolderNoParentSpecified() { Node folderFromClient = Node.builder().name("SomeFolder").build(); services.createNode(null, folderFromClient); }
|
@Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public Node createNode(String parentsUniqueId, Node node) { Node parentFolder = nodeDAO.getNode(parentsUniqueId); if (parentFolder == null || !parentFolder.getNodeType().equals(NodeType.FOLDER)) { String message = String.format("Cannot create new folder as parent folder with id=%s does not exist.", parentsUniqueId); logger.error(message); throw new IllegalArgumentException(message); } node = nodeDAO.createNode(parentsUniqueId, node); logger.info("Created new node: {}", node); return node; } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testSVGHelperGifFile() throws Exception{ String path = null; try { path = getPath("interlock.gif"); } catch (Exception e) { fail(e.getMessage()); return; } assertNull(SVGHelper.loadSVG(path, 400d, 400d)); }
|
public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
@Test public void testSVGHelperTiffFile() throws Exception{ String path = null; try { path = getPath("interlock.tiff"); } catch (Exception e) { fail(e.getMessage()); return; } assertNull(SVGHelper.loadSVG(path, 400d, 400d)); }
|
public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
SVGHelper { public static Image loadSVG(String imageFileName, double width, double height){ String cachedSVGFileName = imageFileName + "_" + width + "_" + height; return ImageCache.cache(cachedSVGFileName, () -> { try(InputStream inputStream = ModelResourceUtil.openResourceStream(imageFileName)){ return loadSVG(inputStream, width, height); } catch ( Exception ex ) { logger.log(Level.WARNING, String.format("Failure loading image: %s", imageFileName), ex); } return null; }); } static Image loadSVG(String imageFileName, double width, double height); static Image loadSVG(InputStream fileStream, double width, double height); }
|
@Test(expected = UnsupportedOperationException.class) public void testRandomFile() { File file = new File(getClass().getClassLoader().getResource("random.txt").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testEmptyBOBList() { File file = new File(getClass().getClassLoader().getResource("bob/root_with_no_children.bob").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); assertTrue("Failed to parse a bob screen with no children, expected empty list but found list " + result , result.isEmpty()); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testEmptyOPIList() { File file = new File(getClass().getClassLoader().getResource("opi/root_with_no_children.opi").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); assertTrue("Failed to parse a bob screen with no children, expected empty list but found list " + result , result.isEmpty()); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testBOBList() { File file = new File(getClass().getClassLoader().getResource("bob/root.bob").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); Set<File> expectedFiles = new HashSet<>(); expectedFiles.add(new File(getClass().getClassLoader().getResource("bob/child_1/child_1.bob").getFile())); expectedFiles.add(new File(getClass().getClassLoader().getResource("bob/child_1/grand_child_1_1/grand_child_1_1.bob").getFile())); expectedFiles.add(new File(getClass().getClassLoader().getResource("bob/child_2/child_2.bob").getFile())); expectedFiles.add(new File(getClass().getClassLoader().getResource("bob/child_3/child_3.bob").getFile())); assertThat(result, is(expectedFiles)); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testOPIList() { File file = new File(getClass().getClassLoader().getResource("opi/root.opi").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); Set<File> expectedFiles = new HashSet<>(); expectedFiles.add(new File(getClass().getClassLoader().getResource("opi/child_1/child_1.opi").getFile())); expectedFiles.add(new File(getClass().getClassLoader().getResource("opi/child_1/grand_child_1_1/grand_child_1_1.opi").getFile())); expectedFiles.add(new File(getClass().getClassLoader().getResource("opi/child_2/child_2.opi").getFile())); expectedFiles.add(new File(getClass().getClassLoader().getResource("opi/child_3/child_3.opi").getFile())); assertThat(result, is(expectedFiles)); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testBOBCyclicLinksList() { File file = new File(getClass().getClassLoader().getResource("bob/cyclic/cyclic_1.bob").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); Set<File> expectedFiles = new HashSet<>(); expectedFiles.add(new File(getClass().getClassLoader().getResource("bob/cyclic/cyclic_2.bob").getFile())); assertThat(result, is(expectedFiles)); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testOPICyclicLinksList() { File file = new File(getClass().getClassLoader().getResource("opi/cyclic/cyclic_1.opi").getFile()); ProcessOPI processOPI = new ProcessOPI(file); Set<File> result = processOPI.process(); Set<File> expectedFiles = new HashSet<>(); expectedFiles.add(new File(getClass().getClassLoader().getResource("opi/cyclic/cyclic_2.opi").getFile())); assertThat(result, is(expectedFiles)); }
|
public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
ProcessOPI { public Set<File> process() { getExtensionByStringHandling(this.rootFile.getName()).ifPresentOrElse(ext -> { if (!ext.equalsIgnoreCase("bob") && !ext.equalsIgnoreCase("opi")) { throw new UnsupportedOperationException("File extension " + ext + " is not supported. The supported extensions are .bob and .opi."); } }, () -> { throw new UnsupportedOperationException("File extension unknown"); }); System.out.println("Processing file : " + this.rootFile); getAllLinkedFiles(this.rootFile); return this.allLinkedFiles; } ProcessOPI(File rootFile); Set<File> process(); static synchronized Set<File> getLinkedFiles(File file); }
|
@Test public void testReset() throws Exception { System.out.println("Timeout in 4 secs?"); final ResettableTimeout timer = new ResettableTimeout(4); final ScheduledExecutorService resetter = Executors.newSingleThreadScheduledExecutor(); resetter.scheduleAtFixedRate(() -> { System.out.println("Reset.."); timer.reset(); }, 1, 1, TimeUnit.SECONDS); assertThat(timer.awaitTimeout(8), equalTo(false)); resetter.shutdown(); System.out.println("Stopped the resets. Should now time out in 4 secs"); assertThat(timer.awaitTimeout(6), equalTo(true)); timer.shutdown(); }
|
public void reset() { final ScheduledFuture<?> previous = timeout.getAndSet(timer.schedule(signal_no_more_messages, timeout_secs, TimeUnit.SECONDS)); if (previous != null) previous.cancel(false); }
|
ResettableTimeout { public void reset() { final ScheduledFuture<?> previous = timeout.getAndSet(timer.schedule(signal_no_more_messages, timeout_secs, TimeUnit.SECONDS)); if (previous != null) previous.cancel(false); } }
|
ResettableTimeout { public void reset() { final ScheduledFuture<?> previous = timeout.getAndSet(timer.schedule(signal_no_more_messages, timeout_secs, TimeUnit.SECONDS)); if (previous != null) previous.cancel(false); } ResettableTimeout(final long timeout_secs); }
|
ResettableTimeout { public void reset() { final ScheduledFuture<?> previous = timeout.getAndSet(timer.schedule(signal_no_more_messages, timeout_secs, TimeUnit.SECONDS)); if (previous != null) previous.cancel(false); } ResettableTimeout(final long timeout_secs); void reset(); boolean awaitTimeout(final long seconds); void shutdown(); }
|
ResettableTimeout { public void reset() { final ScheduledFuture<?> previous = timeout.getAndSet(timer.schedule(signal_no_more_messages, timeout_secs, TimeUnit.SECONDS)); if (previous != null) previous.cancel(false); } ResettableTimeout(final long timeout_secs); void reset(); boolean awaitTimeout(final long seconds); void shutdown(); }
|
@Test public void testGetFolder() { when(nodeDAO.getNode("a")).thenReturn(Node.builder().id(77).uniqueId("a").build()); assertNotNull(services.getNode("a")); }
|
@Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
Services implements IServices { @Override public Node getNode(String nodeId) { logger.info("Getting node {}", nodeId); return nodeDAO.getNode(nodeId); } @Override Node getParentNode(String uniqueNodeId); @Override List<Node> getSnapshots(String configUniqueId); @Override Node getSnapshot(String snapshotUniqueId); @Override Node createNode(String parentsUniqueId, Node node); @Override @Transactional Node moveNode(String nodeId, String targetNodeId, String userName); @Override @Transactional void deleteNode(String nodeId); @Override @Transactional Node updateConfiguration(Node configToUpdate, List<ConfigPv> configPvs); @Override Node updateNode(Node nodeToUpdate); @Override Node updateNode(Node nodeToUpdate, boolean customTimeForMigration); @Override Node getNode(String nodeId); @Override List<Node> getChildNodes(String nodeUniqueId); @Override Node getRootNode(); @Override List<ConfigPv> getConfigPvs(String configUniqueId); @Override List<SnapshotItem> getSnapshotItems(String snapshotUniqueId); @Override Node saveSnapshot(String configUniqueId, List<SnapshotItem> snapshotItems, String snapshotName,
String userName, String comment); @Override List<Tag> getTags(String snapshotUniqueId); @Override List<Tag> getAllTags(); @Override List<Node> getFromPath(String path); @Override String getFullPath(String uniqueNodeId); }
|
@Test public void testURLEncoding() { String pathWithDelimiter = "OPR/TEST/sim: String pathWithColon = "OPR/TEST/SR:test:pv"; String pathWithDelimiterAndColon = "OPR/TEST/sim: String encodedPathWithDelimiter = "OPR/TEST/sim%3A%2F%2Ftest"; String encodedPathWithColon = "OPR/TEST/SR%3Atest%3Apv"; String encodedPathWithDelimiterAndColon = "OPR/TEST/sim%3A%2F%2FSR%3Atest%3Apv"; assertEquals("Failed to encode pv name the delimiter", encodedPathWithDelimiter, AlarmContext.encodedURLPath(pathWithDelimiter)); assertEquals("Failed to encode pv name with colon", encodedPathWithColon, AlarmContext.encodedURLPath(pathWithColon)); assertEquals("Failed to encode pv name with delimiter and colon", encodedPathWithDelimiterAndColon, AlarmContext.encodedURLPath(pathWithDelimiterAndColon)); }
|
static String encodedURLPath(String path) { return String.valueOf(path).replace(": }
|
AlarmContext { static String encodedURLPath(String path) { return String.valueOf(path).replace(": } }
|
AlarmContext { static String encodedURLPath(String path) { return String.valueOf(path).replace(": } }
|
AlarmContext { static String encodedURLPath(String path) { return String.valueOf(path).replace(": } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(AlarmPV alarmPV, boolean enable); }
|
AlarmContext { static String encodedURLPath(String path) { return String.valueOf(path).replace(": } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(AlarmPV alarmPV, boolean enable); }
|
@Test public void testURLDecoding() { String pathWithDelimiter = "OPR/TEST/sim: String pathWithColon = "OPR/TEST/SR:test:pv"; String pathWithDelimiterAndColon = "OPR/TEST/sim: String encodedPathWithDelimiter = "OPR/TEST/sim%3A%2F%2Ftest"; String encodedPathWithColon = "OPR/TEST/SR%3Atest%3Apv"; String encodedPathWithDelimiterAndColon = "OPR/TEST/sim%3A%2F%2FSR%3Atest%3Apv"; assertEquals("Failed to decode pv name the delimiter", pathWithDelimiter, AlarmContext.decodedURLPath(encodedPathWithDelimiter)); assertEquals("Failed to decode pv name with colon", pathWithColon, AlarmContext.decodedURLPath(encodedPathWithColon)); assertEquals("Failed to decode pv name with delimiter and colon", pathWithDelimiterAndColon, AlarmContext.decodedURLPath(encodedPathWithDelimiterAndColon)); }
|
static String decodedURLPath(String path) { return String.valueOf(path).replace(encodecDelimiter, ": }
|
AlarmContext { static String decodedURLPath(String path) { return String.valueOf(path).replace(encodecDelimiter, ": } }
|
AlarmContext { static String decodedURLPath(String path) { return String.valueOf(path).replace(encodecDelimiter, ": } }
|
AlarmContext { static String decodedURLPath(String path) { return String.valueOf(path).replace(encodecDelimiter, ": } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(AlarmPV alarmPV, boolean enable); }
|
AlarmContext { static String decodedURLPath(String path) { return String.valueOf(path).replace(encodecDelimiter, ": } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(AlarmPV alarmPV, boolean enable); }
|
@Test public void testKafkaPathDecoding() { String pathWithDelimiter = "OPR/TEST/sim: String pathWithColon = "OPR/TEST/SR:test:pv"; String pathWithDelimiterAndColon = "OPR/TEST/sim: String encodedPathWithDelimiter = "OPR/TEST/sim:\\/\\/test"; String encodedPathWithColon = "OPR/TEST/SR:test:pv"; String encodedPathWithDelimiterAndColon = "OPR/TEST/sim:\\/\\/SR:test:pv"; assertEquals("Failed to decode pv kafka path the delimiter", pathWithDelimiter, AlarmContext.decodedKafaPath(encodedPathWithDelimiter)); assertEquals("Failed to decode pv kafka path with colon", pathWithColon, AlarmContext.decodedKafaPath(encodedPathWithColon)); assertEquals("Failed to decode pv kafka path with delimiter and colon", pathWithDelimiterAndColon, AlarmContext.decodedKafaPath(encodedPathWithDelimiterAndColon)); }
|
static String decodedKafaPath(String path) { return path.replace("\\/","/"); }
|
AlarmContext { static String decodedKafaPath(String path) { return path.replace("\\/","/"); } }
|
AlarmContext { static String decodedKafaPath(String path) { return path.replace("\\/","/"); } }
|
AlarmContext { static String decodedKafaPath(String path) { return path.replace("\\/","/"); } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(AlarmPV alarmPV, boolean enable); }
|
AlarmContext { static String decodedKafaPath(String path) { return path.replace("\\/","/"); } static synchronized void registerPV(AlarmPV alarmPV); static synchronized void releasePV(AlarmPV alarmPV); static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack); static synchronized void enablePV(AlarmPV alarmPV, boolean enable); }
|
@Test public void testGivenNoExistingCategoryAddingChildFormulaToRootNodeCreatesCategory() { String categoryName = "CATEGORY"; String formula1Name = "TEST_NAME"; FormulaFunction func = createFormula(formula1Name, "TEST_DESC", categoryName); FormulaTreeRootNode rootNode = new FormulaTreeRootNode(); rootNode.addChild(func); assertThat(rootNode.getChildren().size(), equalTo(1)); TreeItem<FormulaTreeByCategoryNode> category = rootNode.getChildren().get(0); assertThat(category.getValue().getSignature(), equalTo(categoryName)); assertThat(category.getValue().getDescription(), equalTo("")); assertThat(category.getChildren().size(), equalTo(1)); List<String> formulaSignatures = getFormulaSignaturesFromCategory(category); assertTrue(formulaSignatures.contains(formula1Name + "()")); }
|
public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } FormulaTreeRootNode(); }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } FormulaTreeRootNode(); void addChild(FormulaFunction child); }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } FormulaTreeRootNode(); void addChild(FormulaFunction child); }
|
@Test public void testGivenExistingCategoryAddingChildFormulaToRootNodeDoesNotCreateCategory() { String categoryName = "CATEGORY"; String formula1Name = "TEST_NAME"; String formula2Name = "TEST_NAME2"; FormulaFunction firstFunc = createFormula(formula1Name, "TEST_DESC", categoryName); FormulaFunction secondFunc = createFormula(formula2Name, "TEST_DESC2", categoryName); FormulaTreeRootNode rootNode = new FormulaTreeRootNode(); rootNode.addChild(firstFunc); assertThat(rootNode.getChildren().size(), equalTo(1)); rootNode.addChild(secondFunc); assertThat(rootNode.getChildren().size(), equalTo(1)); TreeItem<FormulaTreeByCategoryNode> category = rootNode.getChildren().get(0); assertThat(category.getChildren().size(), equalTo(2)); List<String> formulaSignatures = getFormulaSignaturesFromCategory(category); assertTrue(formulaSignatures.contains(formula1Name + "()")); assertTrue(formulaSignatures.contains(formula2Name + "()")); }
|
public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } FormulaTreeRootNode(); }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } FormulaTreeRootNode(); void addChild(FormulaFunction child); }
|
FormulaTreeRootNode extends TreeItem<FormulaTreeByCategoryNode> { public void addChild(FormulaFunction child) { for (FormulaTreeCategoryNode category : categories) { if (category.getValue().getSignature().equals(child.getCategory())) { category.addChild(child); return; } } FormulaTreeCategoryNode newCategory = new FormulaTreeCategoryNode(child); categories.add(newCategory); this.getChildren().add(newCategory); } FormulaTreeRootNode(); void addChild(FormulaFunction child); }
|
@Test public void testCompareTo() { Node folder1 = Node.builder().name("a").build(); Node folder2 = Node.builder().name("b").build(); Node folder3 = Node.builder().name("a").build(); Node config = Node.builder().nodeType(NodeType.CONFIGURATION).name("c1").build(); Node config2 = Node.builder().nodeType(NodeType.CONFIGURATION).name("c2").build(); assertTrue(folder3.compareTo(folder1) == 0); assertTrue(folder2.compareTo(folder1) > 0); assertTrue(folder1.compareTo(folder2) < 0); assertTrue(folder1.compareTo(config) < 0); assertTrue(config.compareTo(folder1) > 0); assertTrue(config.compareTo(config2) < 0); }
|
@Override public int compareTo(Node other) { if(nodeType.equals(NodeType.FOLDER) && other.getNodeType().equals(NodeType.CONFIGURATION)){ return -1; } else if(getNodeType().equals(NodeType.CONFIGURATION) && other.getNodeType().equals(NodeType.FOLDER)){ return 1; } else{ return getName().compareTo(other.getName()); } }
|
Node implements Comparable<Node> { @Override public int compareTo(Node other) { if(nodeType.equals(NodeType.FOLDER) && other.getNodeType().equals(NodeType.CONFIGURATION)){ return -1; } else if(getNodeType().equals(NodeType.CONFIGURATION) && other.getNodeType().equals(NodeType.FOLDER)){ return 1; } else{ return getName().compareTo(other.getName()); } } }
|
Node implements Comparable<Node> { @Override public int compareTo(Node other) { if(nodeType.equals(NodeType.FOLDER) && other.getNodeType().equals(NodeType.CONFIGURATION)){ return -1; } else if(getNodeType().equals(NodeType.CONFIGURATION) && other.getNodeType().equals(NodeType.FOLDER)){ return 1; } else{ return getName().compareTo(other.getName()); } } }
|
Node implements Comparable<Node> { @Override public int compareTo(Node other) { if(nodeType.equals(NodeType.FOLDER) && other.getNodeType().equals(NodeType.CONFIGURATION)){ return -1; } else if(getNodeType().equals(NodeType.CONFIGURATION) && other.getNodeType().equals(NodeType.FOLDER)){ return 1; } else{ return getName().compareTo(other.getName()); } } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other); @Override int hashCode(); @Override int compareTo(Node other); }
|
Node implements Comparable<Node> { @Override public int compareTo(Node other) { if(nodeType.equals(NodeType.FOLDER) && other.getNodeType().equals(NodeType.CONFIGURATION)){ return -1; } else if(getNodeType().equals(NodeType.CONFIGURATION) && other.getNodeType().equals(NodeType.FOLDER)){ return 1; } else{ return getName().compareTo(other.getName()); } } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other); @Override int hashCode(); @Override int compareTo(Node other); static final int ROOT_NODE_ID; }
|
@Test public void testHashCode() { Node node1 = Node.builder().uniqueId("unique").nodeType(NodeType.FOLDER).build(); Node node2 = Node.builder().uniqueId("unique").nodeType(NodeType.CONFIGURATION).build(); assertNotEquals(node1.hashCode(), node2.hashCode()); }
|
@Override public int hashCode() { return Objects.hash(nodeType, uniqueId); }
|
Node implements Comparable<Node> { @Override public int hashCode() { return Objects.hash(nodeType, uniqueId); } }
|
Node implements Comparable<Node> { @Override public int hashCode() { return Objects.hash(nodeType, uniqueId); } }
|
Node implements Comparable<Node> { @Override public int hashCode() { return Objects.hash(nodeType, uniqueId); } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other); @Override int hashCode(); @Override int compareTo(Node other); }
|
Node implements Comparable<Node> { @Override public int hashCode() { return Objects.hash(nodeType, uniqueId); } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other); @Override int hashCode(); @Override int compareTo(Node other); static final int ROOT_NODE_ID; }
|
@Test public void testEquals() { Node node1 = Node.builder().uniqueId("unique").nodeType(NodeType.FOLDER).build(); Node node2 = Node.builder().uniqueId("unique").nodeType(NodeType.CONFIGURATION).build(); Node node3 = Node.builder().uniqueId("unique").nodeType(NodeType.FOLDER).build(); assertFalse(node1.equals(null)); assertFalse(node1.equals(node2)); assertTrue(node1.equals(node3)); assertFalse(node1.equals(new Object())); }
|
@Override public boolean equals(Object other) { if(other == null) { return false; } if(other instanceof Node) { Node otherNode = (Node)other; return nodeType.equals(otherNode.getNodeType()) && uniqueId.equals(otherNode.getUniqueId()); } return false; }
|
Node implements Comparable<Node> { @Override public boolean equals(Object other) { if(other == null) { return false; } if(other instanceof Node) { Node otherNode = (Node)other; return nodeType.equals(otherNode.getNodeType()) && uniqueId.equals(otherNode.getUniqueId()); } return false; } }
|
Node implements Comparable<Node> { @Override public boolean equals(Object other) { if(other == null) { return false; } if(other instanceof Node) { Node otherNode = (Node)other; return nodeType.equals(otherNode.getNodeType()) && uniqueId.equals(otherNode.getUniqueId()); } return false; } }
|
Node implements Comparable<Node> { @Override public boolean equals(Object other) { if(other == null) { return false; } if(other instanceof Node) { Node otherNode = (Node)other; return nodeType.equals(otherNode.getNodeType()) && uniqueId.equals(otherNode.getUniqueId()); } return false; } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other); @Override int hashCode(); @Override int compareTo(Node other); }
|
Node implements Comparable<Node> { @Override public boolean equals(Object other) { if(other == null) { return false; } if(other instanceof Node) { Node otherNode = (Node)other; return nodeType.equals(otherNode.getNodeType()) && uniqueId.equals(otherNode.getUniqueId()); } return false; } void putProperty(String key, String value); void removeProperty(String key); String getProperty(String key); void addTag(Tag tag); void removeTag(Tag tag); @Override boolean equals(Object other); @Override int hashCode(); @Override int compareTo(Node other); static final int ROOT_NODE_ID; }
|
@Test public void testEquals() { ConfigPv configPV1 = ConfigPv.builder().pvName("a").readbackPvName("b").readOnly(true).build(); assertFalse(configPV1.equals(new Object())); assertFalse(configPV1.equals(null)); ConfigPv configPV2 = ConfigPv.builder().pvName("a").readbackPvName("b").readOnly(true).build(); ConfigPv configPV3 = ConfigPv.builder().pvName("a").readbackPvName("c").readOnly(true).build(); assertEquals(configPV1, configPV2); assertNotEquals(configPV1, configPV3); configPV1 = ConfigPv.builder().pvName("a").readbackPvName("b").readOnly(true).build(); configPV2 = ConfigPv.builder().pvName("b").readbackPvName("b").readOnly(true).build(); assertNotEquals(configPV1, configPV2); configPV1 = ConfigPv.builder().pvName("a").readOnly(true).build(); configPV2 = ConfigPv.builder().pvName("b").readOnly(true).build(); assertNotEquals(configPV1, configPV2); configPV1 = ConfigPv.builder().pvName("a").readOnly(true).build(); configPV2 = ConfigPv.builder().pvName("a").readOnly(true).build(); assertEquals(configPV1, configPV2); }
|
@Override public boolean equals(Object other) { if(other instanceof ConfigPv) { ConfigPv otherConfigPv = (ConfigPv)other; return Objects.equals(pvName, otherConfigPv.getPvName()) && Objects.equals(readbackPvName, otherConfigPv.getReadbackPvName()) && Objects.equals(readOnly, otherConfigPv.isReadOnly()); } return false; }
|
ConfigPv implements Comparable<ConfigPv> { @Override public boolean equals(Object other) { if(other instanceof ConfigPv) { ConfigPv otherConfigPv = (ConfigPv)other; return Objects.equals(pvName, otherConfigPv.getPvName()) && Objects.equals(readbackPvName, otherConfigPv.getReadbackPvName()) && Objects.equals(readOnly, otherConfigPv.isReadOnly()); } return false; } }
|
ConfigPv implements Comparable<ConfigPv> { @Override public boolean equals(Object other) { if(other instanceof ConfigPv) { ConfigPv otherConfigPv = (ConfigPv)other; return Objects.equals(pvName, otherConfigPv.getPvName()) && Objects.equals(readbackPvName, otherConfigPv.getReadbackPvName()) && Objects.equals(readOnly, otherConfigPv.isReadOnly()); } return false; } }
|
ConfigPv implements Comparable<ConfigPv> { @Override public boolean equals(Object other) { if(other instanceof ConfigPv) { ConfigPv otherConfigPv = (ConfigPv)other; return Objects.equals(pvName, otherConfigPv.getPvName()) && Objects.equals(readbackPvName, otherConfigPv.getReadbackPvName()) && Objects.equals(readOnly, otherConfigPv.isReadOnly()); } return false; } @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @Override int compareTo(ConfigPv other); }
|
ConfigPv implements Comparable<ConfigPv> { @Override public boolean equals(Object other) { if(other instanceof ConfigPv) { ConfigPv otherConfigPv = (ConfigPv)other; return Objects.equals(pvName, otherConfigPv.getPvName()) && Objects.equals(readbackPvName, otherConfigPv.getReadbackPvName()) && Objects.equals(readOnly, otherConfigPv.isReadOnly()); } return false; } @Override boolean equals(Object other); @Override int hashCode(); @Override String toString(); @Override int compareTo(ConfigPv other); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.