Example usage for java.util TreeSet higher

List of usage examples for java.util TreeSet higher

Introduction

In this page you can find the example usage for java.util TreeSet higher.

Prototype

public E higher(E e) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {

    TreeSet<Integer> treeadd = new TreeSet<Integer>();

    treeadd.add(12);//from ww  w.  java  2 s.  co m
    treeadd.add(11);
    treeadd.add(16);
    treeadd.add(15);

    // getting the higher value for 13
    System.out.println("Higher value of 13: " + treeadd.higher(13));
}

From source file:Main.java

public static void main(String args[]) {
    Set<String> hs = new HashSet<String>();

    hs.add("one");
    hs.add("two");
    hs.add("three");

    System.out.println("Here is the HashSet: " + hs);

    if (!hs.add("three"))
        System.out.println("Attempt to add duplicate. " + "Set is unchanged: " + hs);

    TreeSet<Integer> ts = new TreeSet<Integer>();

    ts.add(8);/* w  w w .  j a  v a  2s  . c o m*/
    ts.add(19);
    ts.add(-2);
    ts.add(3);

    System.out.println(ts);

    System.out.println("First element in ts: " + ts.first());
    System.out.println("Last element in ts: " + ts.last());

    System.out.println("First element > 15: " + ts.higher(15));
    System.out.println("First element < 15: " + ts.lower(15));
}

From source file:md.MangaDownloader.java

public static String automaticVolumeName(List<MangaChaptersInfo> selectedChapters) {
    TreeSet<Integer> chapterNumbers = new TreeSet<Integer>();
    String alternative = "";
    for (MangaChaptersInfo m : selectedChapters) {
        try {//from   w ww. jav a2  s .  c o  m
            if (!m.chapterNumber.equals("")) {
                int test = Integer.parseInt(m.chapterNumber);
                chapterNumbers.add(test);
            }
        } catch (NumberFormatException e) {
            //If more than one alternative chapter name then all renamed to "Extras"
            if (alternative.equals("")) {
                alternative = m.chapterNumber;
            } else {
                alternative = STRINGS.getString("NAME_EXTRAS");
            }
        }
    }

    String result = "";
    if (!chapterNumbers.isEmpty()) {
        int firstInSequence = Integer.MIN_VALUE;
        int lastInSequence;

        for (Iterator<Integer> i = chapterNumbers.iterator(); i.hasNext();) {
            int actualNumber = i.next();
            if (firstInSequence == Integer.MIN_VALUE)
                firstInSequence = actualNumber;
            lastInSequence = actualNumber;
            int next;
            if (i.hasNext()) {
                next = chapterNumbers.higher(actualNumber);
            } else {
                next = Integer.MIN_VALUE;
            }
            if ((actualNumber + 1 != next) || (next == Integer.MIN_VALUE)) {
                //FIN DE SECUENCIA
                if (!result.equals("")) {
                    result += ", ";
                }
                if (firstInSequence == lastInSequence) {
                    result += String.format("%04d", firstInSequence);
                } else {
                    result += String.format("%04d - %04d", firstInSequence, lastInSequence);
                }
                firstInSequence = Integer.MIN_VALUE;
            }
        }

    }

    if (!alternative.equals("")) {
        if (!result.equals(""))
            result += " & ";
        result += alternative;
    }

    return result;
}

From source file:com.ichi2.libanki.test.SchedTestCase.java

@MediumTest
public void test_deckDue() throws JSONException {
    Collection d = Shared.getEmptyDeck(getInstrumentation().getContext());
    // add a note with default deck
    Note f = d.newNote();//from ww w.  j  a  v a  2  s .  c o m
    f.setitem("Front", "one");
    d.addNote(f);
    // and one that's a child
    f = d.newNote();
    f.setitem("Front", "two");
    long default1 = 0;
    f.model().put("did", d.getDecks().id("Default::1"));
    default1 = f.model().getLong("did");
    d.addNote(f);
    // make it a review card
    Card c = f.cards().get(0);
    c.setQueue(2);
    c.setDue(0);
    c.flush();
    // add one more with a new deck
    f = d.newNote();
    f.setitem("Front", "two");
    long foobar = 0;
    f.model().put("did", d.getDecks().id("foo::bar"));
    foobar = f.model().getLong("did");
    d.addNote(f);
    // and one that's a sibling
    f = d.newNote();
    f.setitem("Front", "three");
    long foobaz = 0;
    f.model().put("did", d.getDecks().id("foo::baz"));
    foobaz = f.model().getLong("did");
    d.addNote(f);
    d.reset();
    assertEquals(d.getDecks().getDecks().size(), 5);
    List<Object[]> cnts = d.getSched().deckDueList(Sched.DECK_INFORMATION_SIMPLE_COUNTS);
    // DIFFERENT THAN LIBANKI: deckDueList in AnkiDroid returns [deckname, did, new, lrn, rev] 
    assertEquals(cnts.get(0)[0], "Default");
    assertEquals(((Long) cnts.get(0)[1]).longValue(), 1);
    MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(0), 2, 5, Integer[].class)),
            new int[] { 1, 0, 0 });
    assertEquals(cnts.get(1)[0], "Default::1");
    assertEquals(((Long) cnts.get(1)[1]).longValue(), default1);
    MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(1), 2, 5, Integer[].class)),
            new int[] { 0, 0, 1 });
    assertEquals(cnts.get(2)[0], "foo");
    assertEquals(((Long) cnts.get(2)[1]).longValue(), d.getDecks().id("foo"));
    MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(2), 2, 5, Integer[].class)),
            new int[] { 0, 0, 0 });
    assertEquals(cnts.get(3)[0], "foo::bar");
    assertEquals(((Long) cnts.get(3)[1]).longValue(), foobar);
    MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(3), 2, 5, Integer[].class)),
            new int[] { 1, 0, 0 });
    assertEquals(cnts.get(4)[0], "foo::baz");
    assertEquals(((Long) cnts.get(4)[1]).longValue(), foobaz);
    MoreAsserts.assertEquals(Shared.toPrimitiveInt(Arrays.copyOfRange(cnts.get(4), 2, 5, Integer[].class)),
            new int[] { 1, 0, 0 });
    TreeSet<Object[]> tree = d.getSched().deckDueTree(Sched.DECK_INFORMATION_SIMPLE_COUNTS);
    assertEquals(((String[]) tree.first()[0])[0], "Default");
    // sum of child and parent
    assertEquals(((Long) tree.first()[1]).longValue(), 1);
    assertEquals(((Integer) tree.first()[2]).intValue(), 1);
    assertEquals(((Integer) tree.first()[4]).intValue(), 1);
    // child count is just review
    // DIFFERENT THAN LIBANKI
    assertEquals(((String[]) tree.higher(tree.first())[0])[0], "Default");
    assertEquals(((String[]) tree.higher(tree.first())[0])[1], "1");
    assertEquals(((Long) tree.higher(tree.first())[1]).longValue(), default1);
    assertEquals(((Integer) tree.higher(tree.first())[2]).intValue(), 0);
    assertEquals(tree.higher(tree.first())[4], 1);
    // code should not fail if a card has an invalid deck
    c.setDid(12345);
    c.flush();
    d.getSched().deckDueList(Sched.DECK_INFORMATION_SIMPLE_COUNTS);
    d.getSched().deckDueTree(Sched.DECK_INFORMATION_SIMPLE_COUNTS);
}