List of usage examples for java.util LinkedHashSet LinkedHashSet
public LinkedHashSet()
From source file:locksdemo.RedisLockService.java
@Override public Iterable<Lock> findAll() { Set<String> keys = redisOperations.keys(prefix + "*"); Set<Lock> locks = new LinkedHashSet<Lock>(); for (String key : keys) { Date expires = new Date( System.currentTimeMillis() + redisOperations.getExpire(key, TimeUnit.MILLISECONDS)); locks.add(new Lock(nameForKey(key), redisOperations.opsForValue().get(key), expires)); }/*from ww w . j a v a 2 s . c o m*/ return locks; }
From source file:com.jaeksoft.searchlib.spellcheck.SpellCheck.java
public SpellCheck(ReaderLocal reader, SpellCheckRequest request, SpellCheckField spellCheckField) throws ParseException, SyntaxError, IOException, SearchLibException { fieldName = spellCheckField.getName(); SpellChecker spellchecker = reader.getSpellChecker(fieldName); Set<String> wordSet = new LinkedHashSet<String>(); Set<Term> set = request.getTermSet(spellCheckField.getName()); for (Term term : set) if (term.field().equals(fieldName)) wordSet.add(term.text());/*from w w w. j av a2 s . c o m*/ int suggestionNumber = spellCheckField.getSuggestionNumber(); float minScore = spellCheckField.getMinScore(); synchronized (spellchecker) { spellchecker.setAccuracy(minScore); spellchecker.setStringDistance(spellCheckField.getStringDistance().getNewInstance()); spellCheckItems = new ArrayList<SpellCheckItem>(); for (String word : wordSet) { String[] suggestions = spellchecker.suggestSimilar(word, suggestionNumber); int s = 1; if (suggestions != null) s += suggestions.length; SuggestionItem[] suggestionItems = new SuggestionItem[s]; int i = 0; suggestionItems[i++] = new SuggestionItem(word); if (suggestions != null) { for (String suggestion : suggestions) suggestionItems[i++] = new SuggestionItem(suggestion); spellCheckItems.add(new SpellCheckItem(word, suggestionItems)); } } } List<String> highers = new ArrayList<String>(spellCheckItems.size()); for (SpellCheckItem spellcheckItem : spellCheckItems) { spellcheckItem.computeFrequency(reader, fieldName); String higher = spellcheckItem.getHigher(); if (higher != null) highers.add(higher); } suggestion = StringUtils.join(highers, ' '); }
From source file:com.haulmont.cuba.gui.data.impl.EntityCopyUtils.java
public static void copyCompositions(Entity source, Entity dest) { Preconditions.checkNotNullArgument(source, "source is null"); Preconditions.checkNotNullArgument(dest, "dest is null"); if (source instanceof BaseDbGeneratedIdEntity && dest instanceof BaseDbGeneratedIdEntity) { ((BaseDbGeneratedIdEntity) dest).setId(((BaseDbGeneratedIdEntity) source).getId()); }/* w ww. j a v a 2 s .com*/ for (MetaProperty srcProperty : source.getMetaClass().getProperties()) { String name = srcProperty.getName(); MetaProperty dstProperty = dest.getMetaClass().getProperty(name); if (dstProperty != null && !dstProperty.isReadOnly()) { try { Object value = source.getValue(name); if (value != null && srcProperty.getRange().getCardinality().isMany() && srcProperty.getType() == MetaProperty.Type.COMPOSITION) { //noinspection unchecked Collection<Entity> srcCollection = (Collection) value; // Copy first to a Set to remove duplicates that could be created on repeated editing newly // added items Collection<Entity> tmpCollection = new LinkedHashSet<>(); for (Entity item : srcCollection) { Entity copy = copyCompositions(item); tmpCollection.add(copy); } Collection<Entity> dstCollection; if (value instanceof List) dstCollection = new ArrayList<>(tmpCollection); else dstCollection = tmpCollection; dest.setValue(name, dstCollection); } else { dest.setValue(name, source.getValue(name)); } } catch (RuntimeException e) { Throwable cause = ExceptionUtils.getRootCause(e); if (cause == null) cause = e; // ignore exception on copy for not loaded fields if (!isNotLoadedAttributeException(cause)) throw e; } } } if (source instanceof BaseGenericIdEntity && dest instanceof BaseGenericIdEntity) { BaseGenericIdEntity destGenericEntity = (BaseGenericIdEntity) dest; BaseGenericIdEntity<?> sourceGenericEntity = (BaseGenericIdEntity<?>) source; BaseEntityInternalAccess.setDetached(destGenericEntity, BaseEntityInternalAccess.isDetached(sourceGenericEntity)); BaseEntityInternalAccess.setNew(destGenericEntity, BaseEntityInternalAccess.isNew(sourceGenericEntity)); destGenericEntity.setDynamicAttributes(sourceGenericEntity.getDynamicAttributes()); } }
From source file:facebook4j.TargetingParameter.java
public TargetingParameter country(String country) { if (countries == null) { countries = new LinkedHashSet<String>(); }//from w w w.j a v a 2s .co m countries.add(country); return this; }
From source file:mondrian.util.ServiceDiscovery.java
/** * Returns a list of classes that implement the service. * * @return List of classes that implement the service *///w w w . ja v a2 s. c o m public List<Class<T>> getImplementor() { // Use linked hash set to eliminate duplicates but still return results // in the order they were added. Set<Class<T>> uniqueClasses = new LinkedHashSet<Class<T>>(); ClassLoader cLoader = Thread.currentThread().getContextClassLoader(); if (cLoader == null) { cLoader = this.getClass().getClassLoader(); } try { // Enumerate the files because I may have more than one .jar file // that contains an implementation for the interface, and therefore, // more than one list of entries. String lookupName = "META-INF/services/" + theInterface.getName(); Enumeration<URL> urlEnum = cLoader.getResources(lookupName); while (urlEnum.hasMoreElements()) { URL resourceURL = urlEnum.nextElement(); InputStream is = null; try { is = resourceURL.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); // read each class and parse it String clazz; while ((clazz = reader.readLine()) != null) { parseImplementor(clazz, cLoader, uniqueClasses); } } catch (IOException e) { logger.warn("Error while finding service file " + resourceURL + " for " + theInterface, e); } finally { if (is != null) { is.close(); } } } } catch (IOException e) { logger.warn("Error while finding service files for " + theInterface, e); } List<Class<T>> rtn = new ArrayList<Class<T>>(); rtn.addAll(uniqueClasses); return rtn; }
From source file:com.phoenixnap.oss.ramlapisync.style.checkers.ResourceUrlStyleChecker.java
@Override public Set<StyleIssue> checkResourceStyle(String name, Resource resource, IssueLocation location) { logger.debug("Checking resource " + name); Set<StyleIssue> issues = new LinkedHashSet<>(); if (!NamingHelper.isUriParamResource(name) && CHARS_NOT_ALLOWED.matcher(name).find()) { issues.add(new StyleIssue(location, SPECIAL_CHARS_IN_URL, resource, null)); }//ww w. j a v a 2s . c o m if (CharUtils.isAsciiAlphaUpper(name.charAt(0))) { issues.add(new StyleIssue(location, CAPITALISED_RESOURCE, resource, null)); } return issues; }
From source file:com.joliciel.talismane.filters.RollingSentenceProcessorImplTest.java
@Test public void testAddNextSegment() { FilterService filterService = new FilterServiceImpl(); RollingSentenceProcessorImpl processor = new RollingSentenceProcessorImpl(""); processor.setFilterService(filterService); final Set<TextMarker> textMarkers = new LinkedHashSet<TextMarker>(); new NonStrictExpectations() { TextMarker textMarker1, textMarker2; {/*from w w w.j a va 2 s. co m*/ textMarker1.getType(); returns(TextMarkerType.PUSH_SKIP); textMarker1.getPosition(); returns(6); textMarker2.getType(); returns(TextMarkerType.POP_SKIP); textMarker2.getPosition(); returns(9); textMarkers.add(textMarker1); textMarkers.add(textMarker2); } }; SentenceHolder holder = processor.addNextSegment("Hello <b>World", textMarkers); assertEquals("Hello World", holder.getText()); // up to World we have no text to skip assertEquals("Hello".length(), holder.getOriginalIndex("Hello".length())); // World starts at index 7 assertEquals("Hello <b>W".length(), holder.getOriginalIndex("Hello W".length())); // no segments marked for output assertEquals(0, holder.getOriginalTextSegments().size()); }
From source file:com.addthis.hydra.job.HostFailState.java
public HostFailState(Spawn spawn) { this.spawn = spawn; failFsDead = new LinkedHashSet<>(); failFsOkay = new LinkedHashSet<>(); fsFull = new LinkedHashSet<>(); hostsToFailByType = ImmutableMap.of(FailState.FAILING_FS_DEAD, failFsDead, FailState.DISK_FULL, fsFull, FailState.FAILING_FS_OKAY, failFsOkay); }
From source file:de.vandermeer.skb.interfaces.messagesets.IsWarningSetFT.java
/** * Creates a new warning set./*from w ww .j av a 2s . co m*/ * @return new warning set */ static IsWarningSetFT create() { return new IsWarningSetFT() { final Set<FormattingTuple> warningSet = new LinkedHashSet<>(); @Override public Set<FormattingTuple> getWarningMessages() { return this.warningSet; } }; }
From source file:net.jazdw.rql.parser.listfilter.ListFilter.java
@SuppressWarnings("unchecked") @Override//www .j av a2 s .c o m public List<T> visit(ASTNode node, List<T> list) { switch (node.getName()) { case "and": for (Object obj : node) { if (obj instanceof ASTNode) { list = ((ASTNode) obj).accept(this, list); } else { throw new UnsupportedOperationException("Encountered a non-ASTNode argument in AND statement"); } } return list; case "or": Set<T> set = new LinkedHashSet<T>(); for (Object obj : node) { if (obj instanceof ASTNode) { set.addAll(((ASTNode) obj).accept(this, list)); } else { throw new UnsupportedOperationException("Encountered a non-ASTNode argument in OR statement"); } } return new ArrayList<>(set); case "eq": case "gt": case "ge": case "lt": case "le": case "ne": String propName = (String) node.getArgument(0); Object test = node.getArgumentsSize() > 1 ? node.getArgument(1) : null; List<T> result = new ArrayList<>(); for (T item : list) { Object property = getProperty(item, propName); Comparable<Object> comparableProperty; if (property instanceof Comparable) { comparableProperty = (Comparable<Object>) property; } else { throw new UnsupportedOperationException( String.format("Property '%s' is not comparable", propName)); } int comparisonValue; try { comparisonValue = comparableProperty.compareTo(test); } catch (ClassCastException e) { throw new UnsupportedOperationException( String.format("Couldn't compare '%s' to '%s'", property.toString(), test.toString())); } if (checkComparisonValue(node.getName(), comparisonValue)) { result.add(item); } } return result; case "like": case "match": propName = (String) node.getArgument(0); String matchString = (String) node.getArgument(1); Pattern matchPattern = Pattern.compile(matchString.replace("*", ".*"), Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); result = new ArrayList<>(); for (T item : list) { Object property = getProperty(item, propName); String stringProperty; if (property instanceof String) { stringProperty = (String) property; } else { throw new UnsupportedOperationException( String.format("Property '%s' is not a string", propName)); } if (matchPattern.matcher(stringProperty).matches()) { result.add(item); } } return result; case "limit": int limit = (int) node.getArgument(0); int offset = node.getArgumentsSize() > 1 ? (int) node.getArgument(1) : 0; if (offset > list.size() - 1) { return Collections.emptyList(); } int toIndex = offset + limit; if (toIndex > list.size()) { toIndex = list.size(); } return list.subList(offset, toIndex); case "sort": ComparatorChain cc = new ComparatorChain(); for (Object obj : node) { String sortOption = (String) obj; boolean desc = sortOption.startsWith("-"); cc.addComparator(new BeanComparator<T>(sortOption.substring(1)), desc); } // copy the list as we are modifying it list = new ArrayList<>(list); Collections.sort(list, cc); return list; default: throw new UnsupportedOperationException( String.format("Encountered unknown operator '%s'", node.getName())); } }