@Override
 public void addPrimitive(long value) {
   if (!buf.hasRemaining()) {
     buf = list.addBlock().asLongBuffer();
   }
   buf.put(value);
   list.incSize();
 }
  /**
   * Returns a new list of the part of the receiver between <code>from</code>, inclusive, and <code>
   * to</code>, inclusive.
   *
   * @param from the index of the first element (inclusive).
   * @param to the index of the last element (inclusive).
   * @return a new list
   * @exception IndexOutOfBoundsException index is out of range (<tt>size()&gt;0 && (from&lt;0 ||
   *     from&gt;to || to&gt;=size())</tt>).
   */
  public AbstractLongList partFromTo(int from, int to) {
    checkRangeFromTo(from, to, size);

    int length = to - from + 1;
    LongArrayList part = new LongArrayList(length);
    part.addAllOfFromTo(this, from, to);
    return part;
  }
  public List<NewsReference> getNews(Set<INews.State> states) {
    List<NewsReference> newsRefs = new ArrayList<NewsReference>(getNewsCount(states));

    for (INews.State state : states) {
      int index = state.ordinal();
      LongArrayList newsIds = fNewsIds[index];
      for (int i = 0, c = newsIds.size(); i < c; ++i) {
        long newsId = newsIds.get(i);
        Assert.isLegal(newsId != 0);
        newsRefs.add(new NewsReference(newsId));
      }
    }

    return newsRefs;
  }
Beispiel #4
0
  /**
   * Get the keys of this vector sorted by the value of the items stored for each key.
   *
   * @param decreasing If {@code true}, sort in decreasing order.
   * @return The sorted list of keys of this vector.
   */
  public LongArrayList keysByValue(boolean decreasing) {
    long[] skeys = keySet().toLongArray();

    LongComparator cmp;
    // Set up the comparator. We use the key as a secondary comparison to get
    // a reproducible sort irrespective of sorting algorithm.
    if (decreasing) {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k2), get(k1));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    } else {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k1), get(k2));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    }

    LongArrays.quickSort(skeys, cmp);
    return LongArrayList.wrap(skeys);
  }
 LongArrayListWriter(LongArrayList list) {
   this.list = list;
   buf = list.addBlock().asLongBuffer();
 }
  public Pair<Boolean, Boolean> setNews(Map<INews.State, List<NewsReference>> newsMap) {
    Assert.isNotNull(newsMap, "newsMap"); // $NON-NLS-1$

    boolean changed = false;
    boolean isNewNewsAdded = false;

    Set<INews.State> statesToReset = EnumSet.allOf(INews.State.class);
    statesToReset.removeAll(newsMap.keySet());

    /* Reset all ArrayLists whose state is not present in newsMap */
    for (INews.State state : statesToReset) {
      int index = state.ordinal();
      LongArrayList currentArrayList = fNewsIds[index];
      if (currentArrayList.size() > 0) {
        currentArrayList.clear();
        changed = true;
      }
    }

    /* For each Result */
    for (Map.Entry<INews.State, List<NewsReference>> mapEntry : newsMap.entrySet()) {
      List<NewsReference> news = mapEntry.getValue();
      INews.State state = mapEntry.getKey();

      Assert.isNotNull(news, "news"); // $NON-NLS-1$
      Assert.isNotNull(state, "state"); // $NON-NLS-1$

      long[] newArray = new long[news.size()];

      /* Fill Bucket */
      for (int i = 0; i < news.size(); i++) {
        newArray[i] = news.get(i).getId();
      }

      int index = state.ordinal();
      LongArrayList currentArrayList = fNewsIds[index];

      if (state.equals(INews.State.NEW)) {
        /* Check for added *new* News */

        if (newArray.length > currentArrayList.size()) isNewNewsAdded = true;
        else {
          for (long value : newArray) {
            if (currentArrayList.indexOf(value) < 0) {
              isNewNewsAdded = true;
              break;
            }
          }
        }
        if (isNewNewsAdded || (newArray.length != currentArrayList.size())) {
          changed = true;
          currentArrayList.setAll(newArray);
        }
      } else {
        if (!currentArrayList.elementsEqual(newArray)) {
          currentArrayList.setAll(newArray);
          changed = true;
        }
      }
    }

    return Pair.create(changed, isNewNewsAdded);
  }
 public void removeNewsRefs(List<NewsReference> newsRefs) {
   for (LongArrayList list : fNewsIds) {
     for (NewsReference newsRef : newsRefs) list.removeByElement(newsRef.getId());
   }
 }