本文整理汇总了Java中com.redhat.lightblue.metadata.types.DateType类的典型用法代码示例。如果您正苦于以下问题:Java DateType类的具体用法?Java DateType怎么用?Java DateType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateType类属于com.redhat.lightblue.metadata.types包,在下文中一共展示了DateType类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTranslate_SimpleField_Date
import com.redhat.lightblue.metadata.types.DateType; //导入依赖的package包/类
@Test
public void testTranslate_SimpleField_Date() throws JSONException{
Attribute keyAttribute = new Attribute("key", "20150109201731.570Z");
//Note in and out data are formatted differently
SearchResultEntry result = new SearchResultEntry(-1, "uid=john.doe,dc=example,dc=com", new Attribute[]{
keyAttribute
});
EntityMetadata md = fakeEntityMetadata(
"fakeMetadata",
new SimpleField("key", DateType.TYPE)
);
JsonDoc document = new ResultTranslatorToJson(factory, md, new TrivialLdapFieldNameTranslator()).translate(result);
assertNotNull(document);
String lbDate = Constants.getDateFormat().format(keyAttribute.getValueAsDate());
JSONAssert.assertEquals(
"{\"key\":\"" + lbDate + "\",\"dn\":\"uid=john.doe,dc=example,dc=com\"}",
document.toString(),
true);
}
示例2: rawValueToJson
import com.redhat.lightblue.metadata.types.DateType; //导入依赖的package包/类
private static JsonNode rawValueToJson(Object value) {
if(value instanceof Number) {
if(value instanceof Float || value instanceof Double) {
return DoubleType.TYPE.toJson(JsonNodeFactory.instance,value);
} else {
return IntegerType.TYPE.toJson(JsonNodeFactory.instance,value);
}
} else if(value instanceof Date) {
return DateType.TYPE.toJson(JsonNodeFactory.instance,value);
} else if(value instanceof Boolean) {
return BooleanType.TYPE.toJson(JsonNodeFactory.instance,value);
} else if(value==null) {
return JsonNodeFactory.instance.nullNode();
} else {
return JsonNodeFactory.instance.textNode(value.toString());
}
}
示例3: translate
import com.redhat.lightblue.metadata.types.DateType; //导入依赖的package包/类
@Override
protected JsonNode translate(SimpleField field, Object o) {
Type type = field.getType();
Attribute attr = (Attribute) o;
Object value = null;
if(type instanceof DateType){
value = attr.getValueAsDate();
}
else if(type instanceof BinaryType){
value = attr.getValueByteArray();
}
else{
value = attr.getValue();
}
if(value == null){
throw new NullPointerException("Unable to convert LDAP attribute to json resulting in a null value: " + attr.getName());
}
return toJson(field.getType(), value);
}
示例4: fromJson
import com.redhat.lightblue.metadata.types.DateType; //导入依赖的package包/类
@Override
protected Object fromJson(Type type, JsonNode node){
if(type instanceof DateType){
return StaticUtils.encodeGeneralizedTime((Date)type.fromJson(node));
}
else if(type instanceof BinaryType){
return type.fromJson(node);
}
else{
return super.fromJson(type, node).toString();
}
}
示例5: getTypeForClass
import com.redhat.lightblue.metadata.types.DateType; //导入依赖的package包/类
private Type getTypeForClass(Class<?> type) {
if (type.equals(String.class) || type.isEnum()) {
return StringType.TYPE;
}
if (type.equals(boolean.class) || type.equals(Boolean.class)) {
return BooleanType.TYPE;
}
if (type.equals(Date.class) || Temporal.class.isAssignableFrom(type)) {
return DateType.TYPE;
}
if (type.equals(BigDecimal.class)) {
return BigDecimalType.TYPE;
}
if (type.equals(BigInteger.class)) {
return BigIntegerType.TYPE;
}
if (type.equals(byte[].class)) {
return BinaryType.TYPE;
}
if (type.equals(double.class) || type.equals(Double.class)) {
return DoubleType.TYPE;
}
if (type.equals(int.class) || type.equals(Integer.class)) {
return IntegerType.TYPE;
}
if (Iterable.class.isAssignableFrom(type)) {
return ArrayType.TYPE;
}
// TODO: Reference type, UUID type
return ObjectType.TYPE;
}