/** * Returns a MetaData instances containing the current entries, <b>and</b> the given {@code key} and given * {@code value}. * If {@code key} already existed, it's old {@code value} is overwritten with the given * {@code value}. * * @param key The key for the entry * @param value The value of the entry * @return a MetaData instance with an additional entry */ public MetaData and(String key, Object value) { HashMap<String, Object> newValues = new HashMap<>(values); newValues.put(key, value); return new MetaData(newValues); }
/** * Returns a MetaData instance with the items with given {@code keys} removed. Keys for which there is no * assigned value are ignored.<br/> * This MetaData instance is not influenced by this operation. * * @param keys The keys of the entries to remove * @return a MetaData instance without the given {@code keys} */ public MetaData withoutKeys(Set<String> keys) { if (keys.isEmpty()) { return this; } Map<String, ?> modified = new HashMap<>(values); keys.forEach(modified::remove); return new MetaData(modified); }
/** * Creates a new MetaData instance from the given {@code metaDataEntries}. If {@code metaDataEntries} is * already a MetaData instance, it is returned as is. This makes this method more suitable than the {@link * #MetaData(java.util.Map)} copy-constructor. * * @param metaDataEntries the items to populate the MetaData with * @return a MetaData instance with the given {@code metaDataEntries} as content */ public static MetaData from(Map<String, ?> metaDataEntries) { if (metaDataEntries instanceof MetaData) { return (MetaData) metaDataEntries; } else if (metaDataEntries == null || metaDataEntries.isEmpty()) { return MetaData.emptyInstance(); } return new MetaData(metaDataEntries); }
/** * Returns a MetaData instance containing values of {@code this}, combined with the given * {@code additionalEntries}. If any entries have identical keys, the values from the * {@code additionalEntries} will take precedence. * * @param additionalEntries The additional entries for the new MetaData * @return a MetaData instance containing values of {@code this}, combined with the given * {@code additionalEntries} */ public MetaData mergedWith(Map<String, ?> additionalEntries) { if (additionalEntries.isEmpty()) { return this; } if (isEmpty()) { return MetaData.from(additionalEntries); } Map<String, Object> merged = new HashMap<>(values); merged.putAll(additionalEntries); return new MetaData(merged); }
/** * Returns a MetaData instances containing the current entries, <b>and</b> the given {@code key} and given * {@code value}. * If {@code key} already existed, it's old {@code value} is overwritten with the given * {@code value}. * * @param key The key for the entry * @param value The value of the entry * @return a MetaData instance with an additional entry */ public MetaData and(String key, Object value) { HashMap<String, Object> newValues = new HashMap<>(values); newValues.put(key, value); return new MetaData(newValues); }
/** * Returns a MetaData instances containing the current entries, <b>and</b> the given {@code key} and given * {@code value}. * If {@code key} already existed, it's old {@code value} is overwritten with the given * {@code value}. * * @param key The key for the entry * @param value The value of the entry * @return a MetaData instance with an additional entry */ public MetaData and(String key, Object value) { HashMap<String, Object> newValues = new HashMap<>(values); newValues.put(key, value); return new MetaData(newValues); }
/** * Returns a MetaData instance with the items with given {@code keys} removed. Keys for which there is no * assigned value are ignored.<br/> * This MetaData instance is not influenced by this operation. * * @param keys The keys of the entries to remove * @return a MetaData instance without the given {@code keys} */ public MetaData withoutKeys(Set<String> keys) { if (keys.isEmpty()) { return this; } Map<String, ?> modified = new HashMap<>(values); keys.forEach(modified::remove); return new MetaData(modified); }
/** * Returns a MetaData instance with the items with given {@code keys} removed. Keys for which there is no * assigned value are ignored.<br/> * This MetaData instance is not influenced by this operation. * * @param keys The keys of the entries to remove * @return a MetaData instance without the given {@code keys} */ public MetaData withoutKeys(Set<String> keys) { if (keys.isEmpty()) { return this; } Map<String, ?> modified = new HashMap<>(values); keys.forEach(modified::remove); return new MetaData(modified); }
/** * Creates a new MetaData instance from the given {@code metaDataEntries}. If {@code metaDataEntries} is * already a MetaData instance, it is returned as is. This makes this method more suitable than the {@link * #MetaData(java.util.Map)} copy-constructor. * * @param metaDataEntries the items to populate the MetaData with * @return a MetaData instance with the given {@code metaDataEntries} as content */ public static MetaData from(Map<String, ?> metaDataEntries) { if (metaDataEntries instanceof MetaData) { return (MetaData) metaDataEntries; } else if (metaDataEntries == null || metaDataEntries.isEmpty()) { return MetaData.emptyInstance(); } return new MetaData(metaDataEntries); }
/** * Creates a new MetaData instance from the given {@code metaDataEntries}. If {@code metaDataEntries} is * already a MetaData instance, it is returned as is. This makes this method more suitable than the {@link * #MetaData(java.util.Map)} copy-constructor. * * @param metaDataEntries the items to populate the MetaData with * @return a MetaData instance with the given {@code metaDataEntries} as content */ public static MetaData from(Map<String, ?> metaDataEntries) { if (metaDataEntries instanceof MetaData) { return (MetaData) metaDataEntries; } else if (metaDataEntries == null || metaDataEntries.isEmpty()) { return MetaData.emptyInstance(); } return new MetaData(metaDataEntries); }
/** * Returns a MetaData instance containing values of {@code this}, combined with the given * {@code additionalEntries}. If any entries have identical keys, the values from the * {@code additionalEntries} will take precedence. * * @param additionalEntries The additional entries for the new MetaData * @return a MetaData instance containing values of {@code this}, combined with the given * {@code additionalEntries} */ public MetaData mergedWith(Map<String, ?> additionalEntries) { if (additionalEntries.isEmpty()) { return this; } if (isEmpty()) { return MetaData.from(additionalEntries); } Map<String, Object> merged = new HashMap<>(values); merged.putAll(additionalEntries); return new MetaData(merged); }
/** * Returns a MetaData instance containing values of {@code this}, combined with the given * {@code additionalEntries}. If any entries have identical keys, the values from the * {@code additionalEntries} will take precedence. * * @param additionalEntries The additional entries for the new MetaData * @return a MetaData instance containing values of {@code this}, combined with the given * {@code additionalEntries} */ public MetaData mergedWith(Map<String, ?> additionalEntries) { if (additionalEntries.isEmpty()) { return this; } if (isEmpty()) { return MetaData.from(additionalEntries); } Map<String, Object> merged = new HashMap<>(values); merged.putAll(additionalEntries); return new MetaData(merged); }