當前位置: 首頁>>代碼示例>>Java>>正文


Java Entry類代碼示例

本文整理匯總了Java中com.google.common.collect.Multiset.Entry的典型用法代碼示例。如果您正苦於以下問題:Java Entry類的具體用法?Java Entry怎麽用?Java Entry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Entry類屬於com.google.common.collect.Multiset包,在下文中一共展示了Entry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: retainOccurrencesImpl

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
/**
 * Delegate implementation which cares about the element type.
 */
private static <E> boolean retainOccurrencesImpl(
    Multiset<E> multisetToModify, Multiset<?> occurrencesToRetain) {
  checkNotNull(multisetToModify);
  checkNotNull(occurrencesToRetain);
  // Avoiding ConcurrentModificationExceptions is tricky.
  Iterator<Entry<E>> entryIterator = multisetToModify.entrySet().iterator();
  boolean changed = false;
  while (entryIterator.hasNext()) {
    Entry<E> entry = entryIterator.next();
    int retainCount = occurrencesToRetain.count(entry.getElement());
    if (retainCount == 0) {
      entryIterator.remove();
      changed = true;
    } else if (retainCount < entry.getCount()) {
      multisetToModify.setCount(entry.getElement(), retainCount);
      changed = true;
    }
  }
  return changed;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:24,代碼來源:Multisets.java

示例2: equalsImpl

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
/**
 * An implementation of {@link Multiset#equals}.
 */
static boolean equalsImpl(Multiset<?> multiset, @Nullable Object object) {
  if (object == multiset) {
    return true;
  }
  if (object instanceof Multiset) {
    Multiset<?> that = (Multiset<?>) object;
    /*
     * We can't simply check whether the entry sets are equal, since that
     * approach fails when a TreeMultiset has a comparator that returns 0
     * when passed unequal elements.
     */

    if (multiset.size() != that.size() || multiset.entrySet().size() != that.entrySet().size()) {
      return false;
    }
    for (Entry<?> entry : that.entrySet()) {
      if (multiset.count(entry.getElement()) != entry.getCount()) {
        return false;
      }
    }
    return true;
  }
  return false;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:28,代碼來源:Multisets.java

示例3: remove

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@SuppressWarnings("cast")
@Override
public boolean remove(Object object) {
  if (object instanceof Multiset.Entry) {
    Entry<?> entry = (Entry<?>) object;
    Object element = entry.getElement();
    int entryCount = entry.getCount();
    if (entryCount != 0) {
      // Safe as long as we never add a new entry, which we won't.
      @SuppressWarnings("unchecked")
      Multiset<Object> multiset = (Multiset) multiset();
      return multiset.setCount(element, entryCount, 0);
    }
  }
  return false;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:17,代碼來源:Multisets.java

示例4: processPacket

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
/**
 * Passes this Packet on to the NetHandler for processing.
 */
@Override
public void processPacket(INetHandler inethandler)
{
    this.netHandler = inethandler;
    EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel, this.target);
    if (internalChannel != null)
    {
        internalChannel.attr(NetworkRegistry.NET_HANDLER).set(this.netHandler);
        try
        {
            if (internalChannel.writeInbound(this))
            {
                badPackets.add(this.channel);
                if (badPackets.size() % packetCountWarning == 0)
                {
                    FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size());
                    int i = 0;
                    for (Entry<String> s  : Multisets.copyHighestCountFirst(badPackets).entrySet())
                    {
                        if (i++ > 10) break;
                        FMLLog.severe("\t %s : %d", s.getElement(), s.getCount());
                    }
                }
            }
            internalChannel.inboundMessages().clear();
        }
        catch (FMLNetworkException ne)
        {
            FMLLog.log(Level.ERROR, ne, "There was a network exception handling a packet on channel %s", channel);
            dispatcher.rejectHandshake(ne.getMessage());
        }
        catch (Throwable t)
        {
            FMLLog.log(Level.ERROR, t, "There was a critical exception handling a packet on channel %s", channel);
            dispatcher.rejectHandshake("A fatal error has occurred, this connection is terminated");
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:42,代碼來源:FMLProxyPacket.java

示例5: contains

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@Override
public boolean contains(@Nullable Object o) {
  if (o instanceof Entry) {
    /*
     * The GWT compiler wrongly issues a warning here.
     */
    @SuppressWarnings("cast")
    Entry<?> entry = (Entry<?>) o;
    if (entry.getCount() <= 0) {
      return false;
    }
    int count = multiset().count(entry.getElement());
    return count == entry.getCount();
  }
  return false;
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:17,代碼來源:Multisets.java

示例6: assertSetCount

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
private void assertSetCount(E element, int count) {
  setCountCheckReturnValue(element, count);

  assertEquals(
      "multiset.count() should return the value passed to setCount()",
      count,
      getMultiset().count(element));

  int size = 0;
  for (Multiset.Entry<E> entry : getMultiset().entrySet()) {
    size += entry.getCount();
  }
  assertEquals(
      "multiset.size() should be the sum of the counts of all entries",
      size,
      getMultiset().size());
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:18,代碼來源:AbstractMultisetSetCountTester.java

示例7: testClearHeadOpen

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClearHeadOpen() {
  List<Entry<E>> expected =
      copyToList(sortedMultiset.tailMultiset(b.getElement(), CLOSED).entrySet());
  sortedMultiset.headMultiset(b.getElement(), OPEN).clear();
  assertEquals(expected, copyToList(sortedMultiset.entrySet()));
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:9,代碼來源:MultisetNavigationTester.java

示例8: entrySet

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public Set<Multiset.Entry<E>> entrySet() {
  Set<Multiset.Entry<E>> es = entrySet;
  return (es == null)
      // Safe because the returned set is made unmodifiable and Entry
      // itself is readonly
      ? entrySet = (Set) Collections.unmodifiableSet(delegate.entrySet())
      : es;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:Multisets.java

示例9: createEntrySet

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@Override
Set<Entry<E>> createEntrySet() {
  return Sets.filter(
      unfiltered.entrySet(),
      new Predicate<Entry<E>>() {
        @Override
        public boolean apply(Entry<E> entry) {
          return predicate.apply(entry.getElement());
        }
      });
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:12,代碼來源:Multisets.java

示例10: equals

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
/**
 * Indicates whether an object equals this entry, following the behavior
 * specified in {@link Multiset.Entry#equals}.
 */
@Override
public boolean equals(@Nullable Object object) {
  if (object instanceof Multiset.Entry) {
    Multiset.Entry<?> that = (Multiset.Entry<?>) object;
    return this.getCount() == that.getCount()
        && Objects.equal(this.getElement(), that.getElement());
  }
  return false;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:14,代碼來源:Multisets.java

示例11: addAllImpl

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
/**
 * An implementation of {@link Multiset#addAll}.
 */
static <E> boolean addAllImpl(Multiset<E> self, Collection<? extends E> elements) {
  if (elements.isEmpty()) {
    return false;
  }
  if (elements instanceof Multiset) {
    Multiset<? extends E> that = cast(elements);
    for (Entry<? extends E> entry : that.entrySet()) {
      self.add(entry.getElement(), entry.getCount());
    }
  } else {
    Iterators.addAll(self, elements.iterator());
  }
  return true;
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:18,代碼來源:Multisets.java

示例12: iterator

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@Override
public Iterator<E> iterator() {
  return new TransformedIterator<Entry<E>, E>(multiset().entrySet().iterator()) {
    @Override
    E transform(Entry<E> entry) {
      return entry.getElement();
    }
  };
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:10,代碼來源:Multisets.java

示例13: testClearHeadClosedEntrySet

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testClearHeadClosedEntrySet() {
  List<Entry<E>> expected =
      copyToList(sortedMultiset.tailMultiset(b.getElement(), OPEN).entrySet());
  sortedMultiset.headMultiset(b.getElement(), CLOSED).entrySet().clear();
  assertEquals(expected, copyToList(sortedMultiset.entrySet()));
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:9,代碼來源:MultisetNavigationTester.java

示例14: spliteratorImpl

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
static <E> Spliterator<E> spliteratorImpl(Multiset<E> multiset) {
  Spliterator<Entry<E>> entrySpliterator = multiset.entrySet().spliterator();
  return CollectSpliterators.flatMap(
      entrySpliterator,
      entry -> Collections.nCopies(entry.getCount(), entry.getElement()).spliterator(),
      Spliterator.SIZED
          | (entrySpliterator.characteristics()
              & (Spliterator.ORDERED | Spliterator.NONNULL | Spliterator.IMMUTABLE)),
      multiset.size());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:Multisets.java

示例15: sizeImpl

import com.google.common.collect.Multiset.Entry; //導入依賴的package包/類
/**
 * An implementation of {@link Multiset#size}.
 */
static int sizeImpl(Multiset<?> multiset) {
  long size = 0;
  for (Entry<?> entry : multiset.entrySet()) {
    size += entry.getCount();
  }
  return Ints.saturatedCast(size);
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:Multisets.java


注:本文中的com.google.common.collect.Multiset.Entry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。