@Override protected void register(DocumentTypeManager manager, List<DataType> seenTypes) { seenTypes.add(this); if (!seenTypes.contains(getKeyType())) { getKeyType().register(manager, seenTypes); } if (!seenTypes.contains(getValueType())) { getValueType().register(manager, seenTypes); } super.register(manager, seenTypes); }
private void replaceTemporaryTypesInMap(MapDataType mapDataType, List<DataType> seenStructs) { if (mapDataType.getValueType() instanceof TemporaryDataType) { mapDataType.setValueType(getDataType(mapDataType.getValueType().getCode(), "")); } else { replaceTemporaryTypes(mapDataType.getValueType(), seenStructs); } if (mapDataType.getKeyType() instanceof TemporaryDataType) { mapDataType.setKeyType(getDataType(mapDataType.getKeyType().getCode(), "")); } else { replaceTemporaryTypes(mapDataType.getKeyType(), seenStructs); } }
/** * Returns a map datatype * * @param key the key type * @param value the value type * @return the map data type */ public static MapDataType getMap(DataType key, DataType value) { return new MapDataType(key, value); }
@Override public FieldPath buildFieldPath(String remainFieldName) { return buildFieldPath(remainFieldName, getKeyType(), getValueType()); }
} else if (dataType instanceof MapDataType) { MapDataType mapType = (MapDataType)dataType; DataType valueType = specialHandleAnnotationReferenceRecurse(docType, fieldName, mapType.getValueType()); if (valueType == null) { return null; mapType = mapType.clone(); mapType.setValueType(valueType); addType(docType, mapType); return mapType;
private static DataType valueTypeForMapUpdate(DataType parentType) { if (parentType instanceof WeightedSetDataType) { return DataType.INT; } else if (parentType instanceof CollectionDataType) { return ((CollectionDataType) parentType).getNestedType(); } else if (parentType instanceof MapDataType) { return ((MapDataType) parentType).getValueType(); } else { throw new UnsupportedOperationException("Unexpected parent type: " + parentType); } }
private static FieldValue keyTypeForMapUpdate(TokenBuffer.Token element, DataType expectedType) { FieldValue v; if (expectedType instanceof ArrayDataType) { v = new IntegerFieldValue(Integer.valueOf(element.text)); } else if (expectedType instanceof WeightedSetDataType) { v = ((WeightedSetDataType) expectedType).getNestedType().createFieldValue(element.text); } else if (expectedType instanceof MapDataType) { v = ((MapDataType) expectedType).getKeyType().createFieldValue(element.text); } else { throw new IllegalArgumentException("Container type " + expectedType + " not supported for match update."); } return v; } }
@Override public FieldPath buildFieldPath(String remainFieldName) { return MapDataType.buildFieldPath(remainFieldName, getNestedType(), DataType.INT); }
return null; MapFieldValue ret = DataType.getMap(nextKeyType, nextValType).createFieldValue(); for (Map.Entry<FieldValue, FieldValue> entry : next.entrySet()) { ret.put(entry.getKey(), entry.getValue());
public StructDataType getFirstStructRecursive() { DataType dataType = getDataType(); while (true) { // Currently no nesting of collections if (dataType instanceof CollectionDataType) { dataType = ((CollectionDataType)dataType).getNestedType(); } else if (dataType instanceof MapDataType) { dataType = ((MapDataType)dataType).getValueType(); } else { break; } } return (dataType instanceof StructDataType) ? (StructDataType)dataType : null; }
key.deserialize(this); } else if (f.getDataType() instanceof MapDataType) { key = ((MapDataType)f.getDataType()).getKeyType().createFieldValue(); key.deserialize(this); } else if (f.getDataType() instanceof ArrayDataType) {
private static boolean isMapOfStructType(DataType type) { if (type instanceof MapDataType) { MapDataType mapType = (MapDataType)type; return ComplexAttributeFieldUtils.isPrimitiveType(mapType.getKeyType()) && isStructType(mapType.getValueType()); } else { return false; } }
t.setKeyType(resolveTemporariesRecurse(t.getKeyType(), repo, docs)); t.setValueType(resolveTemporariesRecurse(t.getValueType(), repo, docs)); } else if (type instanceof CollectionDataType) { CollectionDataType t = (CollectionDataType) type;
public boolean hasFieldForStructFieldAttribute(Attribute structFieldAttribute) { StringTokenizer fieldNames = new StringTokenizer(structFieldAttribute.getName(), "."); if (!fieldNames.nextToken().equals(field.getName())) { return false; } if (isArrayOfStructType(dataType())) { StructDataType nestedType = (StructDataType)((ArrayDataType)dataType()).getNestedType(); if (structTypeContainsLastFieldNameComponent(nestedType, fieldNames)) { return true; } } else if (isMapOfStructType(dataType())) { MapDataType mapType = (MapDataType)dataType(); StructDataType valueType = (StructDataType)mapType.getValueType(); String subFieldName = fieldNames.nextToken(); if (subFieldName.equals("key") && !fieldNames.hasMoreTokens()) { return true; } else if (subFieldName.equals("value") && structTypeContainsLastFieldNameComponent(valueType, fieldNames)) { return true; } } else if (isMapOfPrimitiveType(dataType())) { String subFieldName = fieldNames.nextToken(); if ((subFieldName.equals("key") || subFieldName.equals("value")) && !fieldNames.hasMoreTokens()) { return true; } } return false; }
/** * Reserve space for this amount of keys in order to avoid resizing */ public void clearAndReserve(int count) { map = new MapFieldValue<>(new MapDataType(getDataType().getNestedType(), DataType.INT), count); }
public static boolean isMapOfPrimitiveType(DataType type) { if (type instanceof MapDataType) { MapDataType mapType = (MapDataType)type; return ComplexAttributeFieldUtils.isPrimitiveType(mapType.getKeyType()) && ComplexAttributeFieldUtils.isPrimitiveType(mapType.getValueType()); } else { return false; } }
wasModified = checkAndRemove(fieldPath.get(pos).getLookupKey(), val.iterateNested(fieldPath, pos + 1, handler), wasModified, keysToRemove); } else if (handler.createMissingPath()) { val = getDataType().getValueType().createFieldValue(); FieldPathIteratorHandler.ModificationStatus status = val.iterateNested(fieldPath, pos + 1, handler); if (status == FieldPathIteratorHandler.ModificationStatus.MODIFIED) {
private static void registerMapType(DocumentTypeManager manager, int id, DocumentmanagerConfig.Datatype.Maptype map) { DataType keyType = manager.getDataType(map.keytype(), ""); DataType valType = manager.getDataType(map.valtype(), ""); MapDataType type = new MapDataType(keyType, valType, id); manager.register(type); }
public void putAll(java.util.Map<? extends K, ? extends V> m) { for (K key : m.keySet()) { validateCompatibleTypes(getDataType().getKeyType(), key); } for (V value : m.values()) { validateCompatibleTypes(getDataType().getValueType(), value); } values.putAll(m); }