List of usage examples for com.google.common.collect Sets newHashSet
public static <E> HashSet<E> newHashSet(Iterator<? extends E> elements)
From source file:com.jcjolley.maze.Maze.java
/** * Creates a well formed maze.//ww w . j a v a2 s. c om * * @param size * @return */ public static Maze create(int size) { if (rng == null) { rng = new Random(); } Maze m = new Maze(); m.entrance = new Node.Builder(Pos.create(0, 0)).entrance().build(); Set<Pos> markedPositions = Sets.newHashSet(m.entrance.getPos()); Node lastNode = m.entrance; m.size = size; //build the path from the entrance to the exit lastNode = createPath(lastNode, markedPositions, (int) (size * (size * .15)), size); //setup the exit lastNode.setExit(true); m.exit = lastNode; //randomly build branching paths throughout the maze for (int i = 0; i < (int) (size / 10); i++) { m.getNodes().forEach(n -> { if (rng.nextInt(10) == 1) { createPath(n, markedPositions, (int) (size / 3), size); } }); } //connect adjacent nodes. connectAdjacentNodes(m, markedPositions); //reject and recreate the maze if it's too small. if (markedPositions.size() < (size * (size * .25)) || m.getShortestPath(m.entrance, m.exit).size() < size) { m = Maze.create(size); } return m; }
From source file:org.eclipse.incquery.runtime.base.api.filters.SimpleBaseIndexFilter.java
/** * Creates a filter using a collection of (Resource and) Notifier instances. Every containment subtree, selected by * the given Notifiers are filtered out. * /*from w w w . j a v a2s .c om*/ * @param filterConfiguration */ public SimpleBaseIndexFilter(Collection<Notifier> filterConfiguration) { filters = Sets.newHashSet(filterConfiguration); }
From source file:org.wikimedia.cassandra.metrics.service.InstanceCache.java
Collection<Discovery.Jvm> discover() throws IOException { Map<String, Discovery.Jvm> discovered = new Discovery().getJvms(); Set<Entry<String, Discovery.Jvm>> toAdd = Sets.newHashSet(discovered.entrySet()); toAdd.removeAll(cache.entrySet());//from ww w . ja v a 2s .c om // Return only the delta. List<Discovery.Jvm> r = Lists.newArrayList(); for (Entry<String, Discovery.Jvm> e : toAdd) r.add(e.getValue()); return r; }
From source file:com.siemens.sw360.commonIO.TypeMappings.java
public static <T, U> ImmutableList<T> getElementsWithIdentifiersNotInMap(Function<T, U> getIdentifier, Map<U, T> theMap, List<T> candidates) { return FluentIterable.from(candidates).filter( CommonUtils.afterFunction(getIdentifier).is(containedWithAddIn(Sets.newHashSet(theMap.keySet())))) .toList();// www. j a v a 2 s .c om }
From source file:com.tealcube.minecraft.bukkit.mythicdrops.utils.ChatColorUtil.java
public static ChatColor getRandomChatColorWithoutColors(ChatColor... colors) { Set<ChatColor> colors1 = Sets.newHashSet(ChatColor.values()); for (ChatColor c : colors) { if (colors1.contains(c)) { colors1.remove(c);/*from w w w.j a v a 2 s. co m*/ } } return getRandomChatColorFromSet(colors1); }
From source file:org.elasticsearch.test.rest.support.FileUtils.java
/** * Returns the json files found within the directory provided as argument. * Files are looked up in the classpath first, then outside of it if not found. *//*w w w . j a v a 2 s. c om*/ public static Set<File> findJsonSpec(String optionalPathPrefix, String path) throws FileNotFoundException { File dir = resolveFile(optionalPathPrefix, path, null); if (!dir.isDirectory()) { throw new FileNotFoundException("file [" + path + "] is not a directory"); } File[] jsonFiles = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(JSON_SUFFIX); } }); if (jsonFiles == null || jsonFiles.length == 0) { throw new FileNotFoundException("no json files found within [" + path + "]"); } return Sets.newHashSet(jsonFiles); }
From source file:org.esupportail.publisher.domain.enums.StringListConverter.java
@Override public Set convertToEntityAttribute(String joined) { return Sets.newHashSet(Arrays.asList(joined.split(",")).iterator()); }
From source file:pl.edu.icm.cermine.tools.distance.FeatureVectorEuclideanMetric.java
@Override public double getDistance(FeatureVector vector1, FeatureVector vector2) { double sum = 0; List<String> featureNames1 = vector1.getFeatureNames(); List<String> featureNames2 = vector2.getFeatureNames(); if (Sets.newHashSet(featureNames1).equals(Sets.newHashSet(featureNames2))) { for (String feature : featureNames1) { sum += Math.pow(vector1.getValue(feature) - vector2.getValue(feature), 2); }//from w w w . ja va2 s . c om } else { for (int i = 0; i < vector1.size(); i++) { sum += Math.pow(vector1.getValue(i) - vector2.getValue(i), 2); } } return Math.sqrt(sum); }
From source file:org.gradoop.flink.model.impl.operators.subgraph.functions.LabelIsIn.java
/** * Constructor. * @param labels white list of labels */ public LabelIsIn(String... labels) { this.labels = Sets.newHashSet(labels); }
From source file:org.shaf.shell.action.AbstractAction.java
protected final boolean isProcessAvailable(final ActionContext context, final String command) throws ClientException { return Sets.newHashSet(context.getController().listProcesses().getTable().getColumn(0)).contains(command); }