List of usage examples for com.google.common.collect Sets newTreeSet
public static <E extends Comparable> TreeSet<E> newTreeSet()
From source file:co.cask.common.lang.InstantiatorFactory.java
private <T> Instantiator<T> getByKnownType(TypeToken<T> type) { Class<? super T> rawType = type.getRawType(); if (rawType.isArray()) { return new Instantiator<T>() { @Override// www . j a v a2s . c o m public T create() { return (T) Lists.newLinkedList(); } }; } if (Collection.class.isAssignableFrom(rawType)) { if (SortedSet.class.isAssignableFrom(rawType)) { return new Instantiator<T>() { @Override public T create() { return (T) Sets.newTreeSet(); } }; } if (Set.class.isAssignableFrom(rawType)) { return new Instantiator<T>() { @Override public T create() { return (T) Sets.newHashSet(); } }; } if (Queue.class.isAssignableFrom(rawType)) { return new Instantiator<T>() { @Override public T create() { return (T) Lists.newLinkedList(); } }; } return new Instantiator<T>() { @Override public T create() { return (T) Lists.newArrayList(); } }; } if (Map.class.isAssignableFrom(rawType)) { if (SortedMap.class.isAssignableFrom(rawType)) { return new Instantiator<T>() { @Override public T create() { return (T) Maps.newTreeMap(); } }; } return new Instantiator<T>() { @Override public T create() { return (T) Maps.newHashMap(); } }; } return null; }
From source file:org.smartdeveloperhub.vocabulary.util.VocabularyHelper.java
List<String> uriRefs(final String... namespaces) { final Set<String> valid = Sets.newHashSet(namespaces); if (valid.isEmpty()) { valid.addAll(this.vocabulary.getNsPrefixMap().values()); }// www . ja v a2 s . co m final SortedSet<String> named = Sets.newTreeSet(); named.addAll(extractResourceURIs(this.vocabulary.listSubjects(), valid)); named.addAll(extractResourceURIs(this.vocabulary.listAllOntProperties(), valid)); named.addAll(extractResourceURIs(this.vocabulary.listObjects(), valid)); return Lists.newArrayList(named); }
From source file:org.richfaces.cdk.generate.freemarker.ModelElementBaseTemplateModel.java
public TemplateModel getImportClasses() throws TemplateModelException { Set<ClassName> result = Sets.newTreeSet(); String targetPackage = model.getTargetClass().getPackage(); for (PropertyBase entry : model.getAttributes()) { if (entry.getGenerate()) { addIfNecessary(targetPackage, result, entry.getType()); }//from www . ja v a 2s .c om } // Import all interfaces implemented by the generated class. result.addAll(model.getInterfaces()); if (model instanceof ComponentModel) { ComponentModel component = (ComponentModel) model; for (EventModel event : component.getEvents()) { addIfNecessary(targetPackage, result, event.getSourceInterface()); addIfNecessary(targetPackage, result, event.getListenerInterface()); } } // Collection<String> list = new ArrayList<String>(result); return this.wrapper.wrap(result); }
From source file:co.mitro.core.server.data.DBGroupSecret.java
/** * Adds all data about this to the RPC message secret, including encrypted data and ACLs. * Includes the critical data if critical == INCLUDE_CRITICAL_DATA. */// w w w . j a va2s . c o m public void addToRpcSecret(Manager manager, RPC.Secret secret, CRITICAL critical, String userId) throws MitroServletException, SQLException { DBAudit.ACTION type = critical == CRITICAL.INCLUDE_CRITICAL_DATA ? DBAudit.ACTION.GET_SECRET_WITH_CRITICAL : DBAudit.ACTION.GET_SECRET_WITHOUT_CRITICAL; secret.encryptedClientData = getClientVisibleDataEncrypted(); Set<Integer> groups = Sets.newHashSet(); Set<Integer> hiddenGroups = Sets.newHashSet(); Set<String> users = Sets.newTreeSet(); secret.groupIdToPublicKeyMap = new HashMap<>(); secret.groupNames = new HashMap<>(); secret.groupMap = new HashMap<>(); // TODO: This performs many loads of ServerVisibleSecret, GroupSecret, and Group // can we avoid these? Do fewer? It makes ListMySecretsAndGroups slow final DBServerVisibleSecret svs = getServerVisibleSecret(); secret.king = svs.getKing() == null ? null : svs.getKing().getName(); secret.isViewable = svs.isViewable(); for (DBGroupSecret dbGroupSecret : svs.getGroupSecrets()) { DBGroup group = dbGroupSecret.getGroup(); secret.groupIdToPublicKeyMap.put(group.getId(), group.getPublicKeyString()); if (dbGroupSecret.getGroup().isAutoDelete()) { hiddenGroups.add(dbGroupSecret.getGroup().getId()); // in this case we should add the users for (DBAcl acl : dbGroupSecret.getGroup().getAcls()) { if (null != acl.getMemberIdentityId()) { DBIdentity identity = acl.loadMemberIdentity(manager.identityDao); users.add(identity.getName()); continue; } } } else { groups.add(group.getId()); // add group names so we can display groups even if we don't have access to them // TODO: Should we only return this from GetSecret? secret.groupNames.put(group.getId(), group.getName()); GroupInfo groupInfo = new GroupInfo(); groupInfo.groupId = group.getId(); groupInfo.name = group.getName(); groupInfo.autoDelete = group.isAutoDelete(); groupInfo.isTopLevelOrg = group.isTopLevelOrganization(); secret.groupMap.put(group.getId(), groupInfo); if (null == secret.owningOrgId && groupInfo.isTopLevelOrg) { secret.owningOrgId = groupInfo.groupId; } groupInfo.isOrgPrivateGroup = group.isPrivateUserGroup() && (groupInfo.owningOrgId != null); groupInfo.isNonOrgPrivateGroup = group.isPrivateUserGroup() && (groupInfo.owningOrgId == null); } } secret.hiddenGroups = Lists.newLinkedList(hiddenGroups); secret.users = Lists.newLinkedList(users); secret.groups = Lists.newLinkedList(groups); manager.addAuditLog(type, null, null, null, this.getServerVisibleSecret(), null); if (CRITICAL.INCLUDE_CRITICAL_DATA_FOR_DISPLAY == critical || CRITICAL.INCLUDE_CRITICAL_DATA == critical) { secret.encryptedCriticalData = getCriticalDataEncrypted(); } else { secret.encryptedCriticalData = null; } secret.secretId = getServerVisibleSecret().getId(); // TODO: Figure out how to get icons and titles for sites that doesn't destroy privacy // secret.icons = Manager.getOldJsonData().getIcons(secret.hostname); // secret.title = Manager.getOldJsonData().getTitle(secret.hostname); }
From source file:de.tuberlin.uebb.jdae.llmsl.Block.java
private Map<GlobalVariable, BlockVariable> makeBlockVars(DataLayout layout, Set<DerivedEquation> equations, final Map<Integer, Integer> gvIndex) { final Map<GlobalVariable, BlockVariable> blockVars = Maps.newHashMap(); final Set<GlobalVariable> needed = Sets.newTreeSet(); for (DerivedEquation eq : equations) { final int order = eq.maxOrder; for (int i = 0; i <= order; i++) for (GlobalVariable gv : eq.eqn.need()) needed.add(gv.der(i));//from w w w. j a v a2 s .co m } for (GlobalVariable gv : needed) { if (gvIndex.containsKey(gv.index)) { final int relIndex = gvIndex.get(gv.index); final BlockVariable bv; if (variables[relIndex].der > gv.der) { bv = new BlockState(gv, relIndex); } else { final int derDiff = gv.der - variables[relIndex].der; bv = new BlockIteratee(gv, relIndex + derDiff); } blockVars.put(gv, bv); } else { blockVars.put(gv, new BlockConstant(gv)); } } return blockVars; }
From source file:com.android.tools.idea.sdk.SdkPackages.java
private void computeUpdates() { Map<String, UpdatablePkgInfo> newConsolidatedPkgs = Maps.newTreeMap(); UpdatablePkgInfo[] updatablePkgInfos = new UpdatablePkgInfo[myLocalPkgInfos.length]; for (int i = 0; i < myLocalPkgInfos.length; i++) { updatablePkgInfos[i] = new UpdatablePkgInfo(myLocalPkgInfos[i]); }/*from w w w . ja va2s .co m*/ Set<RemotePkgInfo> updates = Sets.newTreeSet(); // Find updates to locally installed packages for (UpdatablePkgInfo info : updatablePkgInfos) { IPkgDesc localDesc = info.getLocalInfo().getDesc(); for (RemotePkgInfo remote : myRemotePkgInfos.get(localDesc.getType())) { if (remote.getPkgDesc().isUpdateFor(localDesc, FullRevision.PreviewComparison.IGNORE)) { info.addRemote(remote); myUpdatedPkgs.add(info); updates.add(remote); } } // the consolidated packages map is always keyed by the non-preview installid, whether or not the UpdatablePackage happens to // contain a preview package. newConsolidatedPkgs.put(info.getPkgDesc(true).getBaseInstallId(), info); } // Find new packages not yet installed nextRemote: for (RemotePkgInfo remote : myRemotePkgInfos.values()) { if (updates.contains(remote)) { // if package is already a known update, it's not new. continue nextRemote; } IPkgDesc remoteDesc = remote.getPkgDesc(); for (UpdatablePkgInfo info : updatablePkgInfos) { IPkgDesc localDesc = info.getLocalInfo().getDesc(); if (remoteDesc.compareTo(localDesc) == 0 || remoteDesc.isUpdateFor(localDesc, FullRevision.PreviewComparison.IGNORE) || localDesc.isUpdateFor(remoteDesc, FullRevision.PreviewComparison.IGNORE) /* shouldn't happen in the normal case */) { // if package is same as an installed or is an update for an installed // one, then it's not new. continue nextRemote; } } myNewPkgs.add(remote); String key = remoteDesc.getBaseInstallId(); UpdatablePkgInfo existing = newConsolidatedPkgs.get(key); if (existing != null) { existing.addRemote(remote); } else { newConsolidatedPkgs.put(key, new UpdatablePkgInfo(remote)); } } myConsolidatedPkgs = newConsolidatedPkgs; }
From source file:org.kiji.schema.impl.KijiResultRowData.java
/** {@inheritDoc} */ @Override/*from ww w . ja v a 2s . c om*/ public NavigableSet<Long> getTimestamps(final String family, final String qualifier) { final KijiColumnName column = KijiColumnName.create(family, qualifier); validateColumnRequest(column); final NavigableSet<Long> timestamps = Sets.newTreeSet(); for (final KijiCell<?> cell : mResult.narrowView(column)) { timestamps.add(cell.getTimestamp()); } return timestamps; }
From source file:com.notifier.desktop.ApplicationPreferences.java
public ApplicationPreferences() { allowedDevicesIds = Sets.newTreeSet(); allowedDevicesNames = Lists.newArrayList(); notificationsSettings = Maps.newHashMap(); groupsExpansion = Maps.newEnumMap(Group.class); }
From source file:blockplus.model.Context.java
public Context forward() { if (this.isTerminal()) return this; Context nextContext = new Context(this); if (nextContext.options().isEmpty()) { final TreeSet<IPosition> emptySet = Sets.newTreeSet(); // TODO extract constant nextContext = nextContext.apply(new Move(nextContext.side(), emptySet)); nextContext = nextContext.forward(); }/*w w w . ja va2 s. co m*/ return nextContext; }
From source file:org.geogit.api.plumbing.diff.TreeDifference.java
/** * Finds child refs that exist on the right root tree, don't exist on the left root tree, and * are not renames./*w ww . j ava 2s.c om*/ * * @return */ public SortedSet<NodeRef> findNewTrees() { SortedMap<String, MutableTree> leftEntries = leftTree.getChildrenAsMap(); SortedMap<String, MutableTree> rightEntries = rightTree.getChildrenAsMap(); SortedMapDifference<String, MutableTree> difference; difference = difference(leftEntries, rightEntries); Map<String, MutableTree> entriesOnlyOnRight; entriesOnlyOnRight = newHashMap(difference.entriesOnlyOnRight()); // ignore renames Map<NodeRef, NodeRef> pureRenames = findRenames(difference); for (NodeRef renamedTo : pureRenames.values()) { entriesOnlyOnRight.remove(renamedTo.path()); } SortedSet<NodeRef> newTreeRefs = Sets.newTreeSet(); for (Map.Entry<String, MutableTree> newTree : entriesOnlyOnRight.entrySet()) { Node node = newTree.getValue().getNode(); String parentPath = NodeRef.parentPath(newTree.getKey()); // pass NULL to the NodeRef metadataId, to it defers to the one in the Node in case it // has one (see NodeRef.getMetadataId()) ObjectId metadataId = ObjectId.NULL; NodeRef ref = new NodeRef(node, parentPath, metadataId); newTreeRefs.add(ref); } return newTreeRefs; }