/** * Looks up the provided attribute name and returns the associated type name. If the attribute * name is not defined in this record type, then this method returns {@code null}. * <p> * This method is functionally equivalent to: * * {@preformat java * getAttributeTypes().get(name).getTypeName(); * } * * @param memberName The attribute name for which to get the associated type name. * @return The associated type name, or {@code null} if none. */ @Override public TypeName locate(final MemberName memberName) { final Type type = memberTypes.get(memberName); return (type != null) ? type.getTypeName() : null; }
/** * Returns the type associated to the given attribute name, or {@code null} if none. * This method is functionally equivalent to (omitting the check for null value): * * {@preformat java * getMemberTypes().get(memberName).getTypeName(); * } * * <div class="note"><b>Comparison with Java reflection:</b> * If we think about this {@code RecordType} as equivalent to a {@code Class} instance, then * this method can be though as related to the Java {@link Class#getField(String)} method. * </div> * * @param memberName the attribute name for which to get the associated type name. * @return the associated type name, or {@code null} if none. */ @Override public TypeName locate(final MemberName memberName) { final Integer index = indexOf(memberName); return (index != null) ? getType(index).getTypeName() : null; }
/** * Returns the type associated to the given attribute name, or {@code null} if none. * This method is functionally equivalent to (omitting the check for null value): * * {@preformat java * getMemberTypes().get(memberName).getTypeName(); * } * * <div class="note"><b>Comparison with Java reflection:</b> * If we think about this {@code RecordType} as equivalent to a {@code Class} instance, then * this method can be though as related to the Java {@link Class#getField(String)} method. * </div> * * @param memberName the attribute name for which to get the associated type name. * @return the associated type name, or {@code null} if none. */ @Override public TypeName locate(final MemberName memberName) { final Integer index = indexOf(memberName); return (index != null) ? getType(index).getTypeName() : null; }
/** * Creates a new record from member names specified as character sequence. * This constructor builds the {@link MemberName} instance itself. * * @param typeName the name that identifies this record type. * @param container the schema that contains this record type. * @param members the name of the members to be included in this record type. * @param nameFactory the factory to use for instantiating {@link MemberName}. */ DefaultRecordType(final TypeName typeName, final RecordSchema container, final Map<? extends CharSequence, ? extends Type> members, final DefaultNameFactory nameFactory) { this.typeName = typeName; this.container = container; final NameSpace namespace = nameFactory.createNameSpace(typeName, null); final Map<MemberName,Type> memberTypes = new LinkedHashMap<>(Containers.hashMapCapacity(members.size())); for (final Map.Entry<? extends CharSequence, ? extends Type> entry : members.entrySet()) { final Type type = entry.getValue(); final CharSequence name = entry.getKey(); final MemberName member = nameFactory.createMemberName(namespace, name, type.getTypeName()); if (memberTypes.put(member, type) != null) { throw new IllegalArgumentException(Errors.format(Errors.Keys.DuplicatedElement_1, member)); } } this.memberTypes = computeTransientFields(memberTypes); }
/** * Creates a new record from member names specified as character sequence. * This constructor builds the {@link MemberName} instance itself. * * @param typeName the name that identifies this record type. * @param container the schema that contains this record type. * @param members the name of the members to be included in this record type. * @param nameFactory the factory to use for instantiating {@link MemberName}. */ DefaultRecordType(final TypeName typeName, final RecordSchema container, final Map<? extends CharSequence, ? extends Type> members, final DefaultNameFactory nameFactory) { this.typeName = typeName; this.container = container; final NameSpace namespace = nameFactory.createNameSpace(typeName, null); final Map<MemberName,Type> memberTypes = new LinkedHashMap<>(Containers.hashMapCapacity(members.size())); for (final Map.Entry<? extends CharSequence, ? extends Type> entry : members.entrySet()) { final Type type = entry.getValue(); final CharSequence name = entry.getKey(); final MemberName member = nameFactory.createMemberName(namespace, name, type.getTypeName()); if (memberTypes.put(member, type) != null) { throw new IllegalArgumentException(Errors.format(Errors.Keys.DuplicatedElement_1, member)); } } this.memberTypes = computeTransientFields(memberTypes); }
text = CharSequences.upperCaseToSentence(((Enum<?>) value).name()); } else if (value instanceof Type) { text = toString(((Type) value).getTypeName()); } else if (value instanceof Locale) { final Locale locale = getDisplayLocale();
text = CharSequences.upperCaseToSentence(((Enum<?>) value).name()); } else if (value instanceof Type) { text = toString(((Type) value).getTypeName()); } else if (value instanceof Locale) { final Locale locale = getDisplayLocale();
final MemberName name = getName(i); final Type type = this.memberTypes[i]; if (type == null || name.getAttributeType().compareTo(type.getTypeName()) != 0) { throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalMemberType_2, name, type));
final MemberName name = getName(i); final Type type = this.memberTypes[i]; if (type == null || name.getAttributeType().compareTo(type.getTypeName()) != 0) { throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalMemberType_2, name, type));
assertEquals(expectedType, type.getTypeName().toFullyQualifiedName().toString()); assertEquals(expectedClass, ((SimpleAttributeType) type).getValueClass()); count++;
/** * Tests the construction of {@link DefaultRecordType}, and opportunistically tests * {@link DefaultRecordType#locate(MemberName)}. */ @Test public void testConstructor() { init(); final DefaultRecordType type = create(); assertEquals("size", 1, type.size()); assertEquals("baseValueClass", Integer.TYPE, type.baseValueClass()); // Public properties assertSame("container", container, type.getContainer()); assertSame("typeName", recordTypeName, type.getTypeName()); assertSame("members", memberName, getSingleton(type.getMembers())); assertSame("memberTypes", memberName, getSingleton(type.getMemberTypes().keySet())); assertSame("memberTypes", memberTypeName, getSingleton(type.getMemberTypes().values()).getTypeName()); assertSame("locate", memberTypeName, type.locate(memberName)); assertNull("locate", type.locate(new DefaultMemberName(null, "otherMember", memberTypeName))); }