List of usage examples for com.google.common.collect Sets newTreeSet
public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator)
From source file:org.fenixedu.qubdocs.academic.documentRequests.providers.ExtraCurricularCoursesDataProvider.java
public ExtraCurricularCoursesDataProvider(final Collection<? extends ICurriculumEntry> entries, final Locale locale, CurriculumEntryRemarksDataProvider remarks) { this.remarksDataProvider = remarks; this.locale = locale; this.includeAllRegistrations = false; this.includeSubstitutionCreditations = false; curriculumEntries = Sets.newTreeSet(CurriculumEntry.NAME_COMPARATOR(locale)); curriculumEntries.addAll(CurriculumEntry.transform(registration, entries, this.remarksDataProvider)); }
From source file:org.auraframework.components.perf.DependenciesController.java
@AuraEnabled public Map<String, Object> getDependencies(@Key("component") String component) { DefDescriptor<?> descriptor;//from w ww . ja v a2s . c o m SortedSet<DefDescriptor<?>> sorted; Map<String, Object> dependencies = Maps.newHashMap(); ArrayList<String> list = Lists.newArrayList(); String uid; int pos = component.indexOf("@"); if (pos != -1) { component = component.substring(0, pos); } DescriptorFilter filter = new DescriptorFilter(component, Lists.newArrayList(DefType.LIBRARY, DefType.COMPONENT, DefType.APPLICATION)); Set<DefDescriptor<?>> descriptors = definitionService.find(filter); if (descriptors.size() != 1) { return null; } descriptor = descriptors.iterator().next(); try { Definition def = definitionService.getDefinition(descriptor); if (def == null) { return null; } descriptor = def.getDescriptor(); uid = definitionService.getUid(null, descriptor); sorted = Sets.newTreeSet(definitionService.getDependencies(uid)); for (DefDescriptor<?> dep : sorted) { def = definitionService.getDefinition(dep); DefType type = dep.getDefType(); if (type != DefType.EVENT && type != DefType.COMPONENT && type != DefType.INTERFACE && type != DefType.LIBRARY || (def.getDescriptor().getNamespace().equals("aura") || def.getDescriptor().getNamespace().equals("auradev"))) { continue; } list.add(dep.toString() + "@" + dep.getDefType()); } dependencies.put("dependencies", list); dependencies.put("def", component); return dependencies; } catch (Throwable t) { return null; } }
From source file:org.fenixedu.qubdocs.academic.documentRequests.providers.ExtraCurricularActivitiesDataProvider.java
public Set<ExtraCurricularActivity> getActivities() { if (activities == null) { TreeSet<ExtraCurricularActivity> result = Sets.newTreeSet(EXTRA_CURRICULAR_ACTIVITY_COMPARATOR); for (ExtraCurricularActivity extraCurricularActivity : student.getExtraCurricularActivitySet()) { if (!interval.overlaps(extraCurricularActivity.getActivityInterval())) { continue; }/* w ww . ja va 2 s .c o m*/ result.add(extraCurricularActivity); } activities = result; } return activities; }
From source file:com.google.api.tools.framework.importers.swagger.aspects.type.TypeBuilder.java
@Override public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) { if (swagger.getDefinitions() == null) { return;//from ww w . j av a2 s . c o m } TreeSet<String> swaggerModelNames = Sets.newTreeSet(swagger.getDefinitions().keySet()); for (String swaggerModelName : swaggerModelNames) { addTypeFromModel(serviceBuilder, swaggerModelName, swagger.getDefinitions().get(swaggerModelName)); } }
From source file:org.obm.push.backend.CollectionChangeListener.java
private SortedSet<String> convertSetToComparePath(ChangedCollections changedCollections) { SortedSet<String> collectionPathSet = Sets.newTreeSet(new Comparator<String>() { @Override/*from w w w. j av a2 s .c o m*/ public int compare(String o1, String o2) { return ComparisonChain.start().compare(o1, o2).result(); } }); collectionPathSet.addAll(changedCollections.getChanges()); return collectionPathSet; }
From source file:com.google.api.explorer.client.auth.AuthPresenter.java
void clickExecuteAuth() { display.hideScopeDialog();// w w w .jav a2 s . c o m // Get and sort the list of scopes. Set<String> scopes = Sets.newTreeSet(display.getSelectedScopes()); // Inform analytics that a user is requesting auth. final String scopesString = Joiner.on("; ").join(scopes); analytics.trackEventWithValue(AnalyticsEvent.AUTH_REQUEST, scopesString); authManager.requestAuth(service, scopes, new AuthCompleteCallback() { @Override public void complete(AuthToken token) { analytics.trackEventWithValue(AnalyticsEvent.AUTH_TOKEN, scopesString); display.setState(State.PRIVATE, requiredScopes, token.getScopes()); } }); }
From source file:org.gradle.internal.component.AmbiguousConfigurationSelectionException.java
static void formatConfiguration(StringBuilder sb, AttributeContainer fromConfigurationAttributes, AttributesSchema consumerSchema, List<ConfigurationMetadata> matches, Set<String> requestedAttributes, int maxConfLength, final String conf) { Optional<ConfigurationMetadata> match = Iterables.tryFind(matches, new Predicate<ConfigurationMetadata>() { @Override//w w w . ja va2 s .c om public boolean apply(ConfigurationMetadata input) { return conf.equals(input.getName()); } }); if (match.isPresent()) { AttributeContainer producerAttributes = match.get().getAttributes(); Set<Attribute<?>> targetAttributes = producerAttributes.keySet(); Set<String> targetAttributeNames = Sets .newTreeSet(Iterables.transform(targetAttributes, ATTRIBUTE_NAME)); Set<Attribute<?>> allAttributes = Sets.union(fromConfigurationAttributes.keySet(), producerAttributes.keySet()); Set<String> commonAttributes = Sets.intersection(requestedAttributes, targetAttributeNames); Set<String> consumerOnlyAttributes = Sets.difference(requestedAttributes, targetAttributeNames); sb.append(" ").append("- Configuration '").append(StringUtils.rightPad(conf + "'", maxConfLength + 1)) .append(" :"); List<Attribute<?>> sortedAttributes = Ordering.usingToString().sortedCopy(allAttributes); List<String> values = new ArrayList<String>(sortedAttributes.size()); formatAttributes(sb, fromConfigurationAttributes, consumerSchema, producerAttributes, commonAttributes, consumerOnlyAttributes, sortedAttributes, values); } }
From source file:org.apache.tajo.util.history.HistoryReader.java
private synchronized List<QueryInfo> findQueryInfoInStorage(int page, int size, @Nullable QueryId queryId) throws IOException { List<QueryInfo> result = Lists.newLinkedList(); FileSystem fs = HistoryWriter.getNonCrcFileSystem(historyParentPath, tajoConf); try {//from w w w . j a va2 s .c o m if (!fs.exists(historyParentPath)) { return result; } } catch (Throwable e) { return result; } FileStatus[] files = fs.listStatus(historyParentPath); if (files == null || files.length == 0) { return result; } Set<QueryInfo> queryInfos = Sets.newTreeSet(Collections.reverseOrder()); int startIndex = page < 1 ? page : ((page - 1) * size) + 1; int currentIndex = 0; int skipSize = 0; ArrayUtils.reverse(files); for (FileStatus eachDateFile : files) { Path queryListPath = new Path(eachDateFile.getPath(), HistoryWriter.QUERY_LIST); if (eachDateFile.isFile() || !fs.exists(queryListPath)) { continue; } FileStatus[] dateFiles = fs.listStatus(queryListPath); if (dateFiles == null || dateFiles.length == 0) { continue; } ArrayUtils.reverse(dateFiles); for (FileStatus eachFile : dateFiles) { Path path = eachFile.getPath(); if (eachFile.isDirectory() || !path.getName().endsWith(HistoryWriter.HISTORY_FILE_POSTFIX)) { continue; } FSDataInputStream in = null; List<String> jsonList = Lists.newArrayList(); try { in = fs.open(path); //If history file does not close, FileStatus.getLen() are not being updated //So, this code block should check the EOFException while (true) { int length = in.readInt(); byte[] buf = new byte[length]; in.readFully(buf, 0, length); jsonList.add(new String(buf, 0, length, Bytes.UTF8_CHARSET)); currentIndex++; } } catch (EOFException eof) { } catch (Throwable e) { LOG.warn("Reading error:" + path + ", " + e.getMessage()); } finally { IOUtils.cleanup(LOG, in); } //skip previous page if (startIndex > currentIndex) { skipSize += jsonList.size(); } else { for (String json : jsonList) { QueryInfo queryInfo = QueryInfo.fromJson(json); if (queryId != null) { if (queryInfo.getQueryId().equals(queryId)) { result.add(queryInfo); return result; } } else { queryInfos.add(queryInfo); } } } if (currentIndex - (startIndex - 1) >= size) { result.addAll(queryInfos); int fromIndex = (startIndex - 1) - skipSize; return result.subList(fromIndex, fromIndex + size); } } } result.addAll(queryInfos); return result; }
From source file:io.druid.query.search.SearchQueryRunner.java
@Override public Sequence<Result<SearchResultValue>> run(final Query<Result<SearchResultValue>> input, Map<String, Object> responseContext) { if (!(input instanceof SearchQuery)) { throw new ISE("Got a [%s] which isn't a %s", input.getClass(), SearchQuery.class); }// w w w . j a v a 2 s. c om final SearchQuery query = (SearchQuery) input; final Filter filter = Filters.convertDimensionFilters(query.getDimensionsFilter()); final List<DimensionSpec> dimensions = query.getDimensions(); final SearchQuerySpec searchQuerySpec = query.getQuery(); final int limit = query.getLimit(); // Closing this will cause segfaults in unit tests. final QueryableIndex index = segment.asQueryableIndex(); if (index != null) { final TreeSet<SearchHit> retVal = Sets.newTreeSet(query.getSort().getComparator()); Iterable<DimensionSpec> dimsToSearch; if (dimensions == null || dimensions.isEmpty()) { dimsToSearch = Iterables.transform(index.getAvailableDimensions(), Druids.DIMENSION_IDENTITY); } else { dimsToSearch = dimensions; } final BitmapFactory bitmapFactory = index.getBitmapFactoryForDimensions(); final ImmutableBitmap baseFilter; if (filter == null) { baseFilter = bitmapFactory.complement(bitmapFactory.makeEmptyImmutableBitmap(), index.getNumRows()); } else { final ColumnSelectorBitmapIndexSelector selector = new ColumnSelectorBitmapIndexSelector( bitmapFactory, index); baseFilter = filter.getBitmapIndex(selector); } for (DimensionSpec dimension : dimsToSearch) { final Column column = index.getColumn(dimension.getDimension()); if (column == null) { continue; } final BitmapIndex bitmapIndex = column.getBitmapIndex(); ExtractionFn extractionFn = dimension.getExtractionFn(); if (extractionFn == null) { extractionFn = new IdentityExtractionFn(); } if (bitmapIndex != null) { for (int i = 0; i < bitmapIndex.getCardinality(); ++i) { String dimVal = Strings.nullToEmpty(extractionFn.apply(bitmapIndex.getValue(i))); if (searchQuerySpec.accept(dimVal) && bitmapFactory .intersection(Arrays.asList(baseFilter, bitmapIndex.getBitmap(i))).size() > 0) { retVal.add(new SearchHit(dimension.getOutputName(), dimVal)); if (retVal.size() >= limit) { return makeReturnResult(limit, retVal); } } } } } return makeReturnResult(limit, retVal); } final StorageAdapter adapter = segment.asStorageAdapter(); if (adapter == null) { log.makeAlert("WTF!? Unable to process search query on segment.") .addData("segment", segment.getIdentifier()).addData("query", query).emit(); throw new ISE( "Null storage adapter found. Probably trying to issue a query against a segment being memory unmapped."); } final Iterable<DimensionSpec> dimsToSearch; if (dimensions == null || dimensions.isEmpty()) { dimsToSearch = Iterables.transform(adapter.getAvailableDimensions(), Druids.DIMENSION_IDENTITY); } else { dimsToSearch = dimensions; } final Sequence<Cursor> cursors = adapter.makeCursors(filter, segment.getDataInterval(), QueryGranularity.ALL); final TreeSet<SearchHit> retVal = cursors.accumulate(Sets.newTreeSet(query.getSort().getComparator()), new Accumulator<TreeSet<SearchHit>, Cursor>() { @Override public TreeSet<SearchHit> accumulate(TreeSet<SearchHit> set, Cursor cursor) { if (set.size() >= limit) { return set; } Map<String, DimensionSelector> dimSelectors = Maps.newHashMap(); for (DimensionSpec dim : dimsToSearch) { dimSelectors.put(dim.getOutputName(), cursor.makeDimensionSelector(dim.getDimension(), dim.getExtractionFn())); } while (!cursor.isDone()) { for (Map.Entry<String, DimensionSelector> entry : dimSelectors.entrySet()) { final DimensionSelector selector = entry.getValue(); if (selector != null) { final IndexedInts vals = selector.getRow(); for (int i = 0; i < vals.size(); ++i) { final String dimVal = selector.lookupName(vals.get(i)); if (searchQuerySpec.accept(dimVal)) { set.add(new SearchHit(entry.getKey(), dimVal)); if (set.size() >= limit) { return set; } } } } } cursor.advance(); } return set; } }); return makeReturnResult(limit, retVal); }
From source file:de.tu_berlin.dima.oligos.stat.distribution.histogram.StringHistogram.java
@Override public SortedSet<String> getLowerBounds() { return Sets.newTreeSet(exactValues.keySet()); }