/** * Reads the given system property. * * @param property the property to read * @return the contents of the property wrapped as {@link Value} */ protected static Value getProperty(String property) { return Value.of(System.getProperty(property)); }
/** * Returns the named out parameter * * @param key the parameter to return * @return the value of the given out parameter wrapped as {@link Value} */ public Value getValue(String key) { return Value.of(output.get(key)); }
/** * Returns the value of the requested field wrapped as {@link Value}. * * @param field the field to fetch * @return the value for the given field */ public Value get(String field) { return Value.of(obj.get(field)); }
/** * Queries a {@link sirius.kernel.commons.Value} by evaluating the given xpath. * * @param path the xpath used to retrieve property * @return a Value wrapping the value returned by the given xpath expression * @throws java.lang.IllegalArgumentException if an invalid xpath was given */ @Nonnull public Value queryValue(String path) { return Value.of(queryString(path)); }
/** * Provides the value associated with the given key as {@link Value} * * @param key the key for which the value should ne returned * @return a value wrapping the internally associated value for the given key */ @Nonnull public Value getValue(Object key) { return Value.of(get(key)); }
/** * Provides a "routed by" context for {@link #find(Class, Object, ContextInfo...)}. * * @param value the routing value to use * @return the value wrapped as context info */ public static ContextInfo routedBy(String value) { return new ContextInfo(CONTEXT_ROUTING, Value.of(value)); }
/** * Returns a new <tt>Value</tt> which will wrap the given value, if the current value is empty. * Otherwise, the current value will be returned. * * @param replacement the value which is used as replacement if this value is empty * @return a new Value wrapping the given value or the current value if this is not empty. */ @Nonnull public Value replaceEmptyWith(@Nullable Object replacement) { if (isFilled()) { return this; } return Value.of(replacement); }
/** * Reads a embedded map. * * @param key the key of the map to read * @return the map within the config */ public Map<String, String> getMap(String key) { Map<String, String> result = new HashMap<>(); config.getConfig(key) .entrySet() .forEach(e -> result.put(e.getKey(), Value.of(e.getValue().unwrapped()).asString())); return result; }
private static SQLEntity makeEntity(EntityDescriptor descriptor, String alias, Set<String> columns, ResultSet rs) throws Exception { SQLEntity result = (SQLEntity) descriptor.make(OMA.class, alias, key -> { try { return columns.contains(key.toUpperCase()) ? Value.of(rs.getObject(key)) : null; } catch (SQLException e) { throw Exceptions.handle(OMA.LOG, e); } }); if (descriptor.isVersioned() && columns.contains(BaseMapper.VERSION.toUpperCase())) { result.setVersion(rs.getInt(BaseMapper.VERSION.toUpperCase())); } return result; }
/** * Returns the value of the requested field wrapped as {@link Value}. * * @param field the field to fetch * @return the value for the given field */ public Value get(Mapping field) { return Value.of(obj.get(field.toString())); }
/** * Returns a two letter abbreviation of the name of the given day, like {@code "Mo"}. * * @param day the weekday to be translated. Use constants {@link Calendar#MONDAY} etc. * @return returns the first two letters of the name * or {@code ""} if the given index was invalid. */ public static String getDayOfWeekShort(int day) { return Value.of(getDayOfWeek(day)).substring(0, 2); }
private void transformValues(List<?> values, List<Object> result) { for (Object element : values) { Object enumValue = Value.of(element).coerce(getField().getAnnotation(ListType.class).value(), null); if (enumValue != null) { result.add(enumValue); } } }
private Value convertToString(NumberFormat format, boolean smartRound) { if (isEmpty()) { return Value.of(null); } DecimalFormat df = new DecimalFormat(); df.setMinimumFractionDigits(smartRound ? 0 : format.getScale()); df.setMaximumFractionDigits(format.getScale()); df.setDecimalFormatSymbols(format.getDecimalFormatSymbols()); df.setGroupingUsed(format.isUseGrouping()); return Value.of(df.format(value)).append(" ", format.getSuffix()); }
@Override @SuppressWarnings("unchecked") public Object transformFromSource(Object value) { try { return Value.of(value) .coerce((Class<Object>) getField().getType(), isNullAllowed() ? null : getField().getType().getEnumConstants()[0]); } catch (IllegalArgumentException e) { Exceptions.ignore(e); return isNullAllowed() ? null : getField().getType().getEnumConstants()[0]; } }
@SuppressWarnings({"unchecked", "raw", "rawtypes"}) @Override public Object transformValue(Value value) { if (value.isFilled()) { return value.asEnum((Class<Enum>) field.getType()); } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return null; } return Value.of(defaultValue).asEnum((Class<Enum>) field.getType()); }
/** * Returns the inner value stored in the object in the given field. * * @param field the field to read the object from * @param key the key to read from the object * @return the value within the inner object wrapped as {@link Value} */ public Value getValueInObject(String field, String key) { if (Strings.isEmpty(key)) { return Value.EMPTY; } return Value.of(getObject(field).get(key)); }
@SuppressWarnings("unchecked") private Object transfromFromElastic(Value object) { List<Nested> result = new ArrayList<>(); Object obj = object.get(); if (obj instanceof List) { for (JSONObject doc : (List<JSONObject>) obj) { try { result.add((Nested) getNestedDescriptor().make(Elastic.class, null, key -> Value.of(doc.get(key)))); } catch (Exception e) { throw Exceptions.handle(Mongo.LOG, e); } } } return result; }
protected FieldValue compileValue(Property property, FieldValue value) { if (!value.isExact() && "-".equals(value.getValue())) { return new FieldValue(null, false); } return new FieldValue(property.transformValue(Value.of(value.getValue())), value.isExact()); }
@Override public Object transformValue(Value value) { if (value.isFilled()) { return NLS.parseUserString(Amount.class, value.asString()); } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return Amount.NOTHING; } return Value.of(defaultValue).getAmount(); }
@Override public Object transformValue(Value value) { if (value.isFilled()) { Long result = value.getLong(); if (result == null) { throw illegalFieldValue(value); } return result; } if (this.isNullable() || Strings.isEmpty(defaultValue)) { return null; } return Value.of(defaultValue).getLong(); }