Tabnine Logo
ArrayList.ensureCapacity
Code IndexAdd Tabnine to your IDE (free)

How to use
ensureCapacity
method
in
java.util.ArrayList

Best Java code snippets using java.util.ArrayList.ensureCapacity (Showing top 20 results out of 3,501)

Refine searchRefine arrow

  • ArrayList.size
  • ArrayList.add
origin: skylot/jadx

protected void addAll(Collection<? extends JNode> nodes) {
  rows.ensureCapacity(rows.size() + nodes.size());
  rows.addAll(nodes);
  if (!addDescColumn) {
    for (JNode row : rows) {
      if (row.hasDescString()) {
        addDescColumn = true;
        break;
      }
    }
  }
}
origin: apache/ignite

/**
 * Ensure counters capacity and initial state.
 *
 * @param minCap Desired minimum capacity.
 */
private void capacity(int minCap) {
  counters.ensureCapacity(minCap);
  while (counters.size() < minCap)
    counters.add(0);
}
origin: hibernate/hibernate-orm

/**
 * Read this object state back in from the given stream as part of de-serialization
 * 
 * @param in The stream from which to read our serial state
 */
@Override
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  sorted = in.readBoolean();
  final int numberOfExecutables = in.readInt();
  executables.ensureCapacity( numberOfExecutables );
  if ( numberOfExecutables > 0 ) {
    for ( int i = 0; i < numberOfExecutables; i++ ) {
      E e = (E) in.readObject();
      executables.add( e );
    }
  }
  final int numberOfQuerySpaces = in.readInt();
  if ( numberOfQuerySpaces < 0 ) {
    this.querySpaces = null;
  }
  else {
    querySpaces = new HashSet<Serializable>( CollectionHelper.determineProperSizing( numberOfQuerySpaces ) );
    for ( int i = 0; i < numberOfQuerySpaces; i++ ) {
      querySpaces.add( in.readUTF() );
    }
  }
}
origin: naman14/Timber

private void addToPlayList(final long[] list, int position, long sourceId, TimberUtils.IdType sourceType) {
  final int addlen = list.length;
  if (position < 0) {
    mPlaylist.clear();
    position = 0;
  }
  mPlaylist.ensureCapacity(mPlaylist.size() + addlen);
  if (position > mPlaylist.size()) {
    position = mPlaylist.size();
  }
  final ArrayList<MusicPlaybackTrack> arrayList = new ArrayList<MusicPlaybackTrack>(addlen);
  for (int i = 0; i < list.length; i++) {
    arrayList.add(new MusicPlaybackTrack(list[i], sourceId, sourceType, i));
  }
  mPlaylist.addAll(position, arrayList);
  if (mPlaylist.size() == 0) {
    closeCursor();
    notifyChange(META_CHANGED);
  }
}
origin: wildfly/wildfly

  @Override
  public void run() {
    while (true) {
      Pair p;
      synchronized (filesToCompare) {
        if (!filesToCompare.hasNext()) {
          break;
        }
        p = filesToCompare.next();
      }
      compareFiles(args[p.getX()], args[p.getY()], messageDeliverOrder);
      int size = messageDeliverOrder.size();
      messageDeliverOrder.clear();
      messageDeliverOrder.ensureCapacity(size);
    }            
    
    System.out.println(getName() + " finished!");
  }
}
origin: apache/ignite

/**
 * Initialize {@link #args} and increase its capacity and size up to given argument if needed.
 * @param size new expected size.
 */
private void ensureArgsSize(int size) {
  if (args == null)
    args = new ArrayList<>(size);
  args.ensureCapacity(size);
  while (args.size() < size)
    args.add(null);
}
origin: aa112901/remusic

public synchronized ArrayList<Playlist> getNetPlaylist() {
  ArrayList<Playlist> results = new ArrayList<>();
  Cursor cursor = null;
  try {
    cursor = mMusicDatabase.getReadableDatabase().query(PlaylistInfoColumns.NAME, null,
        null, null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
      results.ensureCapacity(cursor.getCount());
      do {
        if (!cursor.getString(4).equals("local"))
          results.add(new Playlist(cursor.getLong(0), cursor.getString(1), cursor.getInt(2), cursor.getString(3), cursor.getString(4)));
      } while (cursor.moveToNext());
    }
    return results;
  } finally {
    if (cursor != null) {
      cursor.close();
      cursor = null;
    }
  }
}
origin: aa112901/remusic

private void addToPlayList(final long[] list, int position) {
  final int addlen = list.length;
  if (position < 0) {
    mPlaylist.clear();
    position = 0;
  }
  mPlaylist.ensureCapacity(mPlaylist.size() + addlen);
  if (position > mPlaylist.size()) {
    position = mPlaylist.size();
  }
  final ArrayList<MusicTrack> arrayList = new ArrayList<MusicTrack>(addlen);
  for (int i = 0; i < list.length; i++) {
    arrayList.add(new MusicTrack(list[i], i));
  }
  mPlaylist.addAll(position, arrayList);
  if (mPlaylist.size() == 0) {
    closeCursor();
    notifyChange(META_CHANGED);
  }
}
origin: protostuff/protostuff

protected static <T> void grow(ArrayList<T> list, int size)
{
  int previousSize = list.size();
  list.ensureCapacity(size);
  List<T> l = Collections.nCopies(size - previousSize, null);
  list.addAll(l);
}
origin: alibaba/Tangram-Android

/**
 * append new cards into adapter
 *
 * @param cards new cards will be added to the end
 */
public void appendGroup(@Nullable List<L> cards) {
  if (cards == null || cards.size() == 0)
    return;
  createSnapshot();
  final List<LayoutHelper> helpers = new LinkedList<>(getLayoutHelpers());
  mCards.ensureCapacity(mCards.size() + cards.size());
  helpers.addAll(transformCards(cards, mData, mCards));
  setLayoutHelpers(helpers);
  diffWithSnapshot();
  // not use {@link notifyItemRangeChanged} because not sure whether animations is required
  // notifyItemRangeChanged(oldItem, newitems);
  notifyDataSetChanged();
}
origin: stackoverflow.com

 public static void ensureSize(ArrayList<?> list, int size) {
  // Prevent excessive copying while we're adding
  list.ensureCapacity(size);
  while (list.size() < size) {
    list.add(null);
  }
}
origin: aa112901/remusic

public ArrayList<MusicTrack> getPlaylist(final long playlistid) {
  ArrayList<MusicTrack> results = new ArrayList<>();
  Cursor cursor = null;
  try {
    cursor = mMusicDatabase.getReadableDatabase().query(PlaylistsColumns.NAME, null,
        PlaylistsColumns.PLAYLIST_ID + " = " + String.valueOf(playlistid), null, null, null, PlaylistsColumns.TRACK_ORDER + " ASC ", null);
    if (cursor != null && cursor.moveToFirst()) {
      results.ensureCapacity(cursor.getCount());
      do {
        results.add(new MusicTrack(cursor.getLong(1), cursor.getInt(0)));
      } while (cursor.moveToNext());
    }
    return results;
  } finally {
    if (cursor != null) {
      cursor.close();
      cursor = null;
    }
  }
}
origin: jamesagnew/hapi-fhir

private boolean addToHeldComments(int valueIdx, List<String> theCommentsToAdd, ArrayList<ArrayList<String>> theListToAddTo) {
  if (theCommentsToAdd.size() > 0) {
    theListToAddTo.ensureCapacity(valueIdx);
    while (theListToAddTo.size() <= valueIdx) {
      theListToAddTo.add(null);
    }
    if (theListToAddTo.get(valueIdx) == null) {
      theListToAddTo.set(valueIdx, new ArrayList<String>());
    }
    theListToAddTo.get(valueIdx).addAll(theCommentsToAdd);
    return true;
  }
  return false;
}
origin: wildfly/wildfly

public SimpleName addAll(final int pos, final Name name) {
  if (name instanceof SimpleName) {
    segments.addAll(pos, ((SimpleName) name).segments);
    return this;
  }
  final ArrayList<String> segments = this.segments;
  final int size = name.size();
  final int ourSize = segments.size();
  segments.ensureCapacity(ourSize + size);
  for (int i = 0; i < size; i ++) {
    add(pos + i, name.get(i));
  }
  return this;
}
origin: alibaba/Tangram-Android

/**
 * append new cards into adapter
 *
 * @param cards new cards will be added to the end
 */
public void appendGroup(@Nullable List<L> cards) {
  if (cards == null || cards.size() == 0)
    return;
  createSnapshot();
  final List<LayoutHelper> helpers = new LinkedList<>(getLayoutHelpers());
  mCards.ensureCapacity(mCards.size() + cards.size());
  helpers.addAll(transformCards(cards, mData, mCards));
  setLayoutHelpers(helpers);
  diffWithSnapshot();
  // not use {@link notifyItemRangeChanged} because not sure whether animations is required
  // notifyItemRangeChanged(oldItem, newitems);
  notifyDataSetChanged();
}
origin: airbnb/epoxy

void addPayload(@Nullable EpoxyModel<?> payload) {
 if (payload == null) {
  return;
 }
 if (payloads == null) {
  // In most cases this won't be a batch update so we can expect just one payload
  payloads = new ArrayList<>(1);
 } else if (payloads.size() == 1) {
  // There are multiple payloads, but we don't know how big the batch will end up being.
  // To prevent resizing the list many times we bump it to a medium size
  payloads.ensureCapacity(10);
 }
 payloads.add(payload);
}
origin: aa112901/remusic

public synchronized ArrayList<DownloadDBEntity> getDownLoadedListAll() {
  ArrayList<DownloadDBEntity> results = new ArrayList<>();
  Cursor cursor = null;
  try {
    cursor = mMusicDatabase.getReadableDatabase().query(DownFileStoreColumns.NAME, null,
        null, null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) {
      results.ensureCapacity(cursor.getCount());
      do {
        results.add(new DownloadDBEntity(cursor.getString(0), cursor.getLong(1), cursor.getLong(2),
            cursor.getString(3), cursor.getString(4), cursor.getString(5), cursor.getString(6), cursor.getInt(7)));
      } while (cursor.moveToNext());
    }
    return results;
  } finally {
    if (cursor != null) {
      cursor.close();
      cursor = null;
    }
  }
}
origin: AppliedEnergistics/Applied-Energistics-2

this.lines.ensureCapacity( this.getMaxRows() );
  this.lines.add( n );
this.getScrollBar().setRange( 0, this.lines.size() - LINES_ON_PAGE, 2 );
origin: wildfly/wildfly

public SimpleName addAll(final Name suffix) {
  if (suffix instanceof SimpleName) {
    segments.addAll(((SimpleName) suffix).segments);
    return this;
  }
  final ArrayList<String> segments = this.segments;
  final int size = suffix.size();
  final int ourSize = segments.size();
  segments.ensureCapacity(ourSize + size);
  for (int i = 0; i < size; i ++) {
    add(suffix.get(i));
  }
  return this;
}
origin: klout/brickhouse

private void addVector(Object listObj, VectorArrayAggBuffer myagg, ListObjectInspector inputOI) {
  int listLen = inputOI.getListLength(listObj);
  if (listLen > myagg.sumArray.size())
    myagg.sumArray.ensureCapacity(listLen);
  for (int i = 0; i < listLen; ++i) {
    Object listElem = inputOI.getListElement(listObj, i);
    double listElemDbl = NumericUtil.getNumericValue(
        (PrimitiveObjectInspector) inputOI.getListElementObjectInspector(), listElem);
    Double oldVal = myagg.sumArray.get(i);
    if (oldVal != null) {
      myagg.sumArray.set(i, oldVal + listElemDbl);
    } else {
      myagg.sumArray.set(i, listElemDbl);
    }
  }
}
java.utilArrayListensureCapacity

Javadoc

Ensures that after this operation the ArrayList can hold the specified number of elements without further growing.

Popular methods of ArrayList

  • <init>
  • add
  • size
    Returns the number of elements in this ArrayList.
  • get
    Returns the element at the specified position in this list.
  • toArray
    Returns an array containing all of the elements in this list in proper sequence (from first to last
  • addAll
    Adds the objects in the specified collection to this ArrayList.
  • remove
    Removes the first occurrence of the specified element from this list, if it is present. If the list
  • clear
    Removes all elements from this ArrayList, leaving it empty.
  • isEmpty
    Returns true if this list contains no elements.
  • iterator
    Returns an iterator over the elements in this list in proper sequence.The returned iterator is fail-
  • contains
    Searches this ArrayList for the specified object.
  • set
    Replaces the element at the specified position in this list with the specified element.
  • contains,
  • set,
  • indexOf,
  • clone,
  • subList,
  • stream,
  • trimToSize,
  • removeAll,
  • toString

Popular in Java

  • Start an intent from android
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getExternalFilesDir (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Top PhpStorm 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