2 * © 2008 INA Service GmbH
4 package net.pterodactylus.util.fcp;
6 import java.util.StringTokenizer;
7 import java.util.concurrent.atomic.AtomicLong;
10 * Helper class with utility methods for the FCP protocol.
12 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
15 public class FcpUtils {
17 /** Counter for unique identifiers. */
18 private static AtomicLong counter = new AtomicLong();
21 * Returns a unique identifier.
23 * @return A unique identifier
25 public static String getUniqueIdentifier() {
26 return new StringBuilder().append(System.currentTimeMillis()).append('-').append(counter.getAndIncrement()).toString();
30 * Parses an integer field, separated by ‘;’ and returns the parsed values.
34 * @return An array with the parsed values
35 * @throws NumberFormatException
36 * if a value can not be converted to a number
38 public static int[] parseMultiIntegerField(String field) throws NumberFormatException {
39 StringTokenizer fieldTokens = new StringTokenizer(field, ";");
40 int[] result = new int[fieldTokens.countTokens()];
42 while (fieldTokens.hasMoreTokens()) {
43 String fieldToken = fieldTokens.nextToken();
44 result[counter++] = Integer.valueOf(fieldToken);