*/
package net.pterodactylus.util.fcp;
+import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicLong;
/**
return new StringBuilder().append(System.currentTimeMillis()).append('-').append(counter.getAndIncrement()).toString();
}
+ /**
+ * Parses an integer field, separated by ‘;’ and returns the parsed values.
+ *
+ * @param field
+ * The field to parse
+ * @return An array with the parsed values
+ * @throws NumberFormatException
+ * if a value can not be converted to a number
+ */
+ public static int[] decodeMultiIntegerField(String field) throws NumberFormatException {
+ StringTokenizer fieldTokens = new StringTokenizer(field, ";");
+ int[] result = new int[fieldTokens.countTokens()];
+ int counter = 0;
+ while (fieldTokens.hasMoreTokens()) {
+ String fieldToken = fieldTokens.nextToken();
+ result[counter++] = Integer.valueOf(fieldToken);
+ }
+ return result;
+ }
+
+ /**
+ * Encodes the given integer array into a string, separating the values by
+ * ‘;’.
+ *
+ * @param values
+ * The values to encode
+ * @return The encoded values
+ */
+ public static String encodeMultiIntegerField(int[] values) {
+ StringBuilder encodedField = new StringBuilder();
+ for (int value: values) {
+ if (encodedField.length() > 0) {
+ encodedField.append(';');
+ }
+ encodedField.append(value);
+ }
+ return encodedField.toString();
+ }
+
}