@SuppressWarnings("unchecked") private BitsStringCodec(final Optional<BitsTypeDefinition> typeDef) { super(typeDef, (Class<Set<String>>) (Class<?>) Set.class); if (typeDef.isPresent()) { validBits = ImmutableSet.copyOf(Collections2.transform(typeDef.get().getBits(), Bit::getName)); } else { validBits = null; } }
static int hashCode(final @NonNull BitsTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getBits()); }
@Override public boolean equals(final Object obj) { return BitsTypeDefinition.equals(this, obj); } }
private static long getBaseTypeBitPosition(final String bitName, final BitsTypeDefinition baseType, final StmtContext<?, ?, ?> ctx) { for (Bit baseTypeBit : baseType.getBits()) { if (bitName.equals(baseTypeBit.getName())) { return baseTypeBit.getPosition(); } } throw new SourceException(ctx.getStatementSourceReference(), "Bit '%s' is not a subset of its base bits type %s.", bitName, baseType.getQName()); }
final BitsTypeDefinition typeDef, final String moduleName) { final GeneratedTOBuilder genTOBuilder = newGeneratedTOBuilder(typeName); genTOBuilder.setSchemaPath(typeDef.getPath()); genTOBuilder.setModuleName(moduleName); genTOBuilder.setBaseType(typeDef); addCodegenInformation(genTOBuilder, typeDef); final List<Bit> bitList = typeDef.getBits(); GeneratedPropertyBuilder genPropertyBuilder; for (Bit bit : bitList) {
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()); } }
@SuppressWarnings("unchecked") private BitsStringCodec(final Optional<BitsTypeDefinition> typeDef) { super(typeDef, (Class<Set<String>>) (Class<?>) Set.class); if (typeDef.isPresent()) { validBits = ImmutableSet.copyOf(Collections2.transform(typeDef.get().getBits(), Bit::getName)); } else { validBits = null; } }
static int hashCode(final @NonNull BitsTypeDefinition type) { return Objects.hash(type.getPath(), type.getUnknownSchemaNodes(), type.getBaseType(), type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getBits()); }
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()); } }
@Override public boolean equals(final Object obj) { return BitsTypeDefinition.equals(this, obj); } }
@Override public boolean equals(final Object obj) { return BitsTypeDefinition.equals(this, obj); }
private void emitBitsSpecification(final BitsTypeDefinition typeDefinition) { for (final Bit bit : typeDefinition.getBits()) { emitBit(bit); } }
@Override public boolean equals(final Object obj) { return BitsTypeDefinition.equals(this, obj); }
private static void processBitsType(final BitsTypeDefinition bitsType, final JSONObject property) throws JSONException { property.put(TYPE_KEY, ARRAY_TYPE); property.put(MIN_ITEMS, 0); property.put(UNIQUE_ITEMS_KEY, true); JSONArray enumValues = new JSONArray(); List<Bit> bits = bitsType.getBits(); for (Bit bit : bits) { enumValues.put(bit.getName()); } JSONObject itemsValue = new JSONObject(); itemsValue.put(ENUM, enumValues); property.put(ITEMS_KEY, itemsValue); }
@Override public boolean equals(final Object obj) { return BitsTypeDefinition.equals(this, obj); }
private static boolean containsBit(final BitsTypeDefinition bitsType, final String bitName) { for (BitsTypeDefinition.Bit bit : bitsType.getBits()) { if (bitName.equals(bit.getName())) { return true; } } return false; }
@Override public boolean equals(final Object obj) { return BitsTypeDefinition.equals(this, obj); }
private static boolean containsBit(final BitsTypeDefinition bitsType, final String bitName) { for (BitsTypeDefinition.Bit bit : bitsType.getBits()) { if (bitName.equals(bit.getName())) { return true; } } return false; }