/** * Determines if the wrapped value is not null. * * @return <tt>true</tt> if the wrapped value is neither <tt>null</tt> nor "" */ public boolean isFilled() { return !isEmptyString(); }
/** * Returns a new {@link Value} which will be empty its value equals one of the given ignored values. * * @param ignoredValues the list of values which will be replaced by an empty value * @return a <tt>Value</tt> which is empty if the currently wrapped value equals to one of the given values. * Otherwise the current value is returned. */ @Nonnull public Value ignore(String... ignoredValues) { if (isEmptyString()) { return this; } for (String val : ignoredValues) { if (data.equals(val)) { return Value.EMPTY; } } return this; }
@SuppressWarnings("unchecked") @Override public Object transformValue(Value value) { if (value.isEmptyString()) { return null; } return value.get(); }
@SuppressWarnings("unchecked") @Override public Object transformValue(Value value) { if (value.isEmptyString()) { return null; } return value.get(); }
@SuppressWarnings("unchecked") @Override public Object transformValue(Value value) { if (value.isEmptyString()) { return null; } return value.get(); }
@SuppressWarnings("unchecked") @Override public Object transformValue(Value value) { if (value.isEmptyString()) { return null; } return value.get(); }
/** * Determines if the string representation of the wrapped value is equal to the string representation of the given * object. * <p>In this case equality does not take differences of upper and lower case characters into account. Therefore * this is boilerplate for {@code asString().equalsIgnoreCase(otherString.toString())} * (With proper <tt>null</tt> checks.) * * @param otherString the input to compare against * @return <tt>true</tt> if the string representation of the wrapped object is equal to the string representation * of the given parameter, where differences of lower- and uppercase are not taken into account. * @see String#equalsIgnoreCase(String) */ public boolean equalsIgnoreCase(Object otherString) { if (Strings.isEmpty(otherString)) { return isEmptyString(); } return asString().equalsIgnoreCase(otherString.toString()); }
/** * Returns the substring of the internal value starting right after the first occurrence of the given separator. * <p> * If the separator is not found in the string, or if the internal value is empty, "" is returned. * <p> * An example would be: * <pre> * {@code Value.of("test.tmp.pdf").afterFirst("."); // returns "tmp.pdf"} * </pre> * * @param separator the separator string to search for * @return the substring right after the first occurrence of the given separator. This will not include the * separator itself. */ @Nonnull public String afterFirst(@Nonnull String separator) { if (!isEmptyString()) { int idx = asString().indexOf(separator); if (idx > -1) { return left(idx * -1 - 1); } } return ""; }
/** * Returns the substring of the internal value starting right after the last occurrence of the given separator. * <p> * If the separator is not found in the string, or if the internal value is empty, "" is returned. * <p> * An example would be: * <pre> * {@code Value.of("test.tmp.pdf").afterLast("."); // returns "pdf"} * </pre> * * @param separator the separator string to search for * @return the substring right after the last occurrence of the given separator. This will not include the * separator itself. */ @Nonnull public String afterLast(@Nonnull String separator) { if (!isEmptyString()) { int idx = asString().lastIndexOf(separator); if (idx > -1) { return left(idx * -1 - 1); } } return ""; }
/** * Returns the substring of the internal value containing everything up to the last occurrence of the given * separator. * <p> * If the separator is not found in the string, or if the internal value is empty, "" is returned. * <p> * An example would be: * <pre> * {@code Value.of("test.tmp.pdf").beforeLast("."); // returns "test.tmp"} * </pre> * * @param separator the separator string to search for * @return the substring up to the last occurrence of the given separator. This will not include the separator * itself. */ @Nonnull public String beforeLast(@Nonnull String separator) { if (!isEmptyString()) { int idx = asString().lastIndexOf(separator); if (idx > -1) { return left(idx); } } return ""; }
/** * Returns the substring of the internal value containing everything up to the first occurrence of the given * separator. * <p> * If the separator is not found in the string, or if the internal value is empty, "" is returned. * <p> * An example would be: * <pre> * {@code Value.of("test.tmp.pdf").beforeFirst("."); // returns "test"} * </pre> * * @param separator the separator string to search for * @return the substring up to the first occurrence of the given separator. This will not include the separator * itself. */ @Nonnull public String beforeFirst(@Nonnull String separator) { if (!isEmptyString()) { int idx = asString().indexOf(separator); if (idx > -1) { return left(idx); } } return ""; }
@Override public void execute(Output output, String... params) throws Exception { Value name = Value.indexOf(0, params); if (name.isEmptyString()) { output.line("No class name given. Try: doc <classname>"); return; } Injector.getAllLoadedClasses() .stream() .filter(c -> c.getName().toLowerCase().contains(name.asString().toLowerCase())) .forEach(c -> { output.line(c.getName()); output.separator(); for (Method m : c.getMethods()) { output.line(m.toString()); } output.blankLine(); }); }
@Override public Object transformValue(Value value) { if (value.isEmptyString()) { return Collections.emptyList(); } List<Tuple<Double, Double>> result = new ArrayList<>(); for (String location : value.asString().split("\n")) { Tuple<String, String> latLong = Strings.split(location, ","); try { Tuple<Double, Double> coordinate = Tuple.create(Double.parseDouble(latLong.getFirst()), Double.parseDouble(latLong.getSecond())); result.add(coordinate); } catch (NumberFormatException e) { Exceptions.ignore(e); } } return result; }
/** * Returns a value which wraps {@code value + separator + this} * <p> * If the current value is empty, the given value is returned (without the separator). If the given * value is an empty string, the current value is returned (without the separator). * * @param separator the separator to be put in between the two. If the given value is <tt>null</tt>, "" is assumed * @param value the value to be appended to the current value. * @return a <tt>Value</tt> representing the given value appended with the current value and separated * with the given separator */ @Nonnull public Value prepend(@Nullable String separator, @Nullable Object value) { if (Strings.isEmpty(value)) { return this; } if (isEmptyString()) { return Value.of(value); } if (separator == null) { separator = ""; } return Value.of(value + separator + toString()); }
@SuppressWarnings("unchecked") @Override public Object transformValue(Value value) { if (value.isEmptyString()) { return null; } if (entityRef.getType().isInstance(value.get())) { return value.get(); } Optional<E> e = find(entityRef.getType(), value); if (!e.isPresent()) { throw illegalFieldValue(value); } return e.get(); }
/** * Returns a value which wraps {@code this + separator + value} * <p> * If the current value is empty, the given value is returned (without the separator). If the given * value is an empty string, the current value is returned (without the separator). * * @param separator the separator to be put in between the two. If the given value is <tt>null</tt>, "" is assumed * @param value the value to be appended to the current value. * @return a <tt>Value</tt> representing the current value appended with the given value and separated * with the given separator */ @Nonnull public Value append(@Nullable String separator, @Nullable Object value) { if (Strings.isEmpty(value)) { return this; } if (isEmptyString()) { return Value.of(value); } if (separator == null) { separator = ""; } return Value.of(toString() + separator + value); }
/** * Extracts and converts the value from the given request. * * @param name name of the parameter to read * @param ctx the request to read the data from * @return the converted value which can be assigned to the field */ protected Object transformFromRequest(String name, WebContext ctx) { Value value = ctx.get(name); if (value.isEmptyString() && !field.getType().isPrimitive()) { return null; } Object result = value.coerce(field.getType(), null); if (result == null) { UserContext.setFieldError(name, value.get()); throw Exceptions.createHandled() .withNLSKey("Property.invalidInput") .set("field", NLS.get(field.getDeclaringClass().getSimpleName() + "." + name)) .set("value", value.asString()) .handle(); } return result; }
@Override public void execute(Output output, String... params) throws Exception { if (Value.indexOf(0, params).isEmptyString()) { output.line("Usage: updateMapping <type>"); } else { Class<? extends Entity> type = findTypeOrReportError(output, params[0]); if (type != null) { EntityDescriptor ed = index.getDescriptor(type); try { index.addMapping(index.getIndexName(ed.getIndex()), type); output.line("Mapping was updated..."); } catch (Exception e) { output.line(e.getMessage()); output.line("If necessary use the force option but be aware that there might be data loss!"); } } } }
@Override protected Object transformFromRequest(String name, WebContext ctx) { Value value = ctx.get(name); if (value.isEmptyString()) { return null; } try { return NLS.parseUserString(LocalDate.class, value.getString()); } catch (IllegalArgumentException e) { Exceptions.ignore(e); UserContext.setFieldError(name, value.get()); throw Exceptions.createHandled() .withNLSKey("Property.invalidInput") .set("field", NLS.get(getField().getDeclaringClass().getSimpleName() + "." + name)) .set("value", value.asString()) .handle(); } }
@Override protected Object transformFromRequest(String name, WebContext ctx) { Value value = ctx.get(name); if (value.isEmptyString()) { return null; } try { return NLS.parseUserString(LocalDateTime.class, value.getString()); } catch (IllegalArgumentException e) { Exceptions.ignore(e); UserContext.setFieldError(name, value.get()); throw Exceptions.createHandled() .withNLSKey("Property.invalidInput") .set("field", NLS.get(getField().getDeclaringClass().getSimpleName() + "." + name)) .set("value", value.asString()) .handle(); } }