List of utility methods to do Array Element Get
T | arrayElement(T[] array, int index) Gets the element at an index in the array, but returns null if the index is outside of the array bounds. if (index < 0 || index >= array.length) return null; else return array[index]; |
T | get(int index, final T[]... arrays) get int shift = index; for (T[] tab : arrays) { if (shift < tab.length) { return tab[shift]; } else { shift -= tab.length; return null; |
Object | get(Object[] array, int index) get return getArrayLength(array) > index ? array[index] : null;
|
T | get(T[] array, int index) get return isRange(array, index) ? array[index] : null;
|
T | get(T[] array, int index) Returns the value at the given index in the arrayor null if the index is out of bounds. return index >= 0 && index < array.length ? array[index] : null;
|
T | get(T[] array, int index) get if (array.length < index + 1) { return null; return array[index]; |
ArrayList | getAllMatches(String[] target, String[] pattern) Input: array of strings, and a target array Output: the array of all the appearance ArrayList<Integer> result = new ArrayList<Integer>(); int start = 0; while (start < target.length) { String[] subArray = new String[target.length - start]; for (int iter = 0; iter < subArray.length; iter++) { subArray[iter] = target[iter + start]; int index = getFirst(subArray, pattern); ... |
Map | getArgPairsSeparatedByChar(String[] args, String separator) get Arg Pairs Separated By Char Map<String, String> argPairs = new HashMap<String, String>(); if (args != null) { for (String argPair : args) { String[] pair = argPair.split("="); if (pair.length > 1) { argPairs.put(pair[0], pair[1]); return argPairs; |
String[] | getArgs(final String[] args, final String[] defaultValue, final String... flags) Retrieve multi argument after the given flag and until the next "-*". if (flags == null || flags.length == 0) return null; if (args == null || args.length == 0) return defaultValue; final List<String> r = new ArrayList<String>(); int i = 0; outer: for (; i < args.length; i++) for (final String flag : flags) ... |
Map | getArgs(String[] args, String... singleArgs) Get CLI arguments. Map<String, String[]> params = new HashMap<String, String[]>(); for (int i = 0; i < args.length; i++) { String inArg = args[i]; if (!inArg.startsWith("--")) { throw new Exception("Wrong argument syntax: " + inArg); } else { inArg = inArg.substring(2); for (int j = 0; j < singleArgs.length; j++) { if (singleArgs[j].equals(inArg)) { params.put(inArg, new String[] {}); if (inArg.contains("=")) { String[] keyset = inArg.split("=", 2); if (keyset[1].startsWith("{") && keyset[1].endsWith("}")) { params.put(keyset[0], new String[] { keyset[1].substring(1, keyset[1].length() - 1) }); } else { params.put(keyset[0], keyset[1].split(",")); return params; |