/** * @param defaultValue * the default value. * @return string value or default value if value is null. */ public String stringValue( final String defaultValue ) { final String returnValue = this.stringValue(); if ( returnValue == null ) { return defaultValue; } return returnValue; }
/** * @param key * key to set. * @return new key value initialized with default value. * @throws IllegalArgumentException * if key is blank. */ public KeyValue<T> create( final String key ) throws IllegalArgumentException { return new KeyValue<T>( key, this.defaultValue ); }
/** * @param trueValues * string true values, case is ignored. * @return boolean value, null if value is null. */ public Boolean booleanValue( final List<String> trueValues ) { return this.booleanValue( trueValues, true ); }
/** * @return string representation. */ public String toMultiLineString() { final ToStringBuilder builder = new ToStringBuilder( this, ToStringStyle.MULTI_LINE_STYLE ); for ( KeyValue<?> keyValue : this.entries.values() ) { builder.append( keyValue.getKey(), keyValue.getValue() ); } return builder.toString(); }
/** * @param defaultValue * the default value. * @return double value or default value if value is null or cannot be converted to double. */ public Double doubleValue( final Double defaultValue ) { if ( this.value == null ) { return defaultValue; } try { return this.doubleValue(); } catch ( NumberFormatException e ) { return defaultValue; } }
/** * @param defaultValue * the default value. * @return integer value or default value if value is null or cannot be converted to integer. */ public Integer integerValue( final Integer defaultValue ) { if ( this.value == null ) { return defaultValue; } try { return this.integerValue(); } catch ( NumberFormatException e ) { return defaultValue; } }
/** * @param defaultValue * the default value. * @return long value or default value if value is null or cannot be converted to long. */ public Long longValue( final Long defaultValue ) { if ( this.value == null ) { return defaultValue; } try { return this.longValue(); } catch ( NumberFormatException e ) { return defaultValue; } }
/** * @param defaultValue * the default value. * @return float value or default value if value is null or cannot be converted to float. */ public Float floatValue( final Float defaultValue ) { if ( this.value == null ) { return defaultValue; } try { return this.floatValue(); } catch ( NumberFormatException e ) { return defaultValue; } }
/** * @return values. */ public List<Object> values() { final List<Object> result = new ArrayList<Object>(); for ( KeyValue<?> keyValue : this.entries.values() ) { result.add( keyValue.getValue() ); } return result; }
/** * Add key value(s). * * @param keyValues * key values to add. * @return this. */ public KeyValueSet add( final KeyValue<?>... keyValues ) { for ( KeyValue<?> keyValue : keyValues ) { if ( this.entries.containsKey( keyValue.getKey() ) ) { throw new IllegalArgumentException( "Key already added [key=" + keyValue.getKey() + "]" ); } this.entries.put( keyValue.getKey(), keyValue ); } return this; }
/** * Constructor. Key will be converted to lower case. * * @param key * key to set. * @param value * value to set, may be null. * @throws IllegalArgumentException * if key is invalid. */ public KeyValue( final String key, final T value ) throws IllegalArgumentException { final String keyToSet = StringUtils.lowerCase( key ); assertKey( keyToSet ); this.key = keyToSet; this.value = value; }
/** * @param defaultValue * the default value. * @return string value or default value if value is blank. */ public String stringValueDefaultIfBlank( final String defaultValue ) { final String returnValue = this.stringValue(); if ( StringUtils.isBlank( returnValue ) ) { return defaultValue; } return returnValue; }
/** * Uses DEFAULT_TRUE_VALUES, ignore case. * * @return boolean value or null if value is null. */ public Boolean booleanValue() { return this.booleanValue( DEFAULT_TRUE_VALUES, true ); }
/** * @param trueValues * string true values. * @param ignoreCase * ignore case? * @return boolean value, null if value is null. */ public Boolean booleanValue( final List<String> trueValues, final boolean ignoreCase ) { if ( this.value == null ) { return null; } if ( this.value instanceof Boolean ) { return (Boolean) this.value; } final String stringValue = this.stringValue(); if ( ignoreCase ) { return trueValues.contains( StringUtils.lowerCase( stringValue ) ); } return trueValues.contains( stringValue ); }
/** * @param defaultValue * the default value * @return boolean value or default value if value is null. */ public Boolean booleanValue( final Boolean defaultValue ) { final Boolean returnValue = this.booleanValue(); if ( returnValue == null ) { return defaultValue; } return returnValue; }
/** * @param property * property. * @param textVar * text varibale. */ public static void setTextIfPropertyValue( final PluginProperty property, final TextVar textVar ) { if ( property.evaluate() ) { textVar.setText( ( (KeyValue<?>) property ).stringValue() ); } }
/** * @param trueValues * string true values, case is ignored. * @return boolean value, null if value is null. */ public Boolean booleanValue( final String... trueValues ) { return this.booleanValue( Arrays.asList( trueValues ) ); }
/** * @param property * property. * @param combo * text variable. */ public static void setTextIfPropertyValue( final PluginProperty property, final CCombo combo ) { if ( property.evaluate() ) { combo.setText( ( (KeyValue<?>) property ).stringValue() ); } }