/** * Test if method formal parameters designates a strict object, that is, is not primitive, array, collection or map. * * @param formalParameters method formal parameters list. * @return true if formal parameters designates a strict object. */ private static boolean isObject(Type[] formalParameters) { if (formalParameters.length != 1) { return false; } final Type type = formalParameters[0]; if (!(type instanceof Class)) { return false; } if (Types.isPrimitive(type)) { return false; } if (Types.isArrayLike(type)) { return false; } if (Types.isMap(type)) { return false; } if (ConverterRegistry.hasType(type)) { return false; } return true; }
return true; if(isBoolean(o)) { return (Boolean)o == false; if(isNumber(o)) { return ((Number)o).byteValue() == 0; return !((String)o).isEmpty(); if(isArray(o)) { return Array.getLength(o) == 0; if(isCollection(o)) { return ((Collection<?>)o).isEmpty(); if(isMap(o)) { return ((Map<?, ?>)o).isEmpty(); if(isCharacter(o)) { return !Character.isDefined((Character)o);
/** * Test if type is map. Returns true if type implements, directly or through inheritance, {@link Map} interface. * * @param t type to test. * @return true if type is map. */ public static boolean isMap(Type t) { return Types.isKindOf(t, Map.class); }
/** * Test if type is array like, that is, array or collection. Uses {@link #isArray(Type)} and * {@link #isCollection(Type)}. * * @param t type to test. * @return true if type is array like. */ public static boolean isArrayLike(Type t) { return isArray(t) || isCollection(t); }
/** * Test if type is like a primitive? Return true only if given type is a number, boolean, enumeration, character or * string. * * @param t type to test. * @return true if this type is like a primitive. */ public static boolean isPrimitiveLike(Type t) { if(isNumber(t)) { return true; } if(isBoolean(t)) { return true; } if(isEnum(t)) { return true; } if(isCharacter(t)) { return true; } if(isDate(t)) { return true; } if(t == String.class) { return true; } return false; }
if (Types.isBoolean(value)) { write(converter.asString(value)); return; if (Types.isNumber(value)) { write(converter.asString(value)); return; if (Types.isArrayLike(value)) { serializeArray(value); return; if (Types.isMap(value)) { serializeMap(value); return;
return format.format(value); if (!Types.isPrimitiveLike(value) && !ConverterRegistry.hasType(value.getClass())) { throw new TemplateException("Value |%s#%s| should be a primitive like but is |%s|.", scope.getClass(), propertyPath, value.getClass()); if (Types.isBoolean(value)) { return value.toString().toLowerCase(); if (Types.isNumber(value)) { NumberFormat nf = scriptNumberFormat.get(); if (nf == null) { if (Types.isDate(value)) { DateFormat df = scriptDateFormat.get(); if (df == null) {
return new MissingFieldValue(converter); if (Types.isArray(type)) { return new ArrayValue(converter, type); if (Types.isCollection(type)) { return new CollectionValue(converter, type); return new PrimitiveValue(converter, (Class<?>) type); if (Types.isPrimitiveLike(type)) { return new PrimitiveValue(converter, (Class<?>) type); if (Types.isMap(type)) { return new MapValue(converter, type);
if(Types.isBoolean(t)) { return Boolean.valueOf(false); if(Types.isCharacter(t)) { return '\0'; return ""; if(Types.isDate(t)) { return new Date(); if(Types.isCollection(t)) { return Classes.newCollection(t); if(Types.isArray(t)) { Array.newInstance(((Class<?>)t).getComponentType(), 0);
/** * Check operand format compatibility against value counterpart. * * @param value content value to validate operand against, * @param operand formatted string operand. * @return true if <code>operand</code> format is compatible with requested <code>value</code>. */ public static boolean isValid(Object value, String operand) { if (operand == null) { // validation is enacted only for operator processors that do not accept null operand // so always return false return false; } if (Types.isBoolean(value)) { return BOOLEAN_PATTERN.matcher(operand).matches(); } if (Types.isNumber(value)) { return NUMBER_PATTERN.matcher(operand).matches(); } if (Types.isDate(value)) { return DATE_PATTERN.matcher(operand).matches(); } return true; } }
private static <T> T asObject(String value, Type type) { if (value == null) { return (T) Types.getEmptyValue(type); if (!Types.isArrayLike(type)) { if (!(type instanceof Class)) { throw new BugError("Generic value types are not supported."); return (T) Types.getEmptyValue(type); return (T) strings.toArray(new String[strings.size()]); if (Types.isKindOf(type, Collection.class)) { Type collectionType = type; Class<?> itemType = String.class;
/** * Retrieve content array like instance as iterable. Delegates {@link #getValue(Object, String)} to obtain the requested * value. If value is null warn the event and return empty list. I value is array like return it as iterable, otherwise * throws content exception. * * @param scope scope object, * @param propertyPath object property path. * @return array like instance, possible empty, converted to iterable. * @throws TemplateException if requested value is undefined or is not an {@link Types#isArrayLike(Object) an array like}. */ Iterable<?> getIterable(Object scope, String propertyPath) throws TemplateException { Object value = getValue(scope, propertyPath); if (value == null) { warn(scope.getClass(), propertyPath); return Collections.EMPTY_LIST; } if (!Types.isArrayLike(value)) { throw new TemplateException("Invalid type. Expected list but got |%s|.", value.getClass()); } return Types.asIterable(value); }
if(Types.isCollection(rawClass)) { return newCollection(rawClass); if(Types.isMap(rawClass)) { return newMap(rawClass);
/** * Test instance if is array like. If instance to test is not null delegates {@link #isArrayLike(Type)}; otherwise * return false. * * @param o instance to test, possible null in which case returns false. * @return true if instance is array like; returns false if instance to test is null. */ public static boolean isArrayLike(Object o) { return o != null && isArrayLike(o.getClass()); }
/** * Test if instance is a map. If instance to test is not null delegates {@link #isMap(Type)}; otherwise returns false. * * @param o instance to test, possible null. * @return true if instance is a map; returns false if instance to test is null. */ public static boolean isMap(Object o) { return o != null && Types.isMap(o.getClass()); }
/** * Test if object instance is a primitive like. This predicates delegates {@link #isPrimitiveLike(Type)}. If instance * to test is null returns false. * * @param o object instance, possible null. * @return true if object instance is primitive like. */ public static boolean isPrimitiveLike(Object o) { return o != null && isPrimitiveLike(o.getClass()); }
/** * Test if object instance is a boolean, primitive or boxing class. Returns true if given object is primitive boolean * or {@link Boolean} instance or false otherwise. Return also false if object is null. * * @param o object instance, possible null. * @return true if instance to test is boolean. */ public static boolean isBoolean(Object o) { return o != null && isBoolean(o.getClass()); }
/** * Test if object instance is primitive numeric value or related boxing class. Returns true if given instance is a * primitive numeric value or related boxing class. Returns false if instance is null. * * @param o object instance, possible null. * @return true if instance is a number. */ public static boolean isNumber(Object o) { return o != null && isNumber(o.getClass()); }