public QuerySpec withQueryFilters(QueryFilter... queryFilters) { if (queryFilters == null) { this.queryFilters = null; } else { Set<String> names = new LinkedHashSet<String>(); for (QueryFilter e : queryFilters) { names.add(e.getAttribute()); } if (names.size() != queryFilters.length) { throw new IllegalArgumentException( "attribute names must not duplicate in the list of query filters"); } this.queryFilters = Arrays.asList(queryFilters); } return this; }
protected T withCollectionParam(final String name, final Object value) { // Sanity test, if we got passed null, we should remove the collection if (value == null) { // This should remove it. return setParam(name, null); } // Sanity test, if we got passed a collection, we should handle it gracefully. if (value instanceof Collection) { return withCollectionParams(name, (Collection) value); } Collection<Object> existingValues = getParam(name); if (existingValues == null) { // Using linked hash set to preserve ordering. existingValues = new LinkedHashSet<>(); } existingValues.add(value); return setParam(name, existingValues); }
/** * Calculates the top event of the {@link BDD} based on a functionTransformer that delivers for each variable * {@code T} a double value. * * @param <T> * the type of variable * @param bdd * the bdd * @param transformer * the transformer that returns a double value for each variable * @return the top event of the bdd */ public static <T> double calculateTop(BDD<T> bdd, Transformer<T, Double> transformer) { if (bdd.isOne()) { return 1.0; } if (bdd.isZero()) { return 0.0; } Set<BDD<T>> upSort = new LinkedHashSet<>(); traverseBDD(bdd, upSort); double top = evaluate(bdd, transformer, upSort); for (BDD<T> ups : upSort) { ups.free(); } return top; }
@Override public Set<NitriteId> apply(final NitriteMap<NitriteId, Document> documentMap) { Set<NitriteId> result = new LinkedHashSet<>(); ExecutorService executorService = nitriteService.getNitriteContext().getWorkerPool(); try { List<Callable<Set<NitriteId>>> tasks = createTasks(filters, documentMap); List<Future<Set<NitriteId>>> futures = executorService.invokeAll(tasks); for (Future<Set<NitriteId>> future : futures) { Set<NitriteId> nitriteIds = future.get(); if (nitriteIds != null) { result.addAll(nitriteIds); } } } catch (FilterException fe) { throw fe; } catch (Throwable t) { throw new FilterException(INVALID_OR_FILTER, t); } return result; }
private static List<Vector3> doFindVector3s(final Scene scene) { final Set<Vector3> vector3s = new LinkedHashSet<>(); for(final Shape shape : scene.getShapes()) { if(shape instanceof Plane) { final Plane plane = Plane.class.cast(shape); final Vector3 surfaceNormal = plane.getSurfaceNormal(); vector3s.add(surfaceNormal); } else if(shape instanceof Triangle) { final Triangle triangle = Triangle.class.cast(shape); final Vector3 a = triangle.getA().getNormal(); final Vector3 b = triangle.getB().getNormal(); final Vector3 c = triangle.getC().getNormal(); vector3s.add(a); vector3s.add(b); vector3s.add(c); } } return new ArrayList<>(vector3s); }
@Test public void zrangeByLex() { jedis.zadd("foo", 1, "aa"); jedis.zadd("foo", 1, "c"); jedis.zadd("foo", 1, "bb"); jedis.zadd("foo", 1, "d"); Set<String> expected = new LinkedHashSet<String>(); expected.add("bb"); expected.add("c"); // exclusive aa ~ inclusive c assertEquals(expected, jedis.zrangeByLex("foo", "(aa", "[c")); expected.clear(); expected.add("bb"); expected.add("c"); // with LIMIT assertEquals(expected, jedis.zrangeByLex("foo", "-", "+", 1, 2)); }
/** * Get child users of this group * @param paging Paging object with max number to return, and items to skip * @param sortBy What to sort on (authorityName, shortName or displayName) */ public ScriptUser[] getChildUsers(ScriptPagingDetails paging, String sortBy) { if (childUsers == null) { Set<String> children = getChildNamesOfType(AuthorityType.USER); Set<ScriptUser> users = new LinkedHashSet<ScriptUser>(); for (String authority : children) { ScriptUser user = new ScriptUser(authority, null, serviceRegistry, this.scope); users.add(user); } childUsers = users.toArray(new ScriptUser[users.size()]); } return makePagedAuthority(paging, sortBy, childUsers); }
/** * Returns the AlloyType corresponding to the given sig; create an AlloyType * for it if none existed before. */ private void sigMETA(SubsetSig s) throws Err { AlloyAtom atom; AlloyType type = sig2type.get(s); if (type != null) return; type = makeType(s.label, s.isOne != null, s.isAbstract != null, false, s.isPrivate != null, s.isMeta != null, s.isEnum != null); atom = new AlloyAtom(type, Integer.MAX_VALUE, s.label); atom2sets.put(atom, new LinkedHashSet<AlloySet>()); sig2atom.put(s, atom); sig2type.put(s, type); ts.put(type, AlloyType.SET); for (Sig p : ((SubsetSig) s).parents) { if (p instanceof SubsetSig) sigMETA((SubsetSig) p); else sigMETA((PrimSig) p); ins.add(new AlloyTuple(atom, sig2atom.get(p))); } }
private ClassPath getToolingImpl() { if (!gradleHomeDir.exists()) { throw new IllegalArgumentException(String.format("The specified %s does not exist.", locationDisplayName)); } if (!gradleHomeDir.isDirectory()) { throw new IllegalArgumentException(String.format("The specified %s is not a directory.", locationDisplayName)); } File libDir = new File(gradleHomeDir, "lib"); if (!libDir.isDirectory()) { throw new IllegalArgumentException(String.format("The specified %s does not appear to contain a Gradle distribution.", locationDisplayName)); } LinkedHashSet<File> files = new LinkedHashSet<File>(); for (File file : libDir.listFiles()) { if (hasExtension(file, ".jar")) { files.add(file); } } return new DefaultClassPath(files); }
/** Returns every top-level user type that is itself visible or has a visible subtype. * @param vizState */ static Set<AlloyType> partiallyVisibleUserTopLevelTypes(final VizState vizState) { final AlloyModel model = vizState.getOriginalModel(); final Set<AlloyType> visibleUserTypes = visibleUserTypes(vizState); //final Set<AlloyType> topLevelTypes = topLevelTypes(vizState); final Set<AlloyType> result = new LinkedHashSet<AlloyType>(); for (final AlloyType t : visibleUserTypes) { if (visibleUserTypes.contains(t)) { result.add(model.getTopmostSuperType(t)); } } return Collections.unmodifiableSet(result); }
/** * Stores the Array in static for username + connectionId * * @param array * the Array to store */ public void put(Array array) { debug("Creating an array for user: " + connectionKey); if (array == null) { throw new IllegalArgumentException("array is null!"); } Set<Array> arraySet = arrayMap.get(connectionKey); if (arraySet == null) { arraySet = new LinkedHashSet<Array>(); } arraySet.add(array); arrayMap.put(connectionKey, arraySet); }
/** * Makes a deep copy (for security) */ public Base deepClone() { Base newBase = new Base(getPosition().deepCopy(), teamName, team.deepCopy(), isHomeBase); newBase.energy = energy; newBase.setAlive(isAlive); newBase.id = id; newBase.maxEnergy = maxEnergy; newBase.currentPowerups = new LinkedHashSet<SpaceSettlersPowerupEnum>(currentPowerups); newBase.weaponCapacity = weaponCapacity; newBase.healingIncrement = healingIncrement; newBase.resources = new ResourcePile(); newBase.resources.add(resources); newBase.numFlags = numFlags; return newBase; }
/** * Return an unordered set all the foreign key ancestor tables for the given table * @param catalog_tbl */ public Collection<Table> getAncestors(Table catalog_tbl) { Database catalog_db = (Database) catalog_tbl.getParent(); Set<Table> ret = new LinkedHashSet<Table>(); String key = CatalogKey.createKey(catalog_tbl); for (String ancestor_key : this.table_ancestors.get(key)) { // If this table is missing from the catalog, then we want to stop // the ancestor list Table ancestor_tbl = CatalogKey.getFromKey(catalog_db, ancestor_key, Table.class); if (ancestor_tbl == null) break; // Otherwise, add it to our list ret.add(ancestor_tbl); } // FOR return (ret); }
public Set<String> getAndRemZRange(String key, long score) { Jedis jedis = null; try { jedis = pool.getResource(); Transaction trans = jedis.multi(); trans.zrangeByScore(key.getBytes(), MIN_INF, SafeEncoder.encode(String.valueOf(score))); trans.zremrangeByScore(key.getBytes(), MIN_INF, SafeEncoder.encode(String.valueOf(score))); List<Object> response = trans.exec(); Set<byte[]> data = (Set<byte[]>) response.get(0); Set<String> members = new LinkedHashSet<>(data.size()); for (byte[] d : data) { members.add(new String(d)); } pool.returnResource(jedis); return members; } catch (Exception e) { LOGGER.warn("Failed to get zrem keys from cache {0}:{1}", key, score, e); pool.returnBrokenResource(jedis); throw e; } }
private synchronized Collection<AntLogger> getInterestedLoggersByTask(String task) { Collection<AntLogger> c = interestedLoggersByTask.get(task); if (c == null) { c = new LinkedHashSet<AntLogger>(interestedLoggers.size()); interestedLoggersByTask.put(task, c); for (AntLogger l : interestedLoggers) { String[] tasks = l.interestedInTasks(thisSession); if (tasks == AntLogger.ALL_TASKS || (task != null && Arrays.asList(tasks).contains(task)) || (task == null && tasks == AntLogger.NO_TASKS)) { c.add(l); } } LOG.log(Level.FINEST, "getInterestedLoggersByTask: task={0} loggers={1}", new Object[] {task, c}); } return c; }
@SuppressWarnings("unchecked") public Set<String> build(Object data) { if (null == data) { return null; } List<byte[]> l = (List<byte[]>) data; final Set<String> result = new LinkedHashSet<String>(l.size()); for (final byte[] barray : l) { if (barray == null) { result.add(null); } else { result.add(SafeEncoder.encode(barray)); } } return result; }
public void unregisterThrower(Class<?> interfaceClass, IEventThrower<?> thrower, boolean keepSubscribers){ synchronized (EVENT_THROWERS) { if(EVENT_THROWERS.containsKey(interfaceClass)){ LinkedHashSet<IEventThrower<?>> list = EVENT_THROWERS.get(interfaceClass); if(keepSubscribers){ Queue<Object> toKeep = new ArrayDeque<>(); Iterator<?> subscribers = thrower.getSubscribers(); while(subscribers.hasNext()){ Object listener = subscribers.next(); toKeep.add(listener); } if(!QUEUED_LISTENERS.containsKey(interfaceClass)){ QUEUED_LISTENERS.put(interfaceClass, toKeep); } }else{ thrower.clearSubscribers(); } list.remove(thrower); if(list.isEmpty()){ EVENT_THROWERS.remove(interfaceClass); } } } }
private void loadAll() { mFiles = new LinkedHashSet<String>(); mDirs = new LinkedHashMap<String, AbstractDirectory>(); File[] files = getDir().listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isFile()) { mFiles.add(file.getName()); } else { // IMPOSSIBLE_EXCEPTION try { mDirs.put(file.getName(), new FileDirectory(file)); } catch (DirectoryException e) {} } } }
/** * Stores the Savepoint in static for username + connectionId * * @param savepoint * the Savepoint to store */ public void put(Savepoint savepoint) { debug("Creating a Savepoint for user: " + connectionKey); if (savepoint == null) { throw new IllegalArgumentException("savepoint is null!"); } Set<Savepoint> savepointSet = savepointMap.get(connectionKey); if (savepointSet == null) { savepointSet = new LinkedHashSet<Savepoint>(); } savepointSet.add(savepoint); savepointMap.put(connectionKey, savepointSet); }
/** * Returns the total number of annotations. */ int countAnnotations() { Set<Annotation> set = new LinkedHashSet<Annotation>(); for (Layer layer : layers.values()) set.addAll(layer); return set.size(); }
List getAopTypesValue(ConditionContext context){ String aopTypesKey = DruidStatProperties.DRUID_STAT_PREFIX+".aop-types"; Set<String> keySet = new LinkedHashSet<String>(); for (int i = 0; i <3 ; i++) { String field = context.getEnvironment().getProperty(aopTypesKey+"["+i+"]", String.class); if (!StringUtils.isEmpty(field)) keySet.add(field.toLowerCase()); } if (keySet.size() > 0 ){ return new ArrayList<String>(keySet); }else { return new ArrayList<String>(); } }
/** * Prunes the forest by making sure that every node is either * a root, or a child of exactly one parent. */ public void prune() { Collection<LayoutNode> remaining = one(); // Add real roots one by one List<LayoutNode> roots = new ArrayList<>(); while (!remaining.isEmpty()) { Iterator<LayoutNode> remainingIter = remaining.iterator(); LayoutNode root = remainingIter.next(); roots.add(root); remainingIter.remove(); // compute reachable children and take them from remaining candidate roots // also adjust the branch sets of the reachable leaves Set<LayoutNode> children = new LinkedHashSet<>(); children.add(root); while (!children.isEmpty()) { Iterator<LayoutNode> childIter = children.iterator(); LayoutNode child = childIter.next(); childIter.remove(); // look up the next generation Set<LayoutNode> branches = getBranches(child); // restrict to remaining layoutables branches.retainAll(remaining); children.addAll(branches); // remove the new branches from the remaining candidate roots remaining.removeAll(branches); } } setOne(roots); }
/** * 将字符串词性转为Enum词性 * @param name 词性名称 * @param customNatureCollector 一个收集集合 * @return 转换结果 */ public static Nature convertStringToNature(String name, LinkedHashSet<Nature> customNatureCollector) { try { return Nature.valueOf(name); } catch (Exception e) { Nature nature = CustomNatureUtility.addNature(name); if (customNatureCollector != null) customNatureCollector.add(nature); return nature; } }
/** * Geef de waarde van betrokkenheid set. * @param soortBetrokkenheid soort betrokkenheid * @return betrokkenheid set */ public Set<Betrokkenheid> getBetrokkenheidSet(final SoortBetrokkenheid soortBetrokkenheid) { final Set<Betrokkenheid> result = new LinkedHashSet<>(); for (final Betrokkenheid betrokkenheid : betrokkenheidSet) { if (soortBetrokkenheid.equals(betrokkenheid.getSoortBetrokkenheid())) { result.add(betrokkenheid); } } return result; }
/** * 去重提取 * * @param memberList * @return */ private Set<String> formatEmailDuplicateRemoval(List<Map<String, String>> memberList) { Set<String> emails = new LinkedHashSet<String>(); for (Map<String, String> map : memberList) { String emailList = map.get("emailList"); String[] splits = emailList.split(","); for (int i = 0; i < splits.length; i++) { emails.add(splits[i]); } } return emails; }
SymmInfo(int size) { this.parts = new LinkedHashSet<IntSet>(); for (int i = 0, max = size; i < max; i++) { parts.add(Ints.singleton(i)); } this.time = "t\\o"; this.symms = "t\\o"; }
public CommandRegistry(ConsoleLogger logger, Command[] commands) { this.logger = logger; this.commands = new LinkedHashSet<>(asList(commands)); this.commands.add(new ShowCommand(logger)); this.commands.add(new ExitCommand(logger)); this.commands.add(new ResetProgressionCommand(logger)); this.commands.add(this); }
private static Set<String> getModifiers(int flags, int[] modifierFlags, Kind t) { Set<String> s = new LinkedHashSet<>(); for (int m: modifierFlags) { if ((flags & m) != 0) s.add(flagToModifier(m, t)); } return s; }
private static List<Surface> doFindSurfaces(final Scene scene) { final Set<Surface> surfaces = new LinkedHashSet<>(); for(final Shape shape : scene.getShapes()) { final Surface surface = shape.getSurface(); surfaces.add(surface); } return new ArrayList<>(surfaces); }
/** * Obtain a resource object for the given name and type through autowiring * based on the given factory. * @param factory the factory to autowire against * @param element the descriptor for the annotated field/method * @param requestingBeanName the name of the requesting bean * @return the resource object (never {@code null}) * @throws BeansException if we failed to obtain the target resource */ protected Object autowireResource(BeanFactory factory, LookupElement element, String requestingBeanName) throws BeansException { Object resource; Set<String> autowiredBeanNames; String name = element.name; if (this.fallbackToDefaultTypeMatch && element.isDefaultName && factory instanceof AutowireCapableBeanFactory && !factory.containsBean(name)) { autowiredBeanNames = new LinkedHashSet<String>(); resource = ((AutowireCapableBeanFactory) factory).resolveDependency( element.getDependencyDescriptor(), requestingBeanName, autowiredBeanNames, null); } else { resource = factory.getBean(name, element.lookupType); autowiredBeanNames = Collections.singleton(name); } if (factory instanceof ConfigurableBeanFactory) { ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) factory; for (String autowiredBeanName : autowiredBeanNames) { if (beanFactory.containsBean(autowiredBeanName)) { beanFactory.registerDependentBean(autowiredBeanName, requestingBeanName); } } } return resource; }
private void setTagApps(List<AppAndTag> list, AppTopic topic) { Set<TagApps> tagApps = new LinkedHashSet<TagApps>(); for (AppAndTag appAndTag : list) { if (topic.getId() == appAndTag.getTag().getId()) { tagApps.add(new TagApps(appAndTag.getId(), appAndTag.getRank(), "", appAndTag.getApp())); } } topic.setTagApps(tagApps); }
/** Returns all of the top-level types in the original model. * @param vizState */ static Set<AlloyType> topLevelTypes(final VizState vizState) { final Set<AlloyType> result = new LinkedHashSet<AlloyType>(); final AlloyModel model = vizState.getOriginalModel(); for (final AlloyType t : model.getTypes()) { if (vizState.isTopLevel(t)) { result.add(t); } } return Collections.unmodifiableSet(result); }
@Test public void zrangeWithScores() { jedis.zadd("foo", 1d, "a"); jedis.zadd("foo", 10d, "b"); jedis.zadd("foo", 0.1d, "c"); jedis.zadd("foo", 2d, "a"); Set<Tuple> expected = new LinkedHashSet<Tuple>(); expected.add(new Tuple("c", 0.1d)); expected.add(new Tuple("a", 2d)); Set<Tuple> range = jedis.zrangeWithScores("foo", 0, 1); assertEquals(expected, range); expected.add(new Tuple("b", 10d)); range = jedis.zrangeWithScores("foo", 0, 100); assertEquals(expected, range); // Binary jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bfoo, 0.1d, bc); jedis.zadd(bfoo, 2d, ba); Set<Tuple> bexpected = new LinkedHashSet<Tuple>(); bexpected.add(new Tuple(bc, 0.1d)); bexpected.add(new Tuple(ba, 2d)); Set<Tuple> brange = jedis.zrangeWithScores(bfoo, 0, 1); assertEquals(bexpected, brange); bexpected.add(new Tuple(bb, 10d)); brange = jedis.zrangeWithScores(bfoo, 0, 100); assertEquals(bexpected, brange); }
public SearchLayer addIgnored(String first, String... rest) { if (this.ignored == null) { this.ignored = new LinkedHashSet<>(); } this.ignored.addAll(Lists.asList(first, rest)); return this; }
Set<File> getAllFiles () { if (allFiles == null) { allFiles = new LinkedHashSet<File> (); addFiles (loadPresistentState ()); } return allFiles; }
private LinkedHashSet<String> getPersistedCache() { String serialized = prefs.getString(EMOJI_LRU_PREFERENCE, "[]"); try { CollectionType collectionType = TypeFactory.defaultInstance() .constructCollectionType(LinkedHashSet.class, String.class); return JsonUtils.getMapper().readValue(serialized, collectionType); } catch (IOException e) { Log.w(TAG, e); return new LinkedHashSet<>(); } }
private static Collection<String> createRequestSubprotocols( Collection<String> subprotocols) { LinkedHashSet<String> sp = new LinkedHashSet<>(subprotocols.size(), 1); for (String s : subprotocols) { if (s.trim().isEmpty() || !isValidName(s)) { throw illegal("Bad subprotocol syntax: " + s); } if (!sp.add(s)) { throw illegal("Duplicating subprotocol: " + s); } } return Collections.unmodifiableCollection(sp); }
private String[] toReversePrimitiveArray(@NonNull LinkedHashSet<String> emojiSet) { String[] emojis = new String[emojiSet.size()]; int i = emojiSet.size() - 1; for (String emoji : emojiSet) { emojis[i--] = emoji; } return emojis; }
@Test public void zremrangeByScore() { jedis.zadd("foo", 1d, "a"); jedis.zadd("foo", 10d, "b"); jedis.zadd("foo", 0.1d, "c"); jedis.zadd("foo", 2d, "a"); long result = jedis.zremrangeByScore("foo", 0, 2); assertEquals(2, result); Set<String> expected = new LinkedHashSet<String>(); expected.add("b"); assertEquals(expected, jedis.zrange("foo", 0, 100)); // Binary jedis.zadd(bfoo, 1d, ba); jedis.zadd(bfoo, 10d, bb); jedis.zadd(bfoo, 0.1d, bc); jedis.zadd(bfoo, 2d, ba); long bresult = jedis.zremrangeByScore(bfoo, 0, 2); assertEquals(2, bresult); Set<byte[]> bexpected = new LinkedHashSet<byte[]>(); bexpected.add(bb); assertByteArraySetEquals(bexpected, jedis.zrange(bfoo, 0, 100)); }
/** * Retrieves all dependencies with given kind(s). */ protected Set<Node> getDependencies(DependencyKind... depKinds) { Set<Node> buf = new LinkedHashSet<Node>(); for (DependencyKind dk : depKinds) { Set<Node> depsByKind = deps.get(dk); if (depsByKind != null) { buf.addAll(depsByKind); } } return buf; }