List of usage examples for com.google.common.collect Lists newCopyOnWriteArrayList
@GwtIncompatible("CopyOnWriteArrayList") public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList(Iterable<? extends E> elements)
From source file:com.spotify.statistics.MergingMuninGraphProvider.java
/** * Create a new provider using a list of providers. * * @param providers The providers to merge. *///from w w w . j a v a 2 s. co m public MergingMuninGraphProvider(final Iterable<MuninGraphProvider> providers) { this.providers = Lists.newCopyOnWriteArrayList(providers); }
From source file:org.apache.isis.core.metamodel.facets.CollectionUtils.java
/** * Copies the iterable into the specified type. *///from w w w . jav a 2 s . c o m public static Object copyOf(final Iterable<Object> iterable, final Class<?> requiredType) { if (iterable == null) { throw new IllegalArgumentException("Iterable must be provided"); } if (requiredType == null) { throw new IllegalArgumentException("RequiredType must be provided"); } // specific list implementations if (CopyOnWriteArrayList.class == requiredType) { return Lists.newCopyOnWriteArrayList(iterable); } if (LinkedList.class == requiredType) { return Lists.newLinkedList(iterable); } if (ArrayList.class == requiredType) { return Lists.newArrayList(iterable); } if (AbstractList.class == requiredType) { return Lists.newArrayList(iterable); } // specific set implementations if (CopyOnWriteArraySet.class == requiredType) { return Sets.newCopyOnWriteArraySet(iterable); } if (LinkedHashSet.class == requiredType) { return Sets.newLinkedHashSet(iterable); } if (HashSet.class == requiredType) { return Sets.newHashSet(iterable); } if (TreeSet.class == requiredType) { Iterable rawIterable = iterable; return Sets.newTreeSet(rawIterable); } if (AbstractSet.class == requiredType) { return Sets.newLinkedHashSet(iterable); } // interfaces if (List.class == requiredType) { return Lists.newArrayList(iterable); } if (SortedSet.class == requiredType) { Iterable rawIterable = iterable; return Sets.newTreeSet(rawIterable); } if (Set.class == requiredType) { return Sets.newLinkedHashSet(iterable); } if (Collection.class == requiredType) { return Lists.newArrayList(iterable); } // array if (requiredType.isArray()) { Class<?> componentType = requiredType.getComponentType(); Iterable rawIterable = iterable; return Iterables.toArray(rawIterable, componentType); } // not recognized return null; }
From source file:net.t7seven7t.viewit.SimpleScoreboardElement.java
public SimpleScoreboardElement(Plugin plugin, int priority, long updateDelay, List<FrameSupply> contents) { this.priority = priority; this.contents = Lists.newCopyOnWriteArrayList(contents); this.plugin = plugin; // forced update delay so that players can be cleaned out // implementation specific this.updateDelay = updateDelay > 0 ? updateDelay : 20L * 10; this.isTitle = priority < 0; MapMaker mapMaker = new MapMaker().weakKeys(); this.playerContentsMap = mapMaker.makeMap(); this.cachedContents = mapMaker.makeMap(); Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, this::updateAnimations, 1l, this.updateDelay); }
From source file:com.facebook.buck.jvm.java.BaseCompileToJarStepFactory.java
@Override public void createCompileToJarStep(BuildContext context, ImmutableSortedSet<Path> sourceFilePaths, BuildTarget invokingRule, SourcePathResolver resolver, SourcePathRuleFinder ruleFinder, ProjectFilesystem filesystem, ImmutableSortedSet<Path> declaredClasspathEntries, Path outputDirectory, Optional<Path> workingDirectory, Path pathToSrcsList, Optional<SuggestBuildRules> suggestBuildRules, ImmutableList<String> postprocessClassesCommands, ImmutableSortedSet<Path> entriesToJar, Optional<String> mainClass, Optional<Path> manifestFile, Path outputJar, ClassUsageFileWriter usedClassesFileWriter, /* output params */ ImmutableList.Builder<Step> steps, BuildableContext buildableContext, ImmutableSet<Pattern> classesToRemoveFromJar) { createCompileStep(context, sourceFilePaths, invokingRule, resolver, ruleFinder, filesystem, declaredClasspathEntries, outputDirectory, workingDirectory, pathToSrcsList, suggestBuildRules, usedClassesFileWriter, steps, buildableContext); steps.addAll(Lists.newCopyOnWriteArrayList(addPostprocessClassesCommands(filesystem, postprocessClassesCommands, outputDirectory, declaredClasspathEntries, getBootClasspath(context)))); steps.add(new JarDirectoryStep(filesystem, outputJar, ImmutableSortedSet.of(outputDirectory), mainClass.orElse(null), manifestFile.orElse(null), true, classesToRemoveFromJar)); }
From source file:org.ow2.petals.cloud.controllers.core.TopologyManager.java
/** * Get the current topology * * @return */ public Topology getTopology() { return new Topology(Lists.newCopyOnWriteArrayList(topology.getRuntimes())); }
From source file:com.mogujie.instantrun.IntSwitch.java
private void visitClassifier(GeneratorAdapter mv, Set<String> strings) { visitInt();// w ww .java 2 s . c o m Multimap<Integer, String> buckets = Multimaps.index(strings, HASH_METHOD); List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural() .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<String>> entry) { return entry.getKey(); } }).immutableSortedCopy(buckets.asMap().entrySet()); int sortedHashes[] = new int[sorted.size()]; List<String> sortedCases[] = new List[sorted.size()]; int index = 0; for (Map.Entry<Integer, Collection<String>> entry : sorted) { sortedHashes[index] = entry.getKey(); sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue()); index++; } // Label for each hash and for default. Label labels[] = new Label[sorted.size()]; Label defaultLabel = new Label(); for (int i = 0; i < sorted.size(); ++i) { labels[i] = new Label(); } // Create a switch that dispatches to each label from the hash code of mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels); // Create the cases. for (int i = 0; i < sorted.size(); ++i) { mv.visitLabel(labels[i]); visitx(mv, sortedCases[i]); } mv.visitLabel(defaultLabel); visitDefault(); }
From source file:com.android.build.gradle.internal.incremental.StringSwitch.java
/** * Emit code for a string switch for the given string classifier. * * switch(s.hashCode()) {/* w ww .j a v a 2 s .c om*/ * case 192: visitCase(s); * case 312: visitCase(s); * case 1024: * if (s.equals("collided_method1")) { * visit(s); * } else if (s.equals("collided_method2")) { * visit(s); * } * visitDefault(); * default: * visitDefault(); * } * **/ private void visitClassifier(GeneratorAdapter mv, Set<String> strings) { visitString(); visitHashMethod(mv); // Group strings by hash code. Multimap<Integer, String> buckets = Multimaps.index(strings, HASH_METHOD); List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural() .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<String>> entry) { return entry.getKey(); } }).immutableSortedCopy(buckets.asMap().entrySet()); int sortedHashes[] = new int[sorted.size()]; List<String> sortedCases[] = new List[sorted.size()]; int index = 0; for (Map.Entry<Integer, Collection<String>> entry : sorted) { sortedHashes[index] = entry.getKey(); sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue()); index++; } // Label for each hash and for default. Label labels[] = new Label[sorted.size()]; Label defaultLabel = new Label(); for (int i = 0; i < sorted.size(); ++i) { labels[i] = new Label(); } // Create a switch that dispatches to each label from the hash code of mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels); // Create the cases. for (int i = 0; i < sorted.size(); ++i) { mv.visitLabel(labels[i]); visitx(mv, sortedCases[i]); } mv.visitLabel(defaultLabel); visitDefault(); }
From source file:dodola.anole.lib.StringSwitch.java
/** * Emit code for a string switch for the given string classifier. * * switch(s.hashCode()) {/* ww w . ja v a 2 s . c o m*/ * case 192: visitCase(s); * case 312: visitCase(s); * case 1024: * if (s.equals("collided_method1")) { * visit(s); * } else if (s.equals("collided_method2")) { * visit(s); * } * visitDefault(); * default: * visitDefault(); * } * **/ private void visitClassifier(GeneratorAdapter mv, Set<String> strings) { visitString(); visitHashMethod(mv); // Group strings by hash code. Multimap<Integer, String> buckets = Multimaps.index(strings, hashMethod); List<Map.Entry<Integer, Collection<String>>> sorted = Ordering.natural() .onResultOf(new Function<Map.Entry<Integer, Collection<String>>, Integer>() { @Override public Integer apply(Map.Entry<Integer, Collection<String>> entry) { return entry.getKey(); } }).immutableSortedCopy(buckets.asMap().entrySet()); int sortedHashes[] = new int[sorted.size()]; List<String> sortedCases[] = new List[sorted.size()]; int index = 0; for (Map.Entry<Integer, Collection<String>> entry : sorted) { sortedHashes[index] = entry.getKey(); sortedCases[index] = Lists.newCopyOnWriteArrayList(entry.getValue()); index++; } // Label for each hash and for default. Label labels[] = new Label[sorted.size()]; Label defaultLabel = new Label(); for (int i = 0; i < sorted.size(); ++i) { labels[i] = new Label(); } // Create a switch that dispatches to each label from the hash code of mv.visitLookupSwitchInsn(defaultLabel, sortedHashes, labels); // Create the cases. for (int i = 0; i < sorted.size(); ++i) { mv.visitLabel(labels[i]); visitx(mv, sortedCases[i]); } mv.visitLabel(defaultLabel); visitDefault(); }
From source file:com.mastfrog.acteur.sse.EventSink.java
public synchronized EventSink register(EventChannelName name, Channel channel) { if (!shutdown && channel.isOpen()) { channels.add(channel);/*from w w w . j av a 2s . co m*/ List<Channel> chlls = channelsForName.get(name); if (chlls == null) { chlls = Lists.newCopyOnWriteArrayList(Arrays.asList(channel)); channelsForName.put(name, chlls); } else { chlls.add(channel); } channel.closeFuture().addListener(new RemoveListener(name)); register(channel); } return this; }
From source file:org.xlrnet.tibaija.memory.DefaultCalculatorMemory.java
/** * Sets a single element within an existing list variable. If the targetted index is exactly one higher than the * size of the existing list, then the element will be appended at the end of the list. The first index is always * one and not zero! If the target list doesn't exist, an UndefinedVariableException will be thrown unless the * index/*from w ww . j a v a 2s. c om*/ * is one - then a new list will be created. * * @param listVariable * The variable to which the value should be written. * @param index * Index of the element inside the list. First index is always one. If the dimension is either to big or * too * low, an {@link org.xlrnet.tibaija.exception.InvalidDimensionException} will be thrown. * @param value * The new value for the element at the given index. */ @Override public void setListVariableElementValue(@NotNull ListVariable listVariable, int index, @NotNull Value value) { if (!listVariableValueMap.containsKey(listVariable) && index != 1) throw new UndefinedVariableException(listVariable); Value listValue = listVariableValueMap.get(listVariable); if (listValue == null) listValue = Value.EMPTY_LIST; if (index <= 0 || index > listValue.list().size() + 1) throw new InvalidDimensionException("Invalid index: " + index, index); Complex complex = value.complex(); List<Complex> modifiableList = Lists.newCopyOnWriteArrayList(listValue.list()); if (index == modifiableList.size() + 1) { modifiableList.add(complex); listVariableValueMap.put(listVariable, Value.of(modifiableList)); LOGGER.debug("Appended element {} to list {} at index {}", complex, listVariable, index); } else { modifiableList.set(index - 1, complex); listVariableValueMap.put(listVariable, Value.of(modifiableList)); LOGGER.debug("Set element {} at index {} of list {}", complex, index, listVariable); } }