@Override public BitsTypeDefinition buildType() { final Map<String, Bit> map = builder.build(); final Map<Long, Bit> positionMap = new TreeMap<>(); for (Bit b : map.values()) { final Bit conflict = positionMap.put(b.getPosition(), b); if (conflict != null) { throw new InvalidBitDefinitionException(b, "Bit %s conflicts on position with bit ", conflict); } } return getBaseType() == null ? new BaseBitsType(getPath(), getUnknownSchemaNodes(), positionMap.values()) : new RestrictedBitsType(getBaseType(), getPath(), getUnknownSchemaNodes(), positionMap.values()); } }
@Override public BitsTypeDefinition buildType() { final Map<String, Bit> map = builder.build(); final Map<Long, Bit> positionMap = new TreeMap<>(); for (Bit b : map.values()) { final Bit conflict = positionMap.put(b.getPosition(), b); if (conflict != null) { throw new InvalidBitDefinitionException(b, "Bit %s conflicts on position with bit ", conflict); } } return getBaseType() == null ? new BaseBitsType(getPath(), getUnknownSchemaNodes(), positionMap.values()) : new RestrictedBitsType(getBaseType(), getPath(), getUnknownSchemaNodes(), positionMap.values()); } }
public BitsTypeBuilder addBit(final @NonNull Bit item) { // in case we are dealing with a restricted bits type, validate if the bit is a subset of its base type if (getBaseType() != null) { validateRestrictedBit(item); } builder.put(item.getName(), item); touch(); return this; }
public BitsTypeBuilder addBit(final @NonNull Bit item) { // in case we are dealing with a restricted bits type, validate if the bit is a subset of its base type if (getBaseType() != null) { validateRestrictedBit(item); } builder.put(item.getName(), item); touch(); return this; }
private void validateRestrictedBit(final @NonNull Bit item) { boolean isASubsetOfBaseBits = false; for (Bit baseTypeBit : getBaseType().getBits()) { if (item.getName().equals(baseTypeBit.getName())) { if (item.getPosition() != baseTypeBit.getPosition()) { throw new InvalidBitDefinitionException(item, "Position of bit '%s' must be the same as the " + "position of corresponding bit in the base bits type %s.", item.getName(), getBaseType().getQName()); } isASubsetOfBaseBits = true; break; } } if (!isASubsetOfBaseBits) { throw new InvalidBitDefinitionException(item, "Bit '%s' is not a subset of its base bits type %s.", item.getName(), getBaseType().getQName()); } }
private void validateRestrictedBit(final @NonNull Bit item) { boolean isASubsetOfBaseBits = false; for (Bit baseTypeBit : getBaseType().getBits()) { if (item.getName().equals(baseTypeBit.getName())) { if (item.getPosition() != baseTypeBit.getPosition()) { throw new InvalidBitDefinitionException(item, "Position of bit '%s' must be the same as the " + "position of corresponding bit in the base bits type %s.", item.getName(), getBaseType().getQName()); } isASubsetOfBaseBits = true; break; } } if (!isASubsetOfBaseBits) { throw new InvalidBitDefinitionException(item, "Bit '%s' is not a subset of its base bits type %s.", item.getName(), getBaseType().getQName()); } }