modify_;
+
/**
- * Instantiates a new Entry.
+ * Creates a new {@link Entry entry}.
*
- * @param key the key
+ * @param key the required property key
*/
public Entry(String key) {
super(key);
}
/**
- * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
+ * Returns the modify function.
*
- * @param defaultValue the default value
- * @return the entry
+ * @return the modify function
*/
- @SuppressWarnings("unused")
- public Entry defaultValue(Object defaultValue) {
- setDefaultValue(defaultValue);
- return this;
+ protected BiFunction modify() {
+ return modify_;
}
/**
- * Sets the {@link Entry entry} up for deletion.
+ * Sets the modify function.
*
- * @return the entry
- */
- public Entry delete() {
- setDelete();
- return this;
- }
-
- /**
- * Creates a new {@link Entry entry}.
- *
- * @param modify the modification function
- * @return the entry
+ * @param modify the modify function
*/
public Entry modify(BiFunction modify) {
- setModify(modify);
+ modify_ = modify;
return this;
}
/**
- * Creates a new {@link Entry entry}.
+ * Sets the modify function.
*
* @param value the value to perform a modification with
- * @param modify the modification function
- * @return the entry
+ * @param modify the modify function
*/
public Entry modify(String value, BiFunction modify) {
- setModifyValue(value);
- setModify(modify);
+ modifyValue_ = value;
+ modify_ = modify;
return this;
}
+ /**
+ * Returns the value to be used in the {@link #modify_} function.
+ *
+ * @return the modify value
+ */
+ protected String modifyValue() {
+ return modifyValue_;
+ }
+
/**
* Sets the new {@link java.util.Properties property} value.
*
@@ -88,7 +85,7 @@ public class Entry extends EntryBase {
* @return the entry
*/
public Entry set(Object s) {
- setNewValue(s);
+ newValue(s);
return this;
}
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java
index b724ed3..ca193b1 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryBase.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryBase.java
@@ -16,7 +16,6 @@
package rife.bld.extension.propertyfile;
-import java.util.function.BiFunction;
import java.util.function.IntFunction;
/**
@@ -26,17 +25,14 @@ import java.util.function.IntFunction;
* @author Geert Bevin
* @since 1.0
*/
-@SuppressWarnings("PMD.DataClass")
-public class EntryBase {
+@SuppressWarnings({"unchecked", "PMD.AbstractClassWithoutAbstractMethod"})
+public abstract class EntryBase {
private IntFunction calc_;
private Object defaultValue_;
private boolean isDelete_;
private String key_;
- private String modifyValue_ = "";
- private BiFunction modify_;
private Object newValue_;
- private String pattern_ = "";
- private EntryDate.Units unit_ = EntryDate.Units.DAY;
+ private Object pattern_;
/**
* Creates a new {@link EntryBase entry}.
@@ -52,71 +48,45 @@ public class EntryBase {
*
* @return the calc function
*/
- protected IntFunction getCalc() {
+ protected IntFunction calc() {
return calc_;
}
+ /**
+ * Sets the calculation function.
+ *
+ * @param calc the calc function
+ */
+ public T calc(IntFunction calc) {
+ calc_ = calc;
+ return (T) this;
+ }
+
/**
* Returns the default value.
*
* @return the default value
*/
- protected Object getDefaultValue() {
+ protected Object defaultValue() {
return defaultValue_;
}
/**
- * Returns the key of the {@link java.util.Properties property}.
+ * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
*
- * @return the key
+ * @param defaultValue the default value
*/
- protected String getKey() {
- return key_;
+ public T defaultValue(Object defaultValue) {
+ defaultValue_ = defaultValue;
+ return (T) this;
}
/**
- * Returns the modify function.
- *
- * @return the modify function
+ * Indicates that the {@link java.util.Properties property} is to be deleted.
*/
- protected BiFunction getModify() {
- return modify_;
- }
-
- /**
- * Returns the value to be used in the {@link #modify_} function.
- *
- * @return the modify value
- */
- protected String getModifyValue() {
- return modifyValue_;
- }
-
- /**
- * Returns the new value to set the {@link java.util.Properties property)} to.
- *
- * @return the new value
- */
- public Object getNewValue() {
- return newValue_;
- }
-
- /**
- * Returns the pattern.
- *
- * @return the pattern
- */
- protected String getPattern() {
- return pattern_;
- }
-
- /**
- * Returns the {@link EntryDate.Units unit}.
- *
- * @return the unit
- */
- protected EntryDate.Units getUnit() {
- return unit_;
+ public T delete() {
+ isDelete_ = true;
+ return (T) this;
}
/**
@@ -128,79 +98,33 @@ public class EntryBase {
return isDelete_;
}
+ /**
+ * Returns the key of the {@link java.util.Properties property}.
+ *
+ * @return the key
+ */
+ protected String key() {
+ return key_;
+ }
+
/**
* Sets the key of the {@link java.util.Properties property}.
*
* @param key the {@link java.util.Properties property} key
* @return this instance
*/
- @SuppressWarnings("unused")
- public EntryBase key(String key) {
+ public T key(String key) {
key_ = key;
- return this;
+ return (T) this;
}
/**
- * Sets the calculation function.
+ * Returns the new value to set the {@link java.util.Properties property)} to.
*
- * @param calc the calc function
+ * @return the new value
*/
- protected void setCalc(IntFunction calc) {
- calc_ = calc;
- }
-
- /**
- * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
- *
- * @param defaultValue the default value
- */
- protected void setDefaultValue(Object defaultValue) {
- defaultValue_ = defaultValue;
- }
-
- /**
- * Sets the {@link java.util.Properties property} to be deleted.
- */
- protected void setDelete() {
- isDelete_ = true;
- }
-
- /**
- * Sets the key of the {@link java.util.Properties property}.
- *
- * @param key the {@link java.util.Properties property} key
- */
- protected void setKey(String key) {
- key_ = key;
- }
-
- /**
- * Sets the modify function.
- *
- * @param modify the modify function
- */
- protected void setModify(BiFunction modify) {
- modify_ = modify;
- }
-
- /**
- * Sets the modify function.
- *
- * @param value the value to perform a modification with
- * @param modify the modify function
- */
- protected void setModify(String value, BiFunction modify) {
- modifyValue_ = value;
- modify_ = modify;
- }
-
- /**
- * Sets the modify value.
- *
- * @param value the modify value.
- */
- protected void setModifyValue(String value) {
- modifyValue_ = value;
+ protected Object newValue() {
+ return newValue_;
}
/**
@@ -208,26 +132,26 @@ public class EntryBase {
*
* @param newValue the new value
*/
- public void setNewValue(Object newValue) {
+ protected void newValue(Object newValue) {
newValue_ = newValue;
}
/**
- * Sets the {@link java.text.DecimalFormat DecimalFormat} or {@link java.time.format.DateTimeFormatter DateTimeFormatter}
- * pattern to be used with {@link EntryDate} or {@link EntryInt} respectively.
+ * Returns the pattern.
*
- * @param pattern the pattern
+ * @return the pattern
*/
- protected void setPattern(String pattern) {
- pattern_ = pattern;
+ protected Object pattern() {
+ return pattern_;
}
/**
- * Sets the {@link EntryDate.Units unit} value to apply to calculations.
+ * Sets the {@link java.util.Formatter} pattern.
*
- * @param unit the {@link EntryDate.Units unit}
+ * @param pattern the pattern
*/
- protected void setUnit(EntryDate.Units unit) {
- unit_ = unit;
+ public T pattern(Object pattern) {
+ pattern_ = pattern;
+ return (T) this;
}
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
index a25b0e1..0a93745 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryDate.java
@@ -19,7 +19,6 @@ package rife.bld.extension.propertyfile;
import java.time.*;
import java.util.Calendar;
import java.util.Date;
-import java.util.function.IntFunction;
/**
* Declares the modifications to be made to a {@link java.util.Properties Date-based property}.
@@ -27,9 +26,11 @@ import java.util.function.IntFunction;
* @author Erik C. Thauvin
* @since 1.0
*/
-public class EntryDate extends EntryBase {
+public class EntryDate extends EntryBase {
+ private EntryDate.Units unit_ = EntryDate.Units.DAY;
+
/**
- * Creates a new date {@link Entry entry}.
+ * Creates a new {@link EntryDate entry}.
*
* @param key the required property key
*/
@@ -37,46 +38,13 @@ public class EntryDate extends EntryBase {
super(key);
}
- /**
- * Creates a new {@link EntryDate entry}.
- *
- * @param calc the calculation function
- * @return this instance
- */
- public EntryDate calc(IntFunction calc) {
- setCalc(calc);
- return this;
- }
-
- /**
- * Sets the {@link EntryDate entry} up for deletion.
- *
- * @return this instance
- */
- public EntryDate delete() {
- setDelete();
- return this;
- }
-
/**
* Sets the new {@link java.util.Properties property} value to now.
*
* @return this instance
*/
public EntryDate now() {
- setNewValue("now");
- return this;
- }
-
- /**
- * Sets the pattern for {@link EntryInt} and {@link EntryDate} to{@link java.text.DecimalFormat DecimalFormat} and
- * {@link java.time.format.DateTimeFormatter DateTimeFormatter} respectively.
- *
- * @param pattern the pattern
- * @return this instance
- */
- public EntryDate pattern(String pattern) {
- setPattern(pattern);
+ newValue("now");
return this;
}
@@ -87,7 +55,7 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(Instant instant) {
- setNewValue(instant);
+ newValue(instant);
return this;
}
@@ -98,7 +66,7 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(LocalDate date) {
- setNewValue(date);
+ newValue(date);
return this;
}
@@ -109,7 +77,7 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(LocalDateTime date) {
- setNewValue(date);
+ newValue(date);
return this;
}
@@ -120,7 +88,7 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(ZonedDateTime date) {
- setNewValue(date);
+ newValue(date);
return this;
}
@@ -131,7 +99,7 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(LocalTime time) {
- setNewValue(time);
+ newValue(time);
return this;
}
@@ -142,7 +110,7 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(Calendar cal) {
- setNewValue(cal);
+ newValue(cal);
return this;
}
@@ -153,10 +121,19 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate set(Date date) {
- setNewValue(date);
+ newValue(date);
return this;
}
+ /**
+ * Returns the {@link EntryDate.Units unit}.
+ *
+ * @return the unit
+ */
+ public EntryDate.Units unit() {
+ return unit_;
+ }
+
/**
* Sets the {@link Units unit} value to apply to calculations for {@link EntryDate}.
*
@@ -164,7 +141,17 @@ public class EntryDate extends EntryBase {
* @return this instance
*/
public EntryDate unit(Units unit) {
- setUnit(unit);
+ unit_ = unit;
+ return this;
+ }
+
+ /**
+ * Sets the {@link java.time.format.DateTimeFormatter DateTimeFormatter} pattern.
+ *
+ * @param pattern the pattern
+ */
+ public EntryDate pattern(String pattern) {
+ super.pattern(pattern);
return this;
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java
index 54226f4..896bbf1 100644
--- a/src/main/java/rife/bld/extension/propertyfile/EntryInt.java
+++ b/src/main/java/rife/bld/extension/propertyfile/EntryInt.java
@@ -16,17 +16,15 @@
package rife.bld.extension.propertyfile;
-import java.util.function.IntFunction;
-
/**
* Declares the modifications to be made to an {@link java.util.Properties Integer-based property}.
*
* @author Erik C. Thauvin
* @since 1.0
*/
-public class EntryInt extends EntryBase {
+public class EntryInt extends EntryBase {
/**
- * Creates a new date {@link Entry entry}.
+ * Creates a new {@link EntryInt entry}.
*
* @param key the required property key
*/
@@ -34,39 +32,6 @@ public class EntryInt extends EntryBase {
super(key);
}
- /**
- * Creates a new {@link EntryInt entry}.
- *
- * @param calc the calculation function.
- * @return this instance
- */
- public EntryInt calc(IntFunction calc) {
- setCalc(calc);
- return this;
- }
-
- /**
- * Sets the initial value to set the {@link java.util.Properties property} to, if not already defined.
- *
- * @param defaultValue the default value
- * @return this instance
- */
- @SuppressWarnings("unused")
- public EntryInt defaultValue(Object defaultValue) {
- setDefaultValue(defaultValue);
- return this;
- }
-
- /**
- * Sets the {@link EntryInt entry} up for deletion.
- *
- * @return this instance
- */
- public EntryInt delete() {
- setDelete();
- return this;
- }
-
/**
* Sets the new {@link java.util.Properties property} value to an integer.
*
@@ -74,7 +39,17 @@ public class EntryInt extends EntryBase {
* @return this instance
*/
public EntryInt set(int i) {
- setNewValue(i);
+ newValue(i);
+ return this;
+ }
+
+ /**
+ * Sets the {@link java.text.DecimalFormat DecimalFormat} pattern.
+ *
+ * @param pattern the pattern
+ */
+ public EntryInt pattern(String pattern) {
+ super.pattern(pattern);
return this;
}
}
diff --git a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java
index 0ecf5d7..c86204e 100644
--- a/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java
+++ b/src/main/java/rife/bld/extension/propertyfile/PropertyFileOperation.java
@@ -18,11 +18,14 @@ package rife.bld.extension.propertyfile;
import rife.bld.BaseProject;
import rife.bld.operations.AbstractOperation;
+import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* Creates or applies edits to a {@link Properties Properties} file.
@@ -31,7 +34,8 @@ import java.util.Properties;
* @since 1.0
*/
public class PropertyFileOperation extends AbstractOperation {
- private final List entries_ = new ArrayList<>();
+ private final static Logger LOGGER = Logger.getLogger(PropertyFileOperation.class.getName());
+ private final List> entries_ = new ArrayList<>();
private String comment_ = "";
private boolean failOnWarning_;
private File file_;
@@ -55,8 +59,7 @@ public class PropertyFileOperation extends AbstractOperation entry) {
entries_.add(entry);
return this;
}
@@ -66,38 +69,49 @@ public class PropertyFileOperation extends AbstractOperation