private static String bitsToDef(final BitsTypeDefinition type, final String className, final String defaultValue, final boolean isExt) { List<Bit> bits = new ArrayList<>(type.getBits()); Collections.sort(bits, new Comparator<Bit>() { @Override public int compare(final Bit o1, final Bit o2) { return o1.getName().compareTo(o2.getName()); } }); StringBuilder sb = new StringBuilder(); if (!isExt) { sb.append("new "); sb.append(className); sb.append('('); } for (int i = 0; i < bits.size(); i++) { if (bits.get(i).getName().equals(defaultValue)) { sb.append(true); } else { sb.append(false); } if (i != bits.size() - 1) { sb.append(", "); } } if (!isExt) { sb.append(')'); } return sb.toString(); }
@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 boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Bit other = (Bit) obj; return Objects.equals(schemaPath, other.getPath()); }
GeneratedPropertyBuilder genPropertyBuilder; for (final Bit bit : bitList) { String name = bit.getName(); genPropertyBuilder = genTOBuilder.addProperty(BindingMapping.getPropertyName(name)); genPropertyBuilder.setReadOnly(true);
SourceException.throwIf(bit.getPosition() < 0L && bit.getPosition() > 4294967295L, ctx.getStatementSourceReference(), "Bit %s has illegal position", bit); if (highestPosition == null || highestPosition < bit.getPosition()) { highestPosition = bit.getPosition();
GeneratedPropertyBuilder genPropertyBuilder; for (Bit bit : bitList) { final String name = bit.getName(); genPropertyBuilder = genTOBuilder.addProperty(BindingMapping.getPropertyName(name)); genPropertyBuilder.setReadOnly(true);
private static String bitsToDef(final BitsTypeDefinition type, final String className, final String defaultValue, final boolean isExt) { final List<Bit> bits = new ArrayList<>(type.getBits()); bits.sort(BIT_NAME_COMPARATOR); final StringBuilder sb = new StringBuilder(); if (!isExt) { sb.append("new "); sb.append(className); sb.append('('); } for (int i = 0; i < bits.size(); i++) { if (bits.get(i).getName().equals(defaultValue)) { sb.append(true); } else { sb.append(false); } if (i != bits.size() - 1) { sb.append(", "); } } if (!isExt) { sb.append(')'); } return sb.toString(); }
static Callable<BitsCodec> loader(final Class<?> returnType, final BitsTypeDefinition rootType) { return () -> { final Map<String, Method> getters = new LinkedHashMap<>(); final Set<String> ctorArgs = new TreeSet<>(); for (Bit bit : rootType.getBits()) { final Method valueGetter = returnType.getMethod(BindingMapping.BOOLEAN_GETTER_PREFIX + BindingMapping.getClassName(bit.getName())); ctorArgs.add(bit.getName()); getters.put(bit.getName(), valueGetter); } Constructor<?> constructor = null; for (Constructor<?> cst : returnType.getConstructors()) { if (!cst.getParameterTypes()[0].equals(returnType)) { constructor = cst; } } final MethodHandle ctor = MethodHandles.publicLookup().unreflectConstructor(constructor) .asSpreader(Boolean[].class, ctorArgs.size()).asType(CONSTRUCTOR_INVOKE_TYPE); return new BitsCodec(returnType, ctor, ctorArgs, getters); }; }
static Callable<BitsCodec> loader(final Class<?> returnType, final BitsTypeDefinition rootType) { return () -> { final Map<String, Method> getters = new LinkedHashMap<>(); final Set<String> ctorArgs = new TreeSet<>(); for (Bit bit : rootType.getBits()) { final Method valueGetter = returnType.getMethod("is" + JavaIdentifierNormalizer .normalizeSpecificIdentifier(bit.getName(), JavaIdentifier.CLASS)); ctorArgs.add(bit.getName()); getters.put(bit.getName(), valueGetter); } Constructor<?> constructor = null; for (Constructor<?> cst : returnType.getConstructors()) { if (!cst.getParameterTypes()[0].equals(returnType)) { constructor = cst; } } final MethodHandle ctor = MethodHandles.publicLookup().unreflectConstructor(constructor) .asSpreader(Boolean[].class, ctorArgs.size()).asType(CONSTRUCTOR_INVOKE_TYPE); return new BitsCodec(returnType, ctor, ctorArgs, getters); }; }
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()); } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Bit other = (Bit) obj; return Objects.equals(schemaPath, other.getPath()); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final BitsTypeDefinition.Bit other = (BitsTypeDefinition.Bit) obj; return Objects.equals(qname, other.getQName()) && Objects.equals(schemaPath, other.getPath()); }
@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()); } }
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; }
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 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); }
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 static boolean containsBit(final BitsTypeDefinition bitsType, final String bitName) { for (BitsTypeDefinition.Bit bit : bitsType.getBits()) { if (bitName.equals(bit.getName())) { return true; } } return false; }