/** * Compare the two conditions based on the URL patterns they contain. * Patterns are compared one at a time, from top to bottom. If all compared * patterns match equally, but one instance has more patterns, it is * considered a closer match. * <p>It is assumed that both instances have been obtained via * {@link #getMatchingCondition(ServerWebExchange)} to ensure they * contain only patterns that match the request and are sorted with * the best matches on top. */ @Override public int compareTo(PatternsRequestCondition other, ServerWebExchange exchange) { Iterator<PathPattern> iterator = this.patterns.iterator(); Iterator<PathPattern> iteratorOther = other.getPatterns().iterator(); while (iterator.hasNext() && iteratorOther.hasNext()) { int result = PathPattern.SPECIFICITY_COMPARATOR.compare(iterator.next(), iteratorOther.next()); if (result != 0) { return result; } } if (iterator.hasNext()) { return -1; } else if (iteratorOther.hasNext()) { return 1; } else { return 0; } }
public static ArrayList<Range<Integer>> buildRanges(SortedSet<Integer> values) { ArrayList<Range<Integer>> ranges = Lists.newArrayList(); if (values == null || values.isEmpty()) return ranges; Iterator<Integer> iter = values.iterator(); int lastBegin = iter.next(); int lastEnd = lastBegin; int temp = 0; for (int index = 1; index < values.size(); index++) { temp = iter.next(); if (temp - lastEnd != 1) { ranges.add(Range.closed(lastBegin, lastEnd)); lastBegin = temp; } lastEnd = temp; } ranges.add(Range.closed(lastBegin, lastEnd)); return ranges; } }
/** * A sensible definition of {@link #remove} in terms of the {@code iterator()} method of {@link * #tailSet}. If you override {@link #tailSet}, you may wish to override {@link #remove} to * forward to this implementation. * * @since 7.0 */ @Override @Beta protected boolean standardRemove(@Nullable Object object) { try { // any ClassCastExceptions are caught @SuppressWarnings("unchecked") SortedSet<Object> self = (SortedSet<Object>) this; Iterator<Object> iterator = self.tailSet(object).iterator(); if (iterator.hasNext()) { Object ceiling = iterator.next(); if (unsafeCompare(ceiling, object) == 0) { iterator.remove(); return true; } } } catch (ClassCastException | NullPointerException e) { return false; } return false; }
/** * Constructs a new instance of {@code TreeSet} containing the elements of * the specified SortedSet and using the same Comparator. * * @param set * the SortedSet of elements to add. */ public TreeSet(SortedSet<E> set) { this(set.comparator()); Iterator<E> it = set.iterator(); while (it.hasNext()) { add(it.next()); } }
@Test public void testCurrentStateOfEntity1() { final SortedSetEntity entity1 = getEntityManager().find( SortedSetEntity.class, 1 ); assertEquals( "sortedEntity1", entity1.getData() ); assertEquals( Integer.valueOf( 1 ), entity1.getId() ); final SortedSet<StrTestEntity> sortedSet = entity1.getSortedSet(); assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); assertEquals( 4, sortedSet.size() ); final Iterator<StrTestEntity> iterator = sortedSet.iterator(); checkStrTestEntity( iterator.next(), id2, "aaa" ); checkStrTestEntity( iterator.next(), id4, "aac" ); checkStrTestEntity( iterator.next(), id3, "aba" ); checkStrTestEntity( iterator.next(), id1, "abc" ); final SortedMap<StrTestEntity, String> sortedMap = entity1.getSortedMap(); assertEquals( StrTestEntityComparator.class, sortedMap.comparator().getClass() ); assertEquals( 4, sortedMap.size() ); Iterator<Map.Entry<StrTestEntity, String>> mapIterator = sortedMap.entrySet().iterator(); checkStrTestEntity( mapIterator.next().getKey(), id2, "aaa" ); checkStrTestEntity( mapIterator.next().getKey(), id4, "aac" ); checkStrTestEntity( mapIterator.next().getKey(), id3, "aba" ); checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); mapIterator = sortedMap.entrySet().iterator(); assertEquals( mapIterator.next().getValue(), "aaa" ); assertEquals( mapIterator.next().getValue(), "aac" ); assertEquals( mapIterator.next().getValue(), "aba" ); assertEquals( mapIterator.next().getValue(), "abc" ); }
/** * @param args * args */ public static void main(String[] args) { // TODO Auto-generated method stub Properties p = System.getProperties(); SortedSet keys = new TreeSet(p.keySet()); for (Iterator it = keys.iterator(); it.hasNext();) { String key = (String) it.next(); System.out.println(key + " = " + p.getProperty(key)); } }
/** * Tests IO exception, that can occur during reading of properties file. */ @Test public void testIoException() throws Exception { final DefaultConfiguration checkConfig = createModuleConfig(UniquePropertiesCheck.class); final UniquePropertiesCheck check = new UniquePropertiesCheck(); check.configure(checkConfig); final String fileName = getPath("InputUniquePropertiesCheckNotExisting.properties"); final File file = new File(fileName); final FileText fileText = new FileText(file, Collections.emptyList()); final SortedSet<LocalizedMessage> messages = check.process(file, fileText); assertEquals("Wrong messages count: " + messages.size(), 1, messages.size()); final LocalizedMessage message = messages.iterator().next(); final String retrievedMessage = messages.iterator().next().getKey(); assertEquals("Message key '" + retrievedMessage + "' is not valid", "unable.open.cause", retrievedMessage); assertEquals("Message '" + message.getMessage() + "' is not valid", message.getMessage(), getCheckMessage(MSG_IO_EXCEPTION_KEY, fileName, getFileNotFoundDetail(file))); }
/** * @param args * args */ public static void main(String[] args) { // TODO Auto-generated method stub Properties p = System.getProperties(); SortedSet keys = new TreeSet(p.keySet()); for (Iterator it = keys.iterator(); it.hasNext();) { String key = (String) it.next(); System.out.println(key + " = " + p.getProperty(key)); } }
assertEquals( 0, sortedSet.size() ); assertEquals( 1, sortedSet.size() ); Iterator<StrTestEntity> iterator = sortedSet.iterator(); checkStrTestEntity( iterator.next(), id1, "abc" ); assertEquals( 1, sortedMap.size() ); Iterator<Map.Entry<StrTestEntity, String>> mapIterator = sortedMap.entrySet().iterator(); checkStrTestEntity( mapIterator.next().getKey(), id1, "abc" ); assertEquals( mapIterator.next().getValue(), "abc" ); assertEquals( 2, sortedSet.size() ); iterator = sortedSet.iterator(); checkStrTestEntity( iterator.next(), id2, "aaa" ); checkStrTestEntity( iterator.next(), id1, "abc" ); assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); assertEquals( 3, sortedSet.size() ); iterator = sortedSet.iterator(); checkStrTestEntity( iterator.next(), id2, "aaa" ); checkStrTestEntity( iterator.next(), id3, "aba" ); assertEquals( StrTestEntityComparator.class, sortedSet.comparator().getClass() ); assertEquals( 4, sortedSet.size() ); iterator = sortedSet.iterator(); checkStrTestEntity( iterator.next(), id2, "aaa" ); checkStrTestEntity( iterator.next(), id4, "aac" );