congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
SortedArrayList
Code IndexAdd Tabnine to your IDE (free)

How to use
SortedArrayList
in
jodd.util.collection

Best Java code snippets using jodd.util.collection.SortedArrayList (Showing top 20 results out of 315)

origin: redisson/redisson

/**
 * Add all of the elements in the given collection to this list.
 */
@Override
public boolean addAll(Collection<? extends E> c) {
  Iterator<? extends E> i = c.iterator();
  boolean changed = false;
  while (i.hasNext()) {
    boolean ret = add(i.next());
    if (!changed) {
      changed = ret;
    }
  }
  return changed;
}
origin: redisson/redisson

/**
 * Conducts a binary search to find the index where Object
 * should be inserted.
 */
protected int findInsertionPoint(E o, int low, int high) {
  while (low <= high) {
    int mid = (low + high) >>> 1;
    int delta = compare(get(mid), o);
    if (delta > 0) {
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return low;
}
origin: redisson/redisson

/**
 * Finds the index at which object should be inserted.
 */
public int findInsertionPoint(E o) {
  return findInsertionPoint(o, 0, size() - 1);
}
origin: redisson/redisson

/**
 * Adds an Object to sorted list. Object is inserted at correct place, found
 * using binary search. If the same item exist, it will be put to the end of
 * the range.
 * <p>
 * This method breaks original list contract since objects are not
 * added at the list end, but in sorted manner.
 */
@Override
public boolean add(E o) {
  int idx = 0;
  if (!isEmpty()) {
    idx = findInsertionPoint(o);
  }
  super.add(idx, o);
  return true;
}
origin: oblac/jodd

@Test
void testList2() {
  SortedArrayList<String> list = new SortedArrayList<>();
  list.add("bbb");
  list.add("aaa");
  assertEquals(2, list.size());
  assertEquals("aaa", list.get(0));
  assertEquals("bbb", list.get(1));
  list.add("aa");
  assertEquals(3, list.size());
  assertEquals("aa", list.get(0));
  list.add("a");
  assertEquals(4, list.size());
  assertEquals("a", list.get(0));
  assertEquals(1, list.findInsertionPoint("a"));
}
origin: oblac/jodd

@Test
void testList1() {
  SortedArrayList<String> list = new SortedArrayList<>();
  list.add("aaa");
  list.add("bbb");
  assertEquals(2, list.size());
  assertEquals("aaa", list.get(0));
  assertEquals("bbb", list.get(1));
  list.add("ccc");
  assertEquals(3, list.size());
  assertEquals("ccc", list.get(2));
  list.add("cc");
  assertEquals(4, list.size());
  assertEquals("cc", list.get(2));
    list.add(2, "ddd");
    fail("error");
  } catch (UnsupportedOperationException e) {
    list.set(2, "ddd");
    fail("error");
  } catch (UnsupportedOperationException e) {
    list.addAll(2, new ArrayList<String>());
    fail("error");
  } catch (UnsupportedOperationException e) {
origin: oblac/jodd

  @Test
  void testComparator(){
    Comparator<String> comparator = new Comparator<String>() {
      @Override
      public int compare(String str1, String str2) {
        if (str1 == null && str2 == null) {
          return 0;
        }
        if (str1 == null) {
          return 1;
        }
        if (str2 == null) {
          return -1;
        }
        return str2.compareTo(str1);
      }
    };
    SortedArrayList<String> list = new SortedArrayList<>(comparator);
    assertNotNull(list.getComparator());
    list.add("aaa");
    list.add("bbb");
    assertEquals(2, list.size());
    assertEquals("bbb", list.get(0));
    assertEquals("aaa", list.get(1));
    
  }
}
origin: org.jodd/jodd-wot

int ndx = listBS.find(set);
if (ndx < 0) {
  list.add(set);
} else {
  set = list.get(ndx);
origin: org.jodd/jodd-wot

int high = list.size() - 1;
int macroNdx = 0;
for (int deep = 0; deep < actionChunks.length; deep++) {
ActionConfigSet set = list.get(low);
ActionConfig cfg = set.lookup(method);
origin: oblac/jodd

@Test
void testRandom() {
  int total = 100000;
  ArrayList<String> randomList = new ArrayList<>();
  for (int i = 0; i < total; i++) {
    randomList.add(RandomString.get().random(20, 'a', 'z'));
  }
  SortedArrayList<String> sortedList = new SortedArrayList<>(randomList);
  Collections.sort(randomList);
  for (int i = 0; i < total; i++) {
    assertEquals(randomList.get(i), sortedList.get(i));
  }
}

origin: redisson/redisson

/**
 * Constructs a new <code>SortedArrayList</code> expecting
 * elements are comparable.
 */
public SortedArrayList(Collection<? extends E> c) {
  comparator = null;
  addAll(c);
}
origin: org.jodd/jodd-wot

/**
 * Returns chunk <code>deep</code> of a path at <code>index</code>.
 */
protected String get(int index, int deep) {
  return list.get(index).actionPathChunks[deep];
}
origin: org.jodd/jodd-wot

  @Override
  protected int getLastIndex() {
    return list.size() - 1;
  }
}
origin: org.jodd/jodd-wot

public ActionsManager() {
  this.map = new HashMap<String, ActionConfigSet>();
  this.list = new SortedArrayList<ActionConfigSet>();
  listMatch = new ActionPathChunksBinarySearch();
  listBS = BinarySearch.forList(list);
}
origin: oblac/jodd

/**
 * Adds an Object to sorted list. Object is inserted at correct place, found
 * using binary search. If the same item exist, it will be put to the end of
 * the range.
 * <p>
 * This method breaks original list contract since objects are not
 * added at the list end, but in sorted manner.
 */
@Override
public boolean add(final E o) {
  int idx = 0;
  if (!isEmpty()) {
    idx = findInsertionPoint(o);
  }
  super.add(idx, o);
  return true;
}
origin: oblac/jodd

/**
 * Constructs a new <code>SortedArrayList</code> expecting
 * elements are comparable.
 */
public SortedArrayList(final Collection<? extends E> c) {
  comparator = null;
  addAll(c);
}
origin: org.jodd/jodd-wot

protected int matchChunk(String chunk, int chunkNdx, int macroNdx, int low, int high) {
  for (int i = low; i <= high; i++) {
    ActionConfigSet set = list.get(i);
    // check if there is a macro on this chunk position
    if (macroNdx >= set.actionPathMacros.length) {
      continue;
    }
    ActionConfigSet.PathMacro macro = set.actionPathMacros[macroNdx];
    if (macro.ndx != chunkNdx) {
      continue;
    }
    // match macro
    if (chunk.startsWith(macro.left) == false) {
      continue;
    }
    if (chunk.endsWith(macro.right) == false) {
      continue;
    }
    // match value
    if (macro.pattern != null) {
      String value = chunk.substring(macro.left.length(), chunk.length() - macro.right.length());
      if (macro.pattern.matcher(value).matches() == false) {
        continue;
      }
    }
    // macro found
    return i;
  }
  return -1;
}
origin: oblac/jodd

/**
 * Finds the index at which object should be inserted.
 */
public int findInsertionPoint(final E o) {
  return findInsertionPoint(o, 0, size() - 1);
}
origin: oblac/jodd

/**
 * Conducts a binary search to find the index where Object
 * should be inserted.
 */
protected int findInsertionPoint(final E o, int low, int high) {
  while (low <= high) {
    int mid = (low + high) >>> 1;
    int delta = compare(get(mid), o);
    if (delta > 0) {
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return low;
}
origin: fivesmallq/web-data-extractor

/**
 * Adds an Object to sorted list. Object is inserted at correct place, found
 * using binary search. If the same item exist, it will be put to the end of
 * the range.
 * <p>
 * This method breaks original list contract since objects are not
 * added at the list end, but in sorted manner.
 */
@Override
public boolean add(E o) {
  int idx = 0;
  if (isEmpty() == false) {
    idx = findInsertionPoint(o);
  }
  super.add(idx, o);
  return true;
}
jodd.util.collectionSortedArrayList

Javadoc

An extension of ArrayList that insures that all of the items added are sorted. This breaks original list contract!. A binary search method is used to provide a quick way to auto sort this list.Note: Not all methods for adding and removing elements are supported.

Most used methods

  • add
    Adds an Object to sorted list. Object is inserted at correct place, found using binary search. If th
  • get
  • size
  • addAll
    Add all of the elements in the given collection to this list.
  • findInsertionPoint
    Conducts a binary search to find the index where Object should be inserted.
  • compare
    Compares two keys using the correct comparison method for this collection.
  • isEmpty
  • <init>
    Constructs a new SortedArrayList.
  • getComparator
    Returns comparator assigned to this collection, if such exist.
  • set

Popular in Java

  • Reading from database using SQL prepared statement
  • scheduleAtFixedRate (Timer)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getContentResolver (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • JButton (javax.swing)
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now