private boolean equals(Type<?> a, Type<?> b) { return a == null ? b == null : a.equals(b); }
private boolean equals(Type<?> a, Type<?> b) { return a == null ? b == null : a.equals(b); }
public int compareTo(Type<?> other) { if (this.equals(other)) { return 0; } else if (this.isAssignableFrom(other)) { return -1; } else { return 1; } }
public boolean canConvert(Type<?> sourceType, Type<?> destinationType) { return shouldClone(sourceType) && sourceType.equals(destinationType); }
@Override public boolean canConvert(final Type<?> sourceType, final Type<?> destinationType) { return this.sourceType.isAssignableFrom(sourceType) && this.destinationType.equals(destinationType); }
public boolean canConvert(Type<?> sourceType, Type<?> destinationType) { return shouldPassThrough(sourceType) && sourceType.equals(destinationType); }
public int compareTo(final Type<?> other) { if (this.equals(other)) { return 0; } String thisChain = buildClassInheritanceChain(this).toString(); String otherChain = buildClassInheritanceChain(other).toString(); return thisChain.compareTo(otherChain); }
@SuppressWarnings({ "unchecked" }) public <S, D> void registerConverter(Converter<S, D> converter) { if (mapperFacade != null) { throw new IllegalStateException("Cannot register converters after MapperFacade has been initialized"); } converters.add((Converter<Object, Object>) converter); if (converter instanceof BidirectionalConverter && !converter.getAType().equals(converter.getBType())) { converters.add((Converter<Object, Object>) ((BidirectionalConverter<?, ?>) converter).reverse()); } }
private StringBuilder buildClassInheritanceChain(final Type<?> type) { if (type.equals(TypeFactory.TYPE_OF_OBJECT)) { return new StringBuilder("/java.lang.Object"); } return buildClassInheritanceChain(type.getSuperType()).append('/').append(type.getName()); }
private static final OrderingRelation compare(Type<?> aType1, Type<?> bType1, Type<?> aType2, Type<?> bType2, boolean isBidirectional) { if ((aType1.equals(aType2) && bType1.equals(bType2)) || (aType1.equals(bType2) && aType2.equals(bType1))) { return OrderingRelation.EQUAL; } else if ((aType1.isAssignableFrom(aType2) && bType1.isAssignableFrom(bType2)) || (isBidirectional && aType1.isAssignableFrom(bType2) && bType1.isAssignableFrom(aType2))) { return OrderingRelation.BEFORE; } else if ((aType2.isAssignableFrom(aType1) && bType2.isAssignableFrom(bType1)) || (isBidirectional && aType2.isAssignableFrom(bType1) && bType2.isAssignableFrom(aType1))) { return OrderingRelation.AFTER; } else { return OrderingRelation.UNDEFINED; } }
@Override public boolean canConvert(Type<?> sourceType, Type<?> destinationType) { return super.canConvert(sourceType, destinationType) || this.destinationType.isAssignableFrom(sourceType) && this.sourceType.equals(destinationType); }
public boolean canConvert(Type<?> sourceType, Type<?> destinationType) { return /*destinationType.isAssignableFrom(sourceType) || */(ClassUtil.isImmutable(sourceType) && (sourceType.equals(destinationType) || sourceType.isWrapperFor(destinationType) || destinationType.isWrapperFor(sourceType))); }
private Mapper<Object, Object> resolveMapper(final Type<?> sourceType, final Type<?> destinationType, final MappingContext context) { final MapperKey mapperKey = new MapperKey(sourceType, destinationType); Mapper<Object, Object> mapper = mapperFactory.lookupMapper(mapperKey, context); if (mapper == null) { throw new IllegalStateException(String.format("Cannot create a mapper for classes : %s, %s", destinationType, sourceType)); } if ((!mapper.getAType().equals(sourceType) && mapper.getAType().equals(destinationType)) || (!mapper.getAType().isAssignableFrom(sourceType) && mapper.getAType().isAssignableFrom(destinationType))) { mapper = ReversedMapper.reverse(mapper); } return mapper; }
Mapper<Object, Object> resolveMapper(Type<?> sourceType, Type<?> destinationType) { final MapperKey mapperKey = new MapperKey(sourceType, destinationType); Mapper<Object, Object> mapper = mapperFactory.lookupMapper(mapperKey); if (mapper == null) { throw new IllegalStateException(String.format("Cannot create a mapper for classes : %s, %s", destinationType, sourceType)); } if ((!mapper.getAType().equals(sourceType) && mapper.getAType().equals(destinationType)) || (!mapper.getAType().isAssignableFrom(sourceType) && mapper.getAType().isAssignableFrom(destinationType))) { mapper = ReversedMapper.reverse(mapper); } return mapper; }
public boolean canConvert(Type<?> sourceType, Type<?> destinationType) { return (sourceType.isImmutable() && (sourceType.equals(destinationType) || sourceType.isWrapperFor(destinationType) || destinationType.isWrapperFor(sourceType))); }
public boolean appliesTo(FieldMap fieldMap) { return (fieldMap.getSource().getType().isPrimitive() && !TypeFactory.TYPE_OF_OBJECT.equals(fieldMap.getDestination().getType())) || fieldMap.getDestination().getType().isPrimitive(); }
public boolean appliesTo(FieldMap fieldMap) { return (fieldMap.getSource().isMapKey() || fieldMap.getSource().isArrayElement() || fieldMap.getSource().isListElement()) && (TypeFactory.TYPE_OF_OBJECT.equals(fieldMap.getSource().getType())); }
public boolean appliesTo(FieldMap fieldMap) { return (fieldMap.getDestination().isMapKey() || fieldMap.getDestination().isArrayElement() || fieldMap.getDestination().isListElement()) && (TypeFactory.TYPE_OF_OBJECT.equals(fieldMap.getDestination().getType())); }
private boolean mapFields(Node currentNode, Node srcNode, StringBuilder out, SourceCodeContext code) { VariableRef s = makeVariable(currentNode.value.getSource(), srcNode, "source"); VariableRef d = makeVariable(currentNode.value.getDestination(), currentNode, "destination"); String mapStmt = statement(code.mapFields(currentNode.value, s, d)); VariableRef elRef = currentNode.parent != null ? currentNode.parent.elementRef : null; if (elRef != null && !elRef.isPrimitive() && !elRef.type().isImmutable() && srcNode.parent != null) { // assure instance exists for the element reference append(out, format("if((%s)) { \n", elRef.isNull()), elRef.assign(code.newObject(srcNode.parent.elementRef, elRef.type())), "}"); } out.append(mapStmt); Type<?> parentElementType = currentNode.parent != null ? currentNode.parent.elementRef.type() : TypeFactory.TYPE_OF_OBJECT; return d.type().equals(parentElementType) && mapperFactory.getConverterFactory().canConvert(s.type(), d.type()); }