public static String getConstruct(Result result) { String construct = result.getConstruct(); if (construct == null) { construct = "item"; result.setConstruct(construct); } return construct; }
public static Result createResult(Class<?> resultType) { Result result = new Result(); String resultName = resultType.getCanonicalName(); String simpleName = NameUtil.getSimpleName(resultName); result.setName(NameUtil.uncapName(simpleName)); String typeName = TypeUtil.getTypeFromClass(resultType); // Assert.notNull(typeName, "TypeName not found for: "+resultName); if (typeName == null) typeName = resultName; result.setType(typeName); return result; }
public static boolean validate(Result result) { if (result == null) return false; Validator validator = Validator.getValidator(); validator.notEmpty(result.getType(), "\"Type\" must be specified"); boolean isValid = validator.isValid(); return isValid; }
public static boolean equals(Result result1, Result result2) { Assert.notNull(result1, "Result1 must be specified"); Assert.notNull(result2, "Result2 must be specified"); Assert.notNull(result1.getName(), "Result1 name must be specified"); Assert.notNull(result2.getName(), "Result2 name must be specified"); Assert.notNull(result1.getType(), "Result1 type must be specified"); Assert.notNull(result2.getType(), "Result2 type must be specified"); if (!result1.getName().equals(result2.getName())) return false; if (!result1.getType().equals(result2.getType())) return false; return true; }
public static void initialize(Result result) { if (result.getRequired() == null) result.setRequired(false); }
public static String toString(Result result) { if (isEmpty(result)) return "Result: [uninitialized] " + result.toString(); String text = result.toString(); return text; }
public static boolean isEmpty(Result result) { if (result == null) return true; boolean status = false; status |= StringUtils.isEmpty(result.getType()); return status; }
public static String getLabel(Result result) { return result.getType(); }
public static Object getKey(Result result) { return result.getType(); }
public static Class<?> getResultType(Result result) { if (result != null && result.getType() != null) return TypeMap.INSTANCE.getTypeClassByTypeName(result.getType()); // TODO get this outta here return null; }
public static Result clone(Result result) { if (result == null) return null; Result clone = create(); clone.setType(ObjectUtil.clone(result.getType())); clone.setName(ObjectUtil.clone(result.getName())); clone.setKey(ObjectUtil.clone(result.getKey())); clone.setConstruct(ObjectUtil.clone(result.getConstruct())); clone.setRequired(ObjectUtil.clone(result.getRequired())); return clone; }