Here you can find the source of nextValue(SortedSet
private static int nextValue(SortedSet<Integer> valueSet, int startValue)
//package com.java2s; /************************************************************************************** * Copyright (C) 2008 EsperTech, Inc. All rights reserved. * * http://esper.codehaus.org * * http://www.espertech.com * * ---------------------------------------------------------------------------------- * * The software in this package is published under the terms of the GPL license * * a copy of which has been included with this distribution in the license.txt file. * **************************************************************************************/ import java.util.SortedSet; public class Main { private static int nextValue(SortedSet<Integer> valueSet, int startValue) { if (valueSet == null) { return startValue; }/* ww w .j a va 2 s. c o m*/ if (valueSet.contains(startValue)) { return startValue; } SortedSet<Integer> tailSet = valueSet.tailSet(startValue + 1); if (tailSet.isEmpty()) { return -1; } else { return tailSet.first(); } } }