Search in sources :

Example 1 with StringFieldKey

use of io.datarouter.model.field.imp.StringFieldKey in project datarouter by hotpads.

the class StringEnumField method toStringField.

public static StringField toStringField(StringEnumField<?> stringEnumField) {
    if (stringEnumField == null) {
        return null;
    }
    String value = null;
    if (stringEnumField.getValue() != null) {
        value = stringEnumField.getValue().getPersistentString();
    }
    String defaultValue = null;
    if (stringEnumField.getKey().getDefaultValue() != null) {
        defaultValue = stringEnumField.getKey().getDefaultValue().getPersistentString();
    }
    StringFieldKey key = new StringFieldKey(stringEnumField.key.getName(), stringEnumField.key.getColumnName(), stringEnumField.key.isNullable(), FieldGeneratorType.NONE, defaultValue, stringEnumField.key.getSize(), stringEnumField.key.getAttributes());
    return new StringField(stringEnumField.getPrefix(), key, value);
}
Also used : StringFieldKey(io.datarouter.model.field.imp.StringFieldKey) StringField(io.datarouter.model.field.imp.StringField)

Example 2 with StringFieldKey

use of io.datarouter.model.field.imp.StringFieldKey in project datarouter by hotpads.

the class FieldSetToolTests method testGetConcatenatedValueBytes.

@Test
public void testGetConcatenatedValueBytes() {
    List<Field<?>> fields = List.of(new IntegerField(new IntegerFieldKey("a"), 55), new StringField(new StringFieldKey("b"), "abc"), new StringField(new StringFieldKey("c"), "xyz"));
    int lengthWithout = 4 + 3 + 1 + 3;
    int lengthWith = lengthWithout + 1;
    Bytes withoutTrailingByte = new Bytes(FieldTool.getConcatenatedValueBytesUnterminated(fields));
    Bytes withTrailingByte = new Bytes(FieldTool.getConcatenatedValueBytes(fields));
    Assert.assertEquals(withoutTrailingByte.getLength(), lengthWithout);
    Assert.assertEquals(withTrailingByte.getLength(), lengthWith);
}
Also used : IntegerField(io.datarouter.model.field.imp.comparable.IntegerField) StringField(io.datarouter.model.field.imp.StringField) Bytes(io.datarouter.bytes.Bytes) StringFieldKey(io.datarouter.model.field.imp.StringFieldKey) IntegerFieldKey(io.datarouter.model.field.imp.comparable.IntegerFieldKey) StringField(io.datarouter.model.field.imp.StringField) IntegerField(io.datarouter.model.field.imp.comparable.IntegerField) Test(org.testng.annotations.Test)

Aggregations

StringField (io.datarouter.model.field.imp.StringField)2 StringFieldKey (io.datarouter.model.field.imp.StringFieldKey)2 Bytes (io.datarouter.bytes.Bytes)1 IntegerField (io.datarouter.model.field.imp.comparable.IntegerField)1 IntegerFieldKey (io.datarouter.model.field.imp.comparable.IntegerFieldKey)1 Test (org.testng.annotations.Test)1