/** * Creates a Structure that represents NTTable. This resets this instance state and allows new * instance to be created. * * @return a new instance of a Structure */ public Structure createStructure() { FieldBuilder builder = FieldFactory.getFieldCreate().createFieldBuilder(); FieldBuilder nestedBuilder = builder .setId(NTTable.URI) .addArray("labels", ScalarType.pvString) .addNestedStructure("value"); int len = columnNames.size(); for (int i = 0; i < len; i++) nestedBuilder.addArray(columnNames.get(i), types.get(i)); builder = nestedBuilder.endNested(); NTField ntField = NTField.get(); if (descriptor) builder.add("descriptor", ScalarType.pvString); if (alarm) builder.add("alarm", ntField.createAlarm()); if (timeStamp) builder.add("timeStamp", ntField.createTimeStamp()); int extraCount = extraFieldNames.size(); for (int i = 0; i < extraCount; i++) builder.add(extraFieldNames.get(i), extraFields.get(i)); Structure s = builder.createStructure(); reset(); return s; }
/** * Returns whether the specified Structure is compatible with NTUnion. * * <p>Checks if the specified Structure is compatible with this version of NTUnion through the * introspection interface. * * @param structure the Structure to test * @return (false,true) if (is not, is) a compatible NTUnion */ public static boolean isCompatible(Structure structure) { if (structure == null) return false; Union valueField = structure.getField(Union.class, "value"); if (valueField == null) return false; NTField ntField = NTField.get(); Field field = structure.getField("descriptor"); if (field != null) { Scalar descriptorField = structure.getField(Scalar.class, "descriptor"); if (descriptorField == null || descriptorField.getScalarType() != ScalarType.pvString) return false; } field = structure.getField("alarm"); if (field != null && !ntField.isAlarm(field)) return false; field = structure.getField("timeStamp"); if (field != null && !ntField.isTimeStamp(field)) return false; return true; }