Value Compaction Algorithm

http://json-ld.org/spec/latest/json-ld-api/#value-compaction

@param activeProperty
The Active Property
@param value
The value to compact
@return The compacted value
485718
public Object compactValue(String activeProperty, Map<String, Object> value) {
        // 1)
        int numberMembers = value.size();
        // 2)
        if (value.containsKey(JsonLdConsts.INDEX)
                && JsonLdConsts.INDEX.equals(this.getContainer(activeProperty))) {
            numberMembers--;
        }
        // 3)
        if (numberMembers > 2) {
            return value;
        }
        // 4)
        final String typeMapping = getTypeMapping(activeProperty);
        final String languageMapping = getLanguageMapping(activeProperty);
        if (value.containsKey(JsonLdConsts.ID)) {
            // 4.1)
            if (numberMembers == 1 && JsonLdConsts.ID.equals(typeMapping)) {
                return compactIri((String) value.get(JsonLdConsts.ID));
            }
            // 4.2)
            if (numberMembers == 1 && JsonLdConsts.VOCAB.equals(typeMapping)) {
                return compactIri((String) value.get(JsonLdConsts.ID), true);
            }
            // 4.3)
            return value;
        }
        final Object valueValue = value.get(JsonLdConsts.VALUE);
        // 5)
        if (value.containsKey(JsonLdConsts.TYPE)
                && Obj.equals(value.get(JsonLdConsts.TYPE), typeMapping)) {
            return valueValue;
        }
        // 6)
        if (value.containsKey(JsonLdConsts.LANGUAGE)) {
            // TODO: SPEC: doesn't specify to check default language as well
            if (Obj.equals(value.get(JsonLdConsts.LANGUAGE), languageMapping) || Obj
                    .equals(value.get(JsonLdConsts.LANGUAGE), this.get(JsonLdConsts.LANGUAGE))) {
                return valueValue;
            }
        }
        // 7)
        if (numberMembers == 1 && (!(valueValue instanceof String)
                || !this.containsKey(JsonLdConsts.LANGUAGE)
                || (termDefinitions.containsKey(activeProperty)
                        && getTermDefinition(activeProperty).containsKey(JsonLdConsts.LANGUAGE)
                        && languageMapping == null))) {
            return valueValue;
        }
        // 8)
        return value;
    }
372655
public int addValue(String property, String value) {
		int count = 0;
		for (String geoPackage : propertiesMap.keySet()) {
			if (addValue(geoPackage, property, value)) {
				count++;
			}
		}
		return count;
	}
1297514
public static <T> T getValue(ValuedProperty<T> property) {
		return (property == null) ? null : property.getValue();
	}
483032
public JsonNode getStaticPropertyValue(final String fqn, final String property) {
        ObjectNode req = makeRequest("sget");
        req.put("fqn", fqn);
        req.put("property", property);
        return this.runtime.requestResponse(req).get("value");
    }
98514
@Override
    public Object getDehydratedPropertyValue(JaversProperty property) {
        Edge edge = getEdge(property);

        if (edge != null) {
            return edge.getDehydratedPropertyValue();
        }

        Object propertyValue = getCdo().getPropertyValue(property);
        if (propertyValue == null) {
            return null;
        }

        //Collections & Maps are copied to a new immutable structure
        if (property.getType() instanceof EnumerableType) {
            EnumerableType enumerableType = property.getType();

            return enumerableType.map(propertyValue, it -> it);
        }

        return getCdo().getPropertyValue(property);
    }
100380
public boolean removeValue(Object name,Object value)
    {
        Object lo = super.get(name);
        Object ln=lo;
        int s=LazyList.size(lo);
        if (s>0)
        {
            ln=LazyList.remove(lo,value);
            if (ln==null)
                super.remove(name);
            else
                super.put(name, ln);
        }
        return LazyList.size(ln)!=s;
    }
291146
public static String compactDecimal(final Number value, final Locale locale)
    {
        return compactDecimal(value, CompactStyle.SHORT, locale);
    }
1146014
public JerseyModuleExtender setProperty(String name, Object value) {
        contributeProperties().addBinding(name).toInstance(value);
        return this;
    }
1218741
private Object getPropertyTypeValue(Class propertyType, Object value) {
        if (propertyType.equals(String.class)) {
            return value.toString();
        } else if (propertyType.equals(Boolean.class) || propertyType.equals(Boolean.TYPE)) {
            Boolean arg = null;
            if (value instanceof Boolean) {
                arg = (Boolean) value;
            } else {
                arg = Boolean.parseBoolean(value.toString());
            }
            return arg;
        } else if (propertyType.equals(Short.class) || propertyType.equals(Short.TYPE)) {
            Short arg = null;
            if (value instanceof Short) {
                arg = (Short) value;
            } else {
                arg = Short.parseShort(value.toString());
            }
            return arg;
        } else if (propertyType.equals(Integer.class) || propertyType.equals(Integer.TYPE)) {
            Integer arg = null;
            if (value instanceof Integer) {
                arg = (Integer) value;
            } else {
                arg = Integer.parseInt(value.toString());
            }
            return arg;
        } else if (propertyType.equals(Long.class) || propertyType.equals(Long.TYPE)) {
            Long arg = null;
            if (value instanceof Long) {
                arg = (Long) value;
            } else {
                arg = Long.parseLong(value.toString());
            }
            return arg;
        } else if (propertyType.equals(Float.class) || propertyType.equals(Float.TYPE)) {
            Float arg = null;
            if (value instanceof Float) {
                arg = (Float) value;
            } else {
                arg = Float.parseFloat(value.toString());
            }
            return arg;
        } else if (propertyType.equals(Double.class) || propertyType.equals(Double.TYPE)) {
            Double arg = null;
            if (value instanceof Double) {
                arg = (Double) value;
            } else {
                arg = Double.parseDouble(value.toString());
            }
            return arg;
        } else { // Object
            return value;
        }
    }
699534
private static Boolean getJsonValueAsBoolean(JsonValue value) {
        if (value != null) {
            if (value.getValueType() == ValueType.TRUE) {
                return true;
            } else if (value.getValueType() == ValueType.FALSE) {
                return false;
            }
        }
        return null;
    }
1067485
public JsonValueProcessor findJsonValueProcessor( Class propertyType ) {
      if( !typeMap.isEmpty() ) {
         Object key = jsonValueProcessorMatcher.getMatch( propertyType, typeMap.keySet() );
         return (JsonValueProcessor) typeMap.get( key );

      }
      return null;
   }
260285
public org.inferred.freebuilder.processor.property.Property.Builder mergeFrom(
      org.inferred.freebuilder.processor.property.Property value) {
    Property_Builder defaults = new org.inferred.freebuilder.processor.property.Property.Builder();
    if (defaults._unsetProperties.contains(Property.TYPE)
        || !Objects.equals(value.getType(), defaults.getType())) {
      setType(value.getType());
    }
    value.getBoxedType().ifPresent(this::setBoxedType);
    if (defaults._unsetProperties.contains(Property.NAME)
        || !Objects.equals(value.getName(), defaults.getName())) {
      setName(value.getName());
    }
    if (defaults._unsetProperties.contains(Property.CAPITALIZED_NAME)
        || !Objects.equals(value.getCapitalizedName(), defaults.getCapitalizedName())) {
      setCapitalizedName(value.getCapitalizedName());
    }
    if (defaults._unsetProperties.contains(Property.ALL_CAPS_NAME)
        || !Objects.equals(value.getAllCapsName(), defaults.getAllCapsName())) {
      setAllCapsName(value.getAllCapsName());
    }
    if (defaults._unsetProperties.contains(Property.USING_BEAN_CONVENTION)
        || value.isUsingBeanConvention() != defaults.isUsingBeanConvention()) {
      setUsingBeanConvention(value.isUsingBeanConvention());
    }
    if (defaults._unsetProperties.contains(Property.GETTER_NAME)
        || !Objects.equals(value.getGetterName(), defaults.getGetterName())) {
      setGetterName(value.getGetterName());
    }
    if (defaults._unsetProperties.contains(Property.FULLY_CHECKED_CAST)
        || value.isFullyCheckedCast() != defaults.isFullyCheckedCast()) {
      setFullyCheckedCast(value.isFullyCheckedCast());
    }
    if (value instanceof Value && accessorAnnotations == ImmutableList.<Excerpt>of()) {
      accessorAnnotations = ImmutableList.copyOf(value.getAccessorAnnotations());
    } else {
      addAllAccessorAnnotations(value.getAccessorAnnotations());
    }
    return (org.inferred.freebuilder.processor.property.Property.Builder) this;
  }
587763
public StrongCounterConfigurationBuilder lowerBound(long value) {
      attributes.attribute(StrongCounterConfiguration.LOWER_BOUND).set(value);
      return self();
   }
376668
@Override
	public String getProperty(final String value, final String def) {
		final String result = getProperty(value);
		return result == null ? def : result;
	}
1269944
public static StackManipulation of(Serializable value) {
        if (value == null) {
            return NullConstant.INSTANCE;
        }
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
            try {
                objectOutputStream.writeObject(value);
            } finally {
                objectOutputStream.close();
            }
            return new SerializedConstant(byteArrayOutputStream.toString(CHARSET));
        } catch (IOException exception) {
            throw new IllegalStateException("Cannot serialize " + value, exception);
        }
    }
1033552
public KeyOperationsParameters withValue(byte[] value) {
        if (value == null) {
            this.value = null;
        } else {
            this.value = Base64Url.encode(value);
        }
        return this;
    }
848792
public static void setActiveFieldValue(ODocument document, Boolean active) {
        setFieldValue(document, ACTIVE_FIELD, active.toString());
    }