private Property parseProperty(String[] pairs) { if (pairs.length == 0) { return null; } ArrayList<String> wordList = new ArrayList<String>(pairs.length); for (int i = 0; i < pairs.length; i++) { if (!isEmptyString(pairs[i])) { wordList.add(pairs[i]); } } if (wordList.isEmpty()) { return null; } if (wordList.size() == 1) { return new Property(wordList.get(0), true); } if (wordList.size() == 2) { boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc); } String m = "Expecting a max of 2 words in [" + Arrays.toString(pairs) + "] but got " + wordList.size(); throw new RuntimeException(m); }
private Property parseProperty(String[] pairs) { if (pairs.length == 0) { return null; } ArrayList<String> wordList = new ArrayList<String>(pairs.length); for (int i = 0; i < pairs.length; i++) { if (!isEmptyString(pairs[i])) { wordList.add(pairs[i]); } } if (wordList.isEmpty()) { return null; } if (wordList.size() == 1) { return new Property(wordList.get(0), true); } if (wordList.size() == 2) { boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc); } String m = "Expecting a max of 2 words in [" + Arrays.toString(pairs) + "] but got " + wordList.size(); throw new RuntimeException(m); }
private Property parseProperty(String[] pairs) { if (pairs.length == 0) { return null; } ArrayList<String> wordList = new ArrayList<>(pairs.length); for (String pair : pairs) { if (!isEmptyString(pair)) { wordList.add(pair); } } if (wordList.isEmpty()) { return null; } if (wordList.size() == 1) { return new Property(wordList.get(0), true); } if (wordList.size() == 2) { boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc); } if (wordList.size() == 4) { // nulls high or nulls low as 3rd and 4th boolean asc = isAscending(wordList.get(1)); return new Property(wordList.get(0), asc, wordList.get(2), wordList.get(3)); } String m = "Expecting a 1, 2 or 4 words in [" + Arrays.toString(pairs) + "] but got " + wordList; throw new RuntimeException(m); }