@Override public Map<String, PropertyValue> getProperties() { Map<String,PropertyValue> result = new HashMap<>(); for (PropertyValue en : this.propertySource.getProperties().values()) { String targetKey = keyMapper.mapKey(en.getKey()); if (targetKey != null) { result.put(targetKey, PropertyValue.of(targetKey, en.getValue(), getName())); } } return result; }
@Override public int hashCode() { return Objects.hash(getKey(), getValue(), getSource(), getMetaEntries()); }
@Override public Map<String, PropertyValue> getProperties() { return PropertyValue.map(this.properties,getName()); }
@Override public Map<String, PropertyValue> getProperties() { Map<String,PropertyValue> result = new HashMap<>(); for(PropertyValue val : source.getProperties().values()) { String mappedValue = valueFilter.mapProperty(val.getKey(), val.getValue()); PropertyValue value = val.toBuilder().setValue(mappedValue).build(); result.put(val.getKey(), value); } return result; }
/** * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together. * * @param val the {@code properties} to set * @return a reference to this Builder */ public Builder withProperty(String key, String val) { this.properties.put(key, PropertyValue.of(key, val, name)); return this; }
/** * This method will create a change set that clears all entries fromMap the given base configuration/properties. * * @return the builder for chaining. */ public PropertySourceChangeBuilder deleteAll() { this.delta.clear(); for (Map.Entry<String, PropertyValue> en : this.source.getProperties().entrySet()) { this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue().getValue(), null)); } return this; }
/** * Get the current properties, composed by the loaded {@link PropertySource} and filtered * by registered {@link PropertyFilter}. * * @return the final properties. */ @Override public Map<String, String> getProperties() { Map<String, PropertyValue> filtered = PropertyFiltering.applyFilters( configEvaluator.evaluateRawValues(configurationContext), configurationContext); Map<String,String> result = new HashMap<>(); for(PropertyValue val:filtered.values()){ if(val.getValue()!=null) { result.put(val.getKey(), val.getValue()); // TODO: Discuss metadata handling... result.putAll(val.getMetaEntries()); } } return result; }
/** * Compares the two property config/configurations and creates a collection current all changes * that must be applied to render {@code map1} into {@code map2}. * * @param map1 the source map, not null. * @param map2 the target map, not null. * @return a collection current change events, never null. */ public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) { List<PropertyChangeEvent> changes = new ArrayList<>(); for (Map.Entry<String, PropertyValue> en : map1.getProperties().entrySet()) { PropertyValue val = map2.get(en.getKey()); if (val == null) { changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue().getValue())); } else if (!val.equals(en.getValue())) { changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue().getValue())); } } for (Map.Entry<String, PropertyValue> en : map2.getProperties().entrySet()) { PropertyValue val = map1.get(en.getKey()); if (val == null) { changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), null)); } else if (!val.equals(en.getValue())) { changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), val.getValue())); } } return changes; }
for (PropertyFilter filter : context.getContext().getPropertyFilters()) { filteredValue = filter.filterProperty(inputValue, context); if (filteredValue != null && !filteredValue.equals(inputValue)) { changes++; LOG.finest("Filter - " + inputValue + " -> " + filteredValue + " by " + filter);
/** * Constructor for a simple properties configuration. * @param name the source's name, not null * @param props the properties, not null */ public PropertiesBasedPropertySource(String name, Map<String,String> props) { this.name = Objects.requireNonNull(name); for (Entry<String, String> en : props.entrySet()) { this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); } }
@Override public String get(String key) { Objects.requireNonNull(key, "Key must not be null."); PropertyValue value = configEvaluator.evaluteRawValue(key, configurationContext); if(value==null || value.getValue()==null){ return null; } value = PropertyFiltering.applyFilter(value, configurationContext); if(value!=null){ return value.getValue(); } return null; }
/** * Get the current properties, composed by the loaded {@link PropertySource} and filtered * by registered {@link org.apache.tamaya.spi.PropertyFilter}. * * @return the final properties. */ @Override public Map<String, String> getProperties() { Map<String, PropertyValue> filtered = PropertyFiltering.applyFilters( configEvaluator.evaluateRawValues(configurationContext), configurationContext); Map<String,String> result = new HashMap<>(); for(PropertyValue val:filtered.values()){ if(val.getValue()!=null) { result.put(val.getKey(), val.getValue()); // TODO: Discuss metadata handling... result.putAll(val.getMetaEntries()); } } return result; }
public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context){ LOG.finest("Resolving " + valueToBeFiltered); String newVal = evaluator().evaluateExpression(valueToBeFiltered.getKey(), valueToBeFiltered.getValue(), true); if(newVal!=null){ return valueToBeFiltered.toBuilder().setValue(newVal).build();
@Override public Map<String, PropertyValue> getProperties() { Map<String, PropertyValue> allProps; if (overriding) { allProps = new HashMap<>(); for(PropertyValue val:basePropertySource.getProperties().values()){ allProps.put(val.getKey(), val); } allProps.putAll(addedProperties); } else { allProps = new HashMap<>(addedProperties); for(PropertyValue val:basePropertySource.getProperties().values()){ allProps.put(val.getKey(), val); } } return allProps; }
for (PropertyFilter filter : context.getContext().getPropertyFilters()) { filteredValue = filter.filterProperty(inputValue, context); if (filteredValue != null && !filteredValue.equals(inputValue)) { changes++; LOG.finest("Filter - " + inputValue + " -> " + filteredValue + " by " + filter);
/** * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together. * * @param val the {@code properties} to set * @return a reference to this Builder */ public Builder withProperties(Map<String, String> val) { for(Map.Entry<String,String> en: val.entrySet()) { this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name)); } return this; }