/** * Sets the given value (its string representation), mit limits this to <tt>limit</tt> characters. * * @param key the key to which the value should be associated * @param value the value which string representation should be put into the context * @param limit the maximal number of characters to put into the map. Everything after that will be discarded */ public void putLimited(String key, Object value, int limit) { set(key, Strings.limit(value, limit)); }
/** * Formats the represented value by rounding to zero decimal places. The rounding mode is obtained from * {@link NumberFormat#NO_DECIMAL_PLACES}. * * @return a rounded representation of this number using {@code NumberFormat#NO_DECIMAL_PLACES} * or "" is the value is empty. */ public String toRoundedString() { return toSmartRoundedString(NumberFormat.NO_DECIMAL_PLACES).toString(); }
/** * String representation of the value along with its unit (is necessary) * * @return a string representation of the value */ public String getValueAsString() { return Amount.of(value).toSmartRoundedString(NumberFormat.TWO_DECIMAL_PLACES).append(" ", unit).toString(); }
private boolean parseModifier() throws ParseException { if (tokenizer.getType() != Tokenizer.IDENTIFIER) { return false; } if (in(start())) { parseStartModifier(); return true; } if (in(end())) { parseEndModifier(); return true; } return false; }
/** * Tries to convert the wrapped value to a roman numeral representation * This only works if the wrapped value can be converted to <tt>int</tt> and is >0 and <4000. * * @param defaultValue the value to be converted to roman numeral if the wrapped value can not be converted * @return a roman numeral representation of either the wrapped value or the defaultValue. values >=4000 and * <=0 are represented as an empty String */ public String asRomanNumeral(int defaultValue) { return RomanNumeral.toRoman(asInt(defaultValue)); }
/** * Returns the <tt>Amount</tt> for the wrapped value. * <p> * If the wrapped value can be converted to a BigDecimal ({@link #getBigDecimal(java.math.BigDecimal)}, * an <tt>Amount</tt> for the result is returned. Otherwise an empty <tt>Amount</tt> is returned. * * @return the wrapped value converted to <tt>Amount</tt>. The result might be an empty amount, if the wrapped * value is <tt>null</tt> or if no conversion was possible. * @see #getBigDecimal(java.math.BigDecimal) */ public Amount getAmount() { return Amount.of(getBigDecimal()); }
private void parseModifiers() throws ParseException { do { tokenizer.nextToken(); // ignore "," between modifiers //noinspection UnnecessaryParentheses,UnnecessaryParentheses if ((tokenizer.getType() == Tokenizer.SPECIAL) && in(MODIFIER_SEPARATOR)) { tokenizer.nextToken(); } } while (parseModifier()); }
/** * Determines if an entity is referenced by this field or not. * <p> * This is not be confused with {@link #isValueLoaded()} which indicates if the value has already been * loaded from the database. * * @return <tt>true</tt> if an entity is referenced, <tt>false</tt> otherwise */ public boolean isFilled() { return Strings.isFilled(id); }
private void parseDeltas(Calendar result) throws ParseException { while (tokenizer.getType() != Tokenizer.END_OF_INPUT) { parseDelta(result, tokenizer); tokenizer.nextToken(); } }
/** * 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(); }
@Override public void onFailure(Throwable throwable) throws Exception { failureHandler.invoke(throwable); } });
@SuppressWarnings("unchecked") @Override public <P> Collection<P> getParts(Class<? extends P> partInterface) { return (Collection<P>) parts.get(partInterface); }
/** * Generates a random password with 7 characters length. * * @return a randomly generated password. */ public static String generatePassword() { return generateCode(7); }
/** * Returns the effective date as string * * @return the effective date formatted as string with time information */ public String getDateTime() { return getDateString(true); } }
/** * Creates a new <tt>ValueHolder</tt> with the given initial value. * <p> * This method can be used instead of a constructor, so that the type parameters don't need to be re-typed. * * @param initialValue sets the value of the value holder * @param <T> the type of the value being held by this <tt>ValueHolder</tt> * @return a new ValueHolder initialized with the given value. */ public static <T> ValueHolder<T> of(T initialValue) { return new ValueHolder<>(initialValue); }
/** * Determines if this amount is greater than the given one. * <p> * See {@link #compareTo(Amount)} for an explanation of how empty amounts are handled. * * @param o the other amount to compare against * @return <tt>true</tt> if this amount is greater than the given one */ public boolean isGreaterThan(Amount o) { return compareTo(o) > 0; }
@Override public String toString() { return toSmartRoundedString(NumberFormat.TWO_DECIMAL_PLACES).toString(); }