/**
* Check if the setting is set into this {@link Bundle}.
*
- * @param id
+ * @param name
* the id of the setting to check
* @param includeDefaultValue
* TRUE to only return false when the setting is not set AND
setString(id.name(), value);
} else {
List<String> values = getList(id);
- for (int i = values.size(); i < item; i++) {
- values.add(null);
- }
- values.set(item, value);
- setString(id.name(), BundleHelper.fromList(values));
+ setString(id.name(), BundleHelper.fromList(values, value, item));
}
}
* the id of the value to get
* @param suffix
* the runtime suffix
- * @param item
- * the item number to get for an array of values, or -1 for
- * non-arrays
* @param def
* the default value when it is not present in the config file
* @param item
* @param def
* the default value when it is not present in the config file or
* if it is not a char value
+ * @param item
+ * the item number to get for an array of values, or -1 for
+ * non-arrays
*
* @return the associated value
*/
*
* @param id
* the id of the value to get
+ * @param def
+ * the default value when it is not present in the config file or
+ * if it is not a char value
*
* @return the associated value
*/
*
* @param id
* the id of the value to get
+ * @param def
+ * the default value when it is not present in the config file or
+ * if it is not a char value
+ * @param item
+ * the item number to get for an array of values, or -1 for
+ * non-arrays
*
* @return the associated value
*/
*
* @param id
* the id of the value to get
+ * @param def
+ * the default value when it is not present in the config file or
+ * if it is not a char value
*
* @return the associated list, empty if the value is empty, NULL if it is
* not found or cannot be parsed as a list
*
* @param id
* the id of the value to get
+ * @param def
+ * the default value when it is not present in the config file or
+ * if it is not a char value
+ * @param item
+ * the item number to get for an array of values, or -1 for
+ * non-arrays
*
* @return the associated list, empty if the value is empty, NULL if it is
* not found or cannot be parsed as a list
}
/**
- * The size of this raw list.
+ * The size of this raw list (note than a NULL list is of size 0).
*
* @param raw
* the raw list
*
- * @return its size if it is a list, -1 if not
+ * @return its size if it is a list (NULL is an empty list), -1 if it is not
+ * a list
*/
static public int getListSize(String raw) {
+ if (raw == null) {
+ return 0;
+ }
+
List<String> list = parseList(raw, -1);
if (list == null) {
return -1;
/**
* Return a {@link String} representation of the given list of values.
* <p>
- * NULL will be assimilated to an empty {@link String}.
+ * NULL will be assimilated to an empty {@link String} if later non-null
+ * values exist, or just ignored if not.
+ * <p>
+ * Example:
+ * <ul>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>3</tt> will become <tt>1</tt>,
+ * <tt>""</tt>, <tt>3</tt></li>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>NULL</tt> will become <tt>1</tt></li>
+ * <li><tt>NULL</tt>, <tt>NULL</tt>, <tt>NULL</tt> will become an empty list
+ * </li>
+ * </ul>
*
* @param list
* the input value
* @return the raw {@link String} value that correspond to it
*/
static public String fromList(List<String> list) {
+ if (list == null) {
+ list = new ArrayList<String>();
+ }
+
+ int last = list.size() - 1;
+ for (int i = 0; i < list.size(); i++) {
+ if (list.get(i) != null) {
+ last = i;
+ }
+ }
+
StringBuilder builder = new StringBuilder();
- for (String item : list) {
+ for (int i = 0; i <= last; i++) {
+ String item = list.get(i);
+ if (item == null) {
+ item = "";
+ }
+
if (builder.length() > 0) {
builder.append(", ");
}
- builder.append(escape(item == null ? "" : item));
+ builder.append(escape(item));
}
return builder.toString();
}
+ /**
+ * Return a {@link String} representation of the given list of values.
+ * <p>
+ * NULL will be assimilated to an empty {@link String} if later non-null
+ * values exist, or just ignored if not.
+ * <p>
+ * Example:
+ * <ul>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>3</tt> will become <tt>1</tt>,
+ * <tt>""</tt>, <tt>3</tt></li>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>NULL</tt> will become <tt>1</tt></li>
+ * <li><tt>NULL</tt>, <tt>NULL</tt>, <tt>NULL</tt> will become an empty list
+ * </li>
+ * </ul>
+ *
+ * @param list
+ * the input value
+ * @param value
+ * the value to insert
+ * @param item
+ * the position to insert it at
+ *
+ * @return the raw {@link String} value that correspond to it
+ */
+ static public String fromList(List<String> list, String value, int item) {
+ if (list == null) {
+ list = new ArrayList<String>();
+ }
+
+ while (item >= list.size()) {
+ list.add(null);
+ }
+ list.set(item, value);
+
+ return fromList(list);
+ }
+
+ /**
+ * Return a {@link String} representation of the given list of values.
+ * <p>
+ * NULL will be assimilated to an empty {@link String} if later non-null
+ * values exist, or just ignored if not.
+ * <p>
+ * Example:
+ * <ul>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>3</tt> will become <tt>1</tt>,
+ * <tt>""</tt>, <tt>3</tt></li>
+ * <li><tt>1</tt>,<tt>NULL</tt>, <tt>NULL</tt> will become <tt>1</tt></li>
+ * <li><tt>NULL</tt>, <tt>NULL</tt>, <tt>NULL</tt> will become an empty list
+ * </li>
+ * </ul>
+ *
+ * @param list
+ * the input value
+ * @param value
+ * the value to insert
+ * @param item
+ * the position to insert it at
+ *
+ * @return the raw {@link String} value that correspond to it
+ */
+ static public String fromList(String list, String value, int item) {
+ return fromList(parseList(list, -1), value, item);
+ }
+
/**
* Escape the given value for list formating (no carets, no NEWLINES...).
* <p>
*/
public void setString(String value, int item) {
if (isArray() && item >= 0) {
- List<String> values = BundleHelper.parseList(this.value, -1);
- for (int i = values.size(); i <= item; i++) {
- values.add(null);
- }
- values.set(item, value);
- this.value = BundleHelper.fromList(values);
+ this.value = BundleHelper.fromList(this.value, value, item);
} else {
this.value = value;
}
value = null;
}
- for (Runnable listener : reloadedListeners) {
+ // Copy the list so we can create new listener in a listener
+ for (Runnable listener : new ArrayList<Runnable>(reloadedListeners)) {
try {
listener.run();
} catch (Exception e) {
* dirty flag)
*/
public void save(boolean onlyIfDirty) {
- for (Runnable listener : saveListeners) {
+ // Copy the list so we can create new listener in a listener
+ for (Runnable listener : new ArrayList<Runnable>(saveListeners)) {
try {
listener.run();
} catch (Exception e) {