本文整理汇总了Java中com.google.common.collect.LinkedHashMultiset类的典型用法代码示例。如果您正苦于以下问题:Java LinkedHashMultiset类的具体用法?Java LinkedHashMultiset怎么用?Java LinkedHashMultiset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkedHashMultiset类属于com.google.common.collect包,在下文中一共展示了LinkedHashMultiset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public void add(Key<?> key, State state, Object source) {
if (backingMap == null) {
backingMap = Maps.newHashMap();
}
// if it's an instanceof Class, it was a JIT binding, which we don't
// want to retain.
if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) {
source = null;
}
Multiset<Object> sources = backingMap.get(key);
if (sources == null) {
sources = LinkedHashMultiset.create();
backingMap.put(key, sources);
}
Object convertedSource = Errors.convert(source);
sources.add(convertedSource);
// Avoid all the extra work if we can.
if (state.parent() != State.NONE) {
Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state);
if (keyAndSources == null) {
evictionCache.put(state, keyAndSources = Sets.newHashSet());
}
keyAndSources.add(new KeyAndSource(key, convertedSource));
}
}
示例2: main
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public static void main(String[] args) {
// Parse text to separate words
String INPUT_TEXT = "Hello World! Hello All! Hi World!";
// Create Multiset
Multiset<String> multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
// Print count words
System.out.println(multiset); // print [Hello x 2, World! x 2, All!, Hi]- in predictable iteration order
// Print all unique words
System.out.println(multiset.elementSet()); // print [Hello, World!, All!, Hi] - in predictable iteration order
// Print count occurrences of words
System.out.println("Hello = " + multiset.count("Hello")); // print 2
System.out.println("World = " + multiset.count("World!")); // print 2
System.out.println("All = " + multiset.count("All!")); // print 1
System.out.println("Hi = " + multiset.count("Hi")); // print 1
System.out.println("Empty = " + multiset.count("Empty")); // print 0
// Print count all words
System.out.println(multiset.size()); //print 6
// Print count unique words
System.out.println(multiset.elementSet().size()); //print 4
}
示例3: main
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public static void main(String[] args) {
// Разберем текст на слова
String INPUT_TEXT = "Hello World! Hello All! Hi World!";
// Создаем Multiset
Multiset<String> multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(" ")));
// Выводим кол-вом вхождений слов
System.out.println(multiset); // напечатает [Hello x 2, World! x 2, All!, Hi]- в порядке первого добавления элемента
// Выводим все уникальные слова
System.out.println(multiset.elementSet()); // напечатает [Hello, World!, All!, Hi] - в порядке первого добавления элемента
// Выводим количество по каждому слову
System.out.println("Hello = " + multiset.count("Hello")); // напечатает 2
System.out.println("World = " + multiset.count("World!")); // напечатает 2
System.out.println("All = " + multiset.count("All!")); // напечатает 1
System.out.println("Hi = " + multiset.count("Hi")); // напечатает 1
System.out.println("Empty = " + multiset.count("Empty")); // напечатает 0
// Выводим общее количества всех слов в тексте
System.out.println(multiset.size()); //напечатает 6
// Выводим общее количество всех уникальных слов
System.out.println(multiset.elementSet().size()); //напечатает 4
}
示例4: collectFilePaths
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
/**
* Collect the file paths of the variation points of the selected elements.
*
* Each variation point is registered only once, even if several variants of the same variation
* point have been selected.
*
* @param selection
* The current selection
* @return The multi-set of variation point file paths.
*/
private LinkedHashMultiset<String> collectFilePaths(IStructuredSelection selection) {
LinkedHashMultiset<String> filePaths = LinkedHashMultiset.create();
Set<VariationPoint> vps = Sets.newLinkedHashSet();
for (Object selectedItem : selection.toList()) {
if (selectedItem instanceof Variant) {
vps.add(((Variant) selectedItem).getVariationPoint());
} else if (selectedItem instanceof VariationPoint) {
vps.add((VariationPoint) selectedItem);
}
}
for (VariationPoint vp : vps) {
if (vp != null) {
filePaths.add(getFile(vp));
}
}
return filePaths;
}
示例5: testSerialization
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public void testSerialization() {
BeanWithMultisetTypes bean = new BeanWithMultisetTypes();
List<String> list = Arrays.asList( "foo", "abc", null, "abc" );
List<String> listWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );
bean.multiset = LinkedHashMultiset.create( list );
bean.hashMultiset = HashMultiset.create( Arrays.asList( "abc", "abc" ) );
bean.linkedHashMultiset = LinkedHashMultiset.create( list );
bean.sortedMultiset = TreeMultiset.create( listWithNonNull );
bean.treeMultiset = TreeMultiset.create( listWithNonNull );
bean.immutableMultiset = ImmutableMultiset.copyOf( listWithNonNull );
bean.enumMultiset = EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) );
String expected = "{" +
"\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
"\"hashMultiset\":[\"abc\",\"abc\"]," +
"\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
"\"sortedMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
"\"treeMultiset\":[\"abc\",\"abc\",\"bar\",\"foo\"]," +
"\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\"]," +
"\"enumMultiset\":[\"A\",\"A\",\"B\",\"D\"]" +
"}";
assertEquals( expected, BeanWithMultisetTypesMapper.INSTANCE.write( bean ) );
}
示例6: testDeserialization
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public void testDeserialization() {
String input = "{" +
"\"multiset\":[\"foo\",\"abc\",\"abc\",null]," +
"\"hashMultiset\":[\"abc\",\"abc\"]," +
"\"linkedHashMultiset\":[\"foo\",\"abc\",\"abc\",null]," +
"\"sortedMultiset\":[\"foo\",\"abc\",\"bar\",\"abc\",null]," +
"\"treeMultiset\":[\"bar\",\"abc\",\"abc\",\"foo\",null]," +
"\"immutableMultiset\":[\"foo\",\"abc\",\"abc\",\"bar\",null]," +
"\"enumMultiset\":[\"B\",\"A\",\"A\",\"D\",null]" +
"}";
BeanWithMultisetTypes result = BeanWithMultisetTypesMapper.INSTANCE.read( input );
assertNotNull( result );
List<String> expectedList = Arrays.asList( "foo", "abc", null, "abc" );
List<String> expectedListWithNonNull = Arrays.asList( "foo", "abc", "bar", "abc" );
assertEquals( LinkedHashMultiset.create( expectedList ), result.multiset );
assertEquals( HashMultiset.create( Arrays.asList( "abc", "abc" ) ), result.hashMultiset );
assertEquals( LinkedHashMultiset.create( expectedList ), result.linkedHashMultiset );
assertEquals( TreeMultiset.create( expectedListWithNonNull ), result.sortedMultiset );
assertEquals( TreeMultiset.create( expectedListWithNonNull ), result.treeMultiset );
assertEquals( ImmutableMultiset.copyOf( expectedListWithNonNull ), result.immutableMultiset );
assertEquals( EnumMultiset.create( Arrays.asList( AlphaEnum.B, AlphaEnum.A, AlphaEnum.D, AlphaEnum.A ) ), result.enumMultiset );
}
示例7: CSSContext
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public CSSContext() {
selectors = LinkedHashMultiset.create();
classes = LinkedHashMultiset.create();
javaClasses = LinkedHashMultiset.create();
ids = LinkedHashMultiset.create();
states = LinkedHashMultiset.create();
entries = LinkedListMultimap.create();
paints = LinkedListMultimap.create();
}
示例8: cumulateDistance
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
/**
* Keeps the cumulated distance for all the common raw super types of the given references.
* Interfaces that are more directly implemented will get a lower total count than more general
* interfaces.
*/
protected void cumulateDistance(final List<LightweightTypeReference> references, Multimap<JvmType, LightweightTypeReference> all,
Multiset<JvmType> cumulatedDistance) {
for(LightweightTypeReference other: references) {
Multiset<JvmType> otherDistance = LinkedHashMultiset.create();
initializeDistance(other, all, otherDistance);
cumulatedDistance.retainAll(otherDistance);
for(Multiset.Entry<JvmType> typeToDistance: otherDistance.entrySet()) {
if (cumulatedDistance.contains(typeToDistance.getElement()))
cumulatedDistance.add(typeToDistance.getElement(), typeToDistance.getCount());
}
}
}
示例9: parseArray
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
private static Multiset<Field> parseArray(List<Object> array) throws ParserException {
Multiset<Field> members = LinkedHashMultiset.create();
for(Object member: array) {
members.add(parseField(null, member));
}
return members;
}
示例10: fillStats
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
private void fillStats(List<Status> list, Map<DateMidnight, Integer> map, DateMidnight start, DateMidnight end) {
LinkedList<Status> linkedList = new LinkedList<Status>(list);
Iterator<Status> iterator = linkedList.descendingIterator();
if (!iterator.hasNext()) {
return;
}
Multiset<DateMidnight> data = LinkedHashMultiset.create();
Status currentStatus = iterator.next();
DateMidnight current = new DateMidnight(currentStatus.getCreatedAt());
while (iterator.hasNext() || currentStatus != null) {
DateMidnight msgTime = new DateMidnight(currentStatus.getCreatedAt());
if (current.equals(msgTime)) {
data.add(current);
if (iterator.hasNext()) {
currentStatus = iterator.next();
} else {
currentStatus = null;
}
} else {
current = current.plusDays(1);
}
}
for (DateMidnight dm = start; !dm.isAfter(end); dm = dm.plusDays(1)) {
map.put(dm, data.count(dm));
}
}
示例11: identifyDependencies
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
/**
* Identify the dependencies between the variation points based on referring and referred
* elements.<br>
* Build and return an edge descriptor for each of those pairs.
*
* @param referenceSelector
* The selector for the references to consider.
* @param index
* The index containing previously identified element references.
* @return The list of identified edge descriptors.
*/
private List<VPMEdgeDescriptor> identifyDependencies(ReferenceSelector referenceSelector, VPReferenceIndex index) {
List<VPMEdgeDescriptor> edges = Lists.newArrayList();
List<String> edgeRegistry = new ArrayList<String>();
Multiset<DependencyType> statistics = LinkedHashMultiset.create();
for (Commentable element : index.referencedElementsIndex.keySet()) {
List<VPMEdgeDescriptor> vpEdges = identifyRelatedVPsForReferencedElement(edgeRegistry, element,
referenceSelector, index, statistics);
edges.addAll(vpEdges);
}
printStatistics(statistics);
return edges;
}
示例12: execute
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection curSelection = HandlerUtil.getCurrentSelection(event);
if (curSelection == null || !(curSelection instanceof IStructuredSelection)) {
return null;
}
IStructuredSelection selection = (IStructuredSelection) curSelection;
LinkedHashMultiset<String> filePaths = collectFilePaths(selection);
String clipboardContent = buildClipboardContent(filePaths);
copyToClipboard(clipboardContent);
return null;
}
示例13: buildClipboardContent
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
private String buildClipboardContent(LinkedHashMultiset<String> filePaths) {
StringBuilder copyContent = new StringBuilder();
for (String file : filePaths.elementSet()) {
copyContent.append(FilenameUtils.getName(file));
copyContent.append(",");
copyContent.append(filePaths.count(file));
copyContent.append("\r\n");
}
return copyContent.toString();
}
示例14: add
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
public void add(Key<?> key, State state, Object source) {
if (backingSet == null) {
backingSet = Maps.newHashMap();
}
// if it's an instanceof Class, it was a JIT binding, which we don't
// want to retain.
if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) {
source = null;
}
Object mapKey = toMapKey(key);
Multiset<Object> sources = backingSet.get(mapKey);
if (sources == null) {
sources = LinkedHashMultiset.create();
backingSet.put(mapKey, sources);
}
Object convertedSource = Errors.convert(source);
sources.add(convertedSource);
// Avoid all the extra work if we can.
if (state.parent() != State.NONE) {
Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state);
if (keyAndSources == null) {
evictionCache.put(state, keyAndSources = Sets.newHashSet());
}
keyAndSources.add(new KeyAndSource(mapKey, convertedSource));
}
}
示例15: RandomRoutePlanner
import com.google.common.collect.LinkedHashMultiset; //导入依赖的package包/类
/**
* Creates a random route planner using the specified random seed.
* @param seed The random seed.
*/
public RandomRoutePlanner(long seed) {
LOGGER.info("constructor {}", seed);
assignedParcels = LinkedHashMultiset.create();
current = Optional.absent();
rng = new RandomAdaptor(new MersenneTwister(seed));
}