Java SortedSet Usage nextValue(SortedSet valueSet, int startValue)

Here you can find the source of nextValue(SortedSet valueSet, int startValue)

Description

next Value

License

Open Source License

Declaration

private static int nextValue(SortedSet<Integer> valueSet, int startValue) 

Method Source Code

//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();
        }
    }
}

Related

  1. concatStringList(SortedSet sortedDependencies)
  2. findLT(SortedSet ss, T x)
  3. findPositionFor(final T item, final SortedSet values)
  4. firstOrNull(SortedSet set)
  5. sortedSetIsAssignableFrom(Class aClass)
  6. sortedSetOf(final Object obj, final Class castTo)
  7. toDoubleArray(final int[] intArray)