/* * Copyright 2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package rife.bld.extension.propertyFile; /** *

Declares the edits to be made to a {@link java.util.Properties Properties} file.

* *

The rules used when setting a {@link java.util.Properties property} value are:

* * * *

{@link Operations Operations} occur after the rules are evaluated.

* * @author Erik C. Thauvin * @since 1.0 */ public class Entry { private String key; private String value; private String defaultValue; private Types type = Types.STRING; private Operations operation = Operations.SET; private String pattern = ""; private Units unit = Units.DAY; /** * Creates a new {@link Entry entry} Entry. * * @param key the required property key */ public Entry(String key) { this.key = key; } /** * Returns the name of the {@link java.util.Properties property} name/value pair. */ public String getKey() { return key; } /** * Sets the name of the {@link java.util.Properties property} name/value pair. * * @param key the {@link java.util.Properties property} key */ public void setKey(String key) { this.key = key; } /** * Returns the value of the {@link java.util.Properties property}. */ public String getValue() { return value; } /** * Sets the value of the {@link java.util.Properties property}. * * @param value the {@link java.util.Properties property} value */ public void setValue(String value) { this.value = value; } /** * Returns the default value. */ public String getDefaultValue() { return defaultValue; } /** *

Sets the initial value to set for the {@link java.util.Properties property} if not already defined.

* *

The {@code now} keyword can be used for {@link Types#DATE Types.DATE}

* * @param defaultValue the default value */ public void setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; } /** * Return the value {@link Types Type}/ */ public Types getType() { return type; } /** * Sets the value {@link Types Type}, if none is specified {@link Types#STRING Types.STRING} is assumed. * * @param type the value {@link Types Type} */ public void setType(Types type) { this.type = type; } /** * Return the {@link Operations Operation}. */ public Operations getOperation() { return operation; } /** * Sets the {@link Operations Operation} to be performed on the {@link java.util.Properties property} value, * * @param operation the entry {@link Operations Operation} */ public void setOperation(Operations operation) { this.operation = operation; } /** * Returns the pattern. */ public String getPattern() { return pattern; } /** *

Parses the value of {@link Types#INT Types.INT} and {@link Types#DATE Types.DATE} to * {@link java.text.DecimalFormat DecimalFormat} and {@link java.text.SimpleDateFormat SimpleDateFormat} * respectively.

* * @param pattern the pattern */ public void setPattern(String pattern) { this.pattern = pattern; } /** * Return the {@link Units unit}. */ public Units getUnit() { return unit; } /** * Sets the {@link Units unit} value to apply to {@link Operations#ADD Operations.ADD} * and {@link Operations#SUBTRACT Operations.SUBTRACT} for {@link Types#DATE Types.DATE}. * * @param unit the {@link Units unit} */ public void setUnit(Units unit) { this.unit = unit; } /** * Sets the name of the {@link java.util.Properties property} name/value pair. * * @param key the {@link java.util.Properties property} key */ public Entry key(String key) { setKey(key); return this; } /** * Sets the value of the {@link java.util.Properties property}. * * @param value the {@link java.util.Properties property} value */ public Entry value(Object value) { if (value != null) { setValue(String.valueOf(value)); } else { setValue(null); } return this; } /** *

Sets the initial value to set for the {@link java.util.Properties property} if not already defined.

* *

The {@code now} keyword can be used for {@link Types#DATE Types.DATE}

* * @param defaultValue the default value */ public Entry defaultValue(Object defaultValue) { if (defaultValue != null) { setDefaultValue(String.valueOf(defaultValue)); } else { setDefaultValue(null); } return this; } /** * Sets the value {@link Types Type}, if none is specified {@link Types#STRING Types.STRING} is assumed. * * @param type the value {@link Types Type} */ public Entry type(Types type) { setType(type); return this; } /** * Sets the {@link Operations Operation} to be performed on the {@link java.util.Properties property} value, * * @param operation the entry {@link Operations Operation} */ public Entry operation(Operations operation) { setOperation(operation); return this; } /** *

Parses the value of {@link Types#INT Types.INT} and {@link Types#DATE Types.DATE} to * {@link java.text.DecimalFormat DecimalFormat} and {@link java.text.SimpleDateFormat SimpleDateFormat} * respectively.

* * @param pattern the pattern */ public Entry pattern(String pattern) { setPattern(pattern); return this; } /** * Sets the {@link Units unit} value to apply to {@link Operations#ADD Operations.ADD} * and {@link Operations#SUBTRACT Operations.SUBTRACT} for {@link Types#DATE Types.DATE}. * * @param unit the {@link Units unit} */ public Entry unit(Units unit) { setUnit(unit); return this; } /** * The available datatypes. * * */ public enum Types { DATE, INT, STRING } /** * The operations available for all {@link Types Types}. * * */ public enum Operations { ADD, DELETE, SET, SUBTRACT } /** * The units available for {@link Types#DATE Type.DATE} with {@link Operations#ADD Operations>ADD} * and {@link Operations#SUBTRACT Operations.SUBTRACT}. * * */ public enum Units { MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } }