use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class ContentAssistOperation method visit.
@Override
public void visit(IEntity entity) {
EntityDescriptor<?> entityEd = entity.wGetEntityDescriptor();
DataKinds dataKind = entityEd.getDataKind();
// TODO merge with parent results if different language
if (dataKind.isNotAData()) {
IEntity parent = entity.wGetParent();
if (!EntityUtils.isNull(parent)) {
entityEd = parent.wGetEntityDescriptor(entity);
dataKind = entityEd.getDataKind();
}
}
final EntityDescriptor<?> ed = entityEd;
switch(dataKind) {
case ENUM_VALUE:
final List<EnumValue> enumValues = new ArrayList<EnumValue>(ed.getDataEnumType().values());
final IDataTypeParser unparser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
Collections.sort(enumValues, (EnumValue arg0, EnumValue arg1) -> {
String arg0String = unparser.unparseEnumValue(ed, arg0);
String arg1String = unparser.unparseEnumValue(ed, arg1);
if (arg0String.length() == 0 || arg1String.length() == 0 || !Character.isLetterOrDigit(arg0String.charAt(0)) || !Character.isLetterOrDigit(arg1String.charAt(0)))
return arg0.compareTo(arg1);
else
return arg0String.compareTo(arg1String);
});
int size = enumValues.size();
IEntity[] values = new IEntity[size];
for (int i = 0; i < size; i++) values[i] = GenericEntityFactory.instance.create(ed, enumValues.get(i));
setResult(values);
break;
case BOOLEAN:
setResult(new IEntity[] { GenericEntityFactory.instance.create(ed, true), GenericEntityFactory.instance.create(ed, false) });
break;
default:
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class XsiDateTimeUtilsTest method testGregorianCalendar.
@Test
public void testGregorianCalendar() {
ILanguageKit languageKit = ReflectionFactory.getLanguageKit(DATATYPES_URI);
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
IDataTypeParser dataTypeParser = languageKit.getDataTypeParser(DataTypeParsers.PERSISTENCE);
EntityDescriptor<?> dateTime = edEnum.valueOf("XSDateTime");
EntityDescriptor<?> date = edEnum.valueOf("XSDate");
EntityDescriptor<?> time = edEnum.valueOf("XSTime");
EntityDescriptor<?> gYearMonth = edEnum.valueOf("XSGYearMonth");
DateTime base = new DateTime(2001, 1, 1, 11, 22, 33, 444, DateTimeZone.UTC);
assertEquals(dataTypeParser, base, dateTime, "1990-11-30T12:30:43.999Z", "1990-11-30T12:30:43.999Z");
assertEquals(dataTypeParser, base, dateTime, "1990-11-30T12:30:43", "1990-11-30T12:30:43.000Z");
assertEquals(dataTypeParser, base, gYearMonth, "1990-11", "1990-11-01T11:22:33.444Z");
assertEquals(dataTypeParser, base, date, "1990-11-30", "1990-11-30T11:22:33.444Z");
assertEquals(dataTypeParser, base, date, "1990-11-30Z", "1990-11-30T00:00:00.000Z");
assertEquals(dataTypeParser, base, date, "1990-11-30+02:00", "1990-11-29T22:00:00.000Z");
assertEquals(dataTypeParser, base, time, "12:30:43", "2001-01-01T12:30:43.000Z");
assertEquals(dataTypeParser, base, time, "12:30:43.999Z", "1970-01-01T12:30:43.999Z");
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testDoubleData.
@Test
public void testDoubleData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createDoubleTestEntity(1.2d);
assertGenericParseUnparseRoundtrip(e, "54.35");
assertEquals("1.2", DataTypeUtils.getAsPresentationString(e));
assertEquals("1.2", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "12.3d");
assertEquals(12.3d, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, "37.32");
assertEquals(37.32d, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPersistenceString(e, "23.4d");
assertEquals(23.4d, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, "200");
assertEquals(200d, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, "2.5f");
assertEquals(2.5d, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.NaN));
assertEquals(Double.NaN, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.NEGATIVE_INFINITY));
assertEquals(Double.NEGATIVE_INFINITY, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.POSITIVE_INFINITY));
assertEquals(Double.POSITIVE_INFINITY, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.MIN_VALUE));
assertEquals(Double.MIN_VALUE, e.wDoubleValue(), .01d);
DataTypeUtils.setFromPresentationString(e, String.valueOf(Double.MAX_VALUE));
assertEquals(Double.MAX_VALUE, e.wDoubleValue(), .01d);
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.DoubleTestEntity, "12.3d");
assertEquals(12.3d, e.wDoubleValue(), .01d);
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.DoubleTestEntity, "23.4d");
assertEquals(23.4d, e.wDoubleValue(), .01d);
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseDouble(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testShortData.
@Test
public void testShortData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createShortTestEntity((short) 123);
assertGenericParseUnparseRoundtrip(e, "4132");
assertEquals("123", DataTypeUtils.getAsPresentationString(e));
assertEquals("123", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "123");
assertEquals((short) 123, e.wShortValue());
DataTypeUtils.setFromPersistenceString(e, "532");
assertEquals((short) 532, e.wShortValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Short.MIN_VALUE));
assertEquals(Short.MIN_VALUE, e.wShortValue());
DataTypeUtils.setFromPresentationString(e, String.valueOf(Short.MAX_VALUE));
assertEquals(Short.MAX_VALUE, e.wShortValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.ShortTestEntity, "3324");
assertEquals((short) 3324, e.wShortValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.ShortTestEntity, "983");
assertEquals((short) 983, e.wShortValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseShort(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
try {
parser.parseShort(ed, "-38000");
fail();
} catch (IllegalArgumentException iae) {
}
}
use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.
the class DataTypeUtilsTest method testBooleanData.
@Test
public void testBooleanData() {
TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
IEntity e = ef.createBooleanTestEntity(true);
assertGenericParseUnparseRoundtrip(e, "false");
assertEquals("true", DataTypeUtils.getAsPresentationString(e));
assertEquals("true", DataTypeUtils.getAsPersistenceString(e));
DataTypeUtils.setFromPresentationString(e, "FALSE");
assertFalse(e.wBooleanValue());
DataTypeUtils.setFromPersistenceString(e, "True");
assertTrue(e.wBooleanValue());
e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.BooleanTestEntity, "true");
assertTrue(e.wBooleanValue());
e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.BooleanTestEntity, "true");
assertTrue(e.wBooleanValue());
final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
try {
parser.parseBoolean(ed, "string");
fail();
} catch (IllegalArgumentException iae) {
}
try {
parser.parseBoolean(ed, "0");
fail();
} catch (IllegalArgumentException iae) {
}
}
Aggregations