List of usage examples for java.util HashSet isEmpty
public boolean isEmpty()
From source file:org.tomahawk.libtomahawk.infosystem.InfoSystem.java
public void onLoggedOpsSent(ArrayList<String> doneRequestsIds, boolean success) { List<InfoRequestData> loggedOps = new ArrayList<InfoRequestData>(); HashSet<Integer> requestTypes = new HashSet<Integer>(); HashSet<String> playlistIds = new HashSet<String>(); for (String doneRequestId : doneRequestsIds) { if (mSentRequests.containsKey(doneRequestId)) { InfoRequestData loggedOp = mSentRequests.get(doneRequestId); loggedOps.add(loggedOp);/* ww w. j av a 2 s.c o m*/ requestTypes.add(loggedOp.getType()); if (loggedOp.getType() == InfoRequestData.INFOREQUESTDATA_TYPE_PLAYLISTS_PLAYLISTENTRIES) { playlistIds.add(loggedOp.getQueryParams().playlist_local_id); } else if (loggedOp.getType() == InfoRequestData.INFOREQUESTDATA_TYPE_PLAYLISTS) { HatchetPlaylistEntries entries = loggedOp.getResult(HatchetPlaylistEntries.class); if (entries != null && entries.playlists.size() > 0) { playlistIds.add(entries.playlists.get(0).id); Playlist.getPlaylistById(loggedOp.getQueryParams().playlist_local_id) .setHatchetId(entries.playlists.get(0).id); } } mLoggedOpsMap.remove(loggedOp.getLoggedOpId()); } } if (success) { for (InfoRequestData loggedOp : loggedOps) { mPlaylistsLoggedOpsMap.remove(loggedOp.getLoggedOpId()); } trySendingQueuedOps(); DatabaseHelper.getInstance().removeOpsFromInfoSystemOpLog(loggedOps); if (DatabaseHelper.getInstance().getLoggedOpsCount() == 0) { if (!requestTypes.isEmpty()) { Intent reportIntent = new Intent(INFOSYSTEM_OPLOGISEMPTIED); reportIntent.putIntegerArrayListExtra(INFOSYSTEM_OPLOGISEMPTIED_REQUESTTYPES, new ArrayList<Integer>(requestTypes)); if (!playlistIds.isEmpty()) { reportIntent.putStringArrayListExtra(INFOSYSTEM_OPLOGISEMPTIED_IDS, new ArrayList<String>(playlistIds)); } TomahawkApp.getContext().sendBroadcast(reportIntent); } } } }
From source file:it.iit.genomics.cru.structures.bridges.uniprot.UniprotkbUtils.java
/** * * @param genes// www . j a v a 2 s . c om * @return * @throws BridgesRemoteAccessException */ public MapOfMap<String, MoleculeEntry> getUniprotEntriesFromGenes(Collection<String> genes) throws BridgesRemoteAccessException { String tool = UNIPROT_TOOL; MapOfMap<String, MoleculeEntry> gene2uniprots = new MapOfMap<>(genes); HashSet<String> genes2get = new HashSet<>(); try { for (String gene : genes) { if (cache.containsKey(gene.toUpperCase())) { gene2uniprots.addAll(gene, cache.get(gene.toUpperCase())); } else { genes2get.add(gene); // if size == limit, do query if (genes2get.size() == maxQueries) { String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:" + URLEncoder.encode("\"" + taxid + "\"", "UTF-8") + "+AND+(gene:" + URLEncoder.encode(StringUtils.join(genes2get, " OR gene:"), "UTF-8") + ")"; Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location); for (MoleculeEntry entry : uniprotEntries) { String geneName = entry.getGeneName(); // Only use the first one. Using synomyms may cause // ambiguity. if (geneName != null && gene2uniprots.containsKey(geneName)) { gene2uniprots.add(geneName, entry); } } genes2get.clear(); } } } if (genes2get.isEmpty()) { return gene2uniprots; } String location = UNIPROT_SERVER + tool + "/?" + "query=keyword:181+AND+organism:" + URLEncoder.encode("\"" + taxid + "\"", "UTF-8") + "+AND+(gene:" + URLEncoder.encode(StringUtils.join(genes2get, " OR gene:"), "UTF-8") + ")"; Collection<MoleculeEntry> uniprotEntries = getUniprotEntriesXML(location); for (MoleculeEntry entry : uniprotEntries) { String geneName = entry.getGeneName(); // Only use the first one. Using synomyms may cause ambiguity. if (geneName != null && gene2uniprots.containsKey(geneName)) { gene2uniprots.add(geneName, entry); } } } catch (UnsupportedEncodingException e) { logger.error("cannot get proteins for " + StringUtils.join(genes, ", "), e); } return gene2uniprots; }
From source file:com.tct.mail.ui.AnimatedAdapter.java
private void delete(Collection<Conversation> conversations, ListItemsRemovedListener listener, HashSet<Long> list) { // Clear out any remaining items and add the new ones mLastDeletingItems.clear();/*from w w w .ja v a 2 s . c o m*/ // Since we are deleting new items, clear any remaining undo items mUndoingItems.clear(); final int startPosition = mListView.getFirstVisiblePosition(); final int endPosition = mListView.getLastVisiblePosition(); // Only animate visible items for (Conversation c : conversations) { //TS: Lin-zhou 2015-03-04 EMAIL BUGFIX_1278489 ADD_S Integer position = cachePosition.get(c.id); if (position == null) { continue; } if (position >= startPosition && position <= endPosition) { mLastDeletingItems.add(c.id); list.add(c.id); } //TS: Lin-zhou 2015-03-04 EMAIL BUGFIX_1278489 ADD_E } if (list.isEmpty()) { // If we have no deleted items on screen, skip the animation listener.onListItemsRemoved(); // If we have an action queued up, perform it performAndSetNextAction(null); } else { performAndSetNextAction(listener); } notifyDataSetChanged(); }
From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginView.java
/** * //from w ww. j av a2 s .co m * @param path int of the path to get the Time Options for * @param storedTimePref Long of anytime during the specific day that we want to return times for * @return populates the "times" TreeSet (time longs truncated at the "the seconds" position) * which populates Time Combo box, the truncTimeToFullTimeMap which maps the truncated times * im times TreeSet to each times full Long value. The truncTimeToFullTimeMap chooses each time * up to the second and maps it to the greatest equivalent time up to the milliseconds. * */ protected void setTimeOptions(int path, Long storedTimePref) { try { timeSelectCombo.getItems().clear(); overrideTimestamp = null; Date startDate = null, finishDate = null; if (storedTimePref != null) { StampBdb stampDb = Bdb.getStampDb(); NidSet nidSet = new NidSet(); nidSet.add(path); NidSetBI stamps = null; if (!storedTimePref.equals(getDefaultTime())) { startDate = getStartOfDay(new Date(storedTimePref)); finishDate = getEndOfDay(new Date(storedTimePref)); stamps = stampDb.getSpecifiedStamps(nidSet, startDate.getTime(), finishDate.getTime()); } else { stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); } truncTimeToFullTimeMap.clear(); times.clear(); HashSet<Integer> stampSet = stamps.getAsSet(); Date d = new Date(storedTimePref); if (dateIsLocalDate(d)) { // Get stamps of day Date todayStartDate = getStartOfDay(new Date()); Date todayFinishDate = getEndOfDay(new Date()); NidSetBI todayStamps = stampDb.getSpecifiedStamps(nidSet, todayStartDate.getTime(), todayFinishDate.getTime()); // If have stamps, no action, if not, show Latest and set stamps to latest stamp we have in stampset if (todayStamps.size() == 0) { // timeSelectCombo.getItems().add(Long.MAX_VALUE); NidSetBI allStamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE); HashSet<Integer> allStampSet = allStamps.getAsSet(); SortedSet<Integer> s = new TreeSet<Integer>(allStampSet); if (!s.isEmpty()) { Integer stampToSet = s.last(); overrideTimestamp = stampDb.getPosition(stampToSet).getTime(); timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); } } } this.pathDatesList.add(LocalDate.now()); if (overrideTimestamp == null) { if (!stampSet.isEmpty()) { enableTimeCombo(true); for (Integer thisStamp : stampSet) { Long fullTime = null; Date stampDate; LocalDate stampInstant = null; try { fullTime = stampDb.getPosition(thisStamp).getTime(); stampDate = new Date(fullTime); stampInstant = stampDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); } catch (Exception e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTime(new Date(fullTime)); cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds Long truncTime = cal.getTimeInMillis(); this.pathDatesList.add(stampInstant); //Build DatePicker times.add(truncTime); //This can probably go, we don't populate hashmap like this at initialization timeSelectCombo.getItems().add(truncTime); if (truncTimeToFullTimeMap.containsKey(truncTime)) { //Build Truncated Time to Full Time HashMap //If truncTimeToFullTimeMap has this key, is the value the newest time in milliseconds? if (new Date(truncTimeToFullTimeMap.get(truncTime)).before(new Date(fullTime))) { truncTimeToFullTimeMap.put(truncTime, fullTime); } } else { truncTimeToFullTimeMap.put(truncTime, fullTime); } } } else { // disableTimeCombo(true); // timeSelectCombo.getItems().add(Long.MAX_VALUE); timeSelectCombo.setValue(Long.MAX_VALUE); enableTimeCombo(true); // logger.error("Could not retreive any Stamps"); } } } } catch (Exception e) { logger.error("Error setting the default Time Dropdown"); e.printStackTrace(); } }
From source file:org.apache.hadoop.hdfs.DataStreamer.java
private boolean[] getPinnings(DatanodeInfo[] nodes, boolean shouldLog) { if (favoredNodes == null) { return null; } else {//from w w w.j av a 2s .c om boolean[] pinnings = new boolean[nodes.length]; HashSet<String> favoredSet = new HashSet<String>(Arrays.asList(favoredNodes)); for (int i = 0; i < nodes.length; i++) { pinnings[i] = favoredSet.remove(nodes[i].getXferAddrWithHostname()); if (DFSClient.LOG.isDebugEnabled()) { DFSClient.LOG.debug(nodes[i].getXferAddrWithHostname() + " was chosen by name node (favored=" + pinnings[i] + ")."); } } if (shouldLog && !favoredSet.isEmpty()) { // There is one or more favored nodes that were not allocated. DFSClient.LOG.warn("These favored nodes were specified but not chosen: " + favoredSet + " Specified favored nodes: " + Arrays.toString(favoredNodes)); } return pinnings; } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java
private static Pair<Boolean, Boolean> pushThroughOp(HashSet<LogicalVariable> toPush, Mutable<ILogicalOperator> opRef2, ILogicalOperator initialOp, IOptimizationContext context) throws AlgebricksException { List<LogicalVariable> initProjectList = new ArrayList<LogicalVariable>(toPush); AbstractLogicalOperator op2 = (AbstractLogicalOperator) opRef2.getValue(); do {//w w w.ja va 2s . com if (op2.getOperatorTag() == LogicalOperatorTag.EMPTYTUPLESOURCE || op2.getOperatorTag() == LogicalOperatorTag.NESTEDTUPLESOURCE || op2.getOperatorTag() == LogicalOperatorTag.PROJECT || op2.getOperatorTag() == LogicalOperatorTag.REPLICATE || op2.getOperatorTag() == LogicalOperatorTag.UNIONALL) { return new Pair<Boolean, Boolean>(false, false); } if (!op2.isMap()) { break; } LinkedList<LogicalVariable> usedVars = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(op2, usedVars); toPush.addAll(usedVars); LinkedList<LogicalVariable> producedVars = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, producedVars); toPush.removeAll(producedVars); // we assume pipelineable ops. have only one input opRef2 = op2.getInputs().get(0); op2 = (AbstractLogicalOperator) opRef2.getValue(); } while (true); LinkedList<LogicalVariable> produced2 = new LinkedList<LogicalVariable>(); VariableUtilities.getProducedVariables(op2, produced2); LinkedList<LogicalVariable> used2 = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(op2, used2); boolean canCommuteProjection = initProjectList.containsAll(toPush) && initProjectList.containsAll(produced2) && initProjectList.containsAll(used2); // if true, we can get rid of the initial projection // get rid of useless decor vars. if (!canCommuteProjection && op2.getOperatorTag() == LogicalOperatorTag.GROUP) { boolean gbyChanged = false; GroupByOperator gby = (GroupByOperator) op2; List<Pair<LogicalVariable, Mutable<ILogicalExpression>>> newDecorList = new ArrayList<Pair<LogicalVariable, Mutable<ILogicalExpression>>>(); for (Pair<LogicalVariable, Mutable<ILogicalExpression>> p : gby.getDecorList()) { LogicalVariable decorVar = GroupByOperator.getDecorVariable(p); if (!toPush.contains(decorVar)) { used2.remove(decorVar); gbyChanged = true; } else { newDecorList.add(p); } } gby.getDecorList().clear(); gby.getDecorList().addAll(newDecorList); if (gbyChanged) { context.computeAndSetTypeEnvironmentForOperator(gby); } } used2.clear(); VariableUtilities.getUsedVariables(op2, used2); toPush.addAll(used2); // remember that toPush is a Set toPush.removeAll(produced2); if (toPush.isEmpty()) { return new Pair<Boolean, Boolean>(false, false); } boolean smthWasPushed = false; for (Mutable<ILogicalOperator> c : op2.getInputs()) { if (pushNeededProjections(toPush, c, context, initialOp)) { smthWasPushed = true; } } if (op2.hasNestedPlans()) { AbstractOperatorWithNestedPlans n = (AbstractOperatorWithNestedPlans) op2; for (ILogicalPlan p : n.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { if (pushNeededProjections(toPush, r, context, initialOp)) { smthWasPushed = true; } } } } return new Pair<Boolean, Boolean>(smthWasPushed, canCommuteProjection); }
From source file:com.vmware.bdd.plugin.ambari.service.AmbariImpl.java
private boolean isBlueprintCreatedByBDE(final AmClusterDef clusterDef) throws SoftwareManagementPluginException { /*//from w ww.j a v a 2s.co m For cluster resume/resize, the blueprint is already exist, we need to check if this blueprint is created by BDE. So far, just check if all goup names and components exist in Ambari Cluster are included in given blueprint */ ApiBlueprint apiBlueprint = clusterDef.toApiBlueprint(); String clusterName = clusterDef.getName(); ApiBlueprint apiBlueprintFromAm = apiManager.getBlueprint(clusterName); Map<String, Set> groupNamesWithComponents = new HashMap<String, Set>(); for (ApiHostGroup hostGroup : apiBlueprint.getApiHostGroups()) { HashSet<String> components = new HashSet<String>(); groupNamesWithComponents.put(hostGroup.getName(), components); } for (ApiHostGroup apiHostGroup : apiBlueprintFromAm.getApiHostGroups()) { String groupName = apiHostGroup.getName(); if (!groupNamesWithComponents.containsKey(groupName)) { throw AmException.BLUEPRINT_ALREADY_EXIST(clusterName); } @SuppressWarnings("unchecked") Set<String> components = groupNamesWithComponents.get(groupName); if (components != null && !components.isEmpty()) { for (ApiComponentInfo apiComponent : apiHostGroup.getApiComponents()) { if (!components.contains(apiComponent.getName())) { throw AmException.BLUEPRINT_ALREADY_EXIST(clusterName); } } } } return true; }
From source file:com.android.messaging.mmslib.pdu.PduPersister.java
/** * Update headers of a SendReq./*from ww w . j a va 2s . c o m*/ * * @param uri The PDU which need to be updated. * @param pdu New headers. * @throws MmsException Bad URI or updating failed. */ public void updateHeaders(final Uri uri, final SendReq sendReq) { synchronized (PDU_CACHE_INSTANCE) { // If the cache item is getting updated, wait until it's done updating before // purging it. if (PDU_CACHE_INSTANCE.isUpdating(uri)) { if (LOCAL_LOGV) { LogUtil.v(TAG, "updateHeaders: " + uri + " blocked by isUpdating()"); } try { PDU_CACHE_INSTANCE.wait(); } catch (final InterruptedException e) { Log.e(TAG, "updateHeaders: ", e); } } } PDU_CACHE_INSTANCE.purge(uri); final ContentValues values = new ContentValues(10); final byte[] contentType = sendReq.getContentType(); if (contentType != null) { values.put(Mms.CONTENT_TYPE, toIsoString(contentType)); } final long date = sendReq.getDate(); if (date != -1) { values.put(Mms.DATE, date); } final int deliveryReport = sendReq.getDeliveryReport(); if (deliveryReport != 0) { values.put(Mms.DELIVERY_REPORT, deliveryReport); } final long expiry = sendReq.getExpiry(); if (expiry != -1) { values.put(Mms.EXPIRY, expiry); } final byte[] msgClass = sendReq.getMessageClass(); if (msgClass != null) { values.put(Mms.MESSAGE_CLASS, toIsoString(msgClass)); } final int priority = sendReq.getPriority(); if (priority != 0) { values.put(Mms.PRIORITY, priority); } final int readReport = sendReq.getReadReport(); if (readReport != 0) { values.put(Mms.READ_REPORT, readReport); } final byte[] transId = sendReq.getTransactionId(); if (transId != null) { values.put(Mms.TRANSACTION_ID, toIsoString(transId)); } final EncodedStringValue subject = sendReq.getSubject(); if (subject != null) { values.put(Mms.SUBJECT, toIsoString(subject.getTextString())); values.put(Mms.SUBJECT_CHARSET, subject.getCharacterSet()); } else { values.put(Mms.SUBJECT, ""); } final long messageSize = sendReq.getMessageSize(); if (messageSize > 0) { values.put(Mms.MESSAGE_SIZE, messageSize); } final PduHeaders headers = sendReq.getPduHeaders(); final HashSet<String> recipients = new HashSet<String>(); for (final int addrType : ADDRESS_FIELDS) { EncodedStringValue[] array = null; if (addrType == PduHeaders.FROM) { final EncodedStringValue v = headers.getEncodedStringValue(addrType); if (v != null) { array = new EncodedStringValue[1]; array[0] = v; } } else { array = headers.getEncodedStringValues(addrType); } if (array != null) { final long msgId = ContentUris.parseId(uri); updateAddress(msgId, addrType, array); if (addrType == PduHeaders.TO) { for (final EncodedStringValue v : array) { if (v != null) { recipients.add(v.getString()); } } } } } if (!recipients.isEmpty()) { final long threadId = MmsSmsUtils.Threads.getOrCreateThreadId(mContext, recipients); values.put(Mms.THREAD_ID, threadId); } SqliteWrapper.update(mContext, mContentResolver, uri, values, null, null); }
From source file:org.epics.archiverappliance.config.DefaultConfigService.java
@Override public Set<String> getPVsForApplianceMatchingRegex(String nameToMatch) { logger.debug("Finding matching names for " + nameToMatch); LinkedList<String> fixedStringParts = new LinkedList<String>(); String[] parts = this.pvName2KeyConverter.breakIntoParts(nameToMatch); Pattern fixedStringParttern = Pattern.compile("[a-zA-Z_0-9-]+"); for (String part : parts) { if (fixedStringParttern.matcher(part).matches()) { logger.debug("Fixed string part " + part); fixedStringParts.add(part);//from www . j av a2s . co m } else { logger.debug("Regex string part " + part); } } if (fixedStringParts.size() > 0) { HashSet<String> ret = new HashSet<String>(); HashSet<String> namesSubset = new HashSet<String>(); // This reverse is probably specific to SLAC's namespace rules but it does make a big difference. // Perhaps we can use a more intelligent way of choosing the specific path thru the trie. Collections.reverse(fixedStringParts); for (String fixedStringPart : fixedStringParts) { ConcurrentSkipListSet<String> pvNamesForPart = parts2PVNamesForThisAppliance.get(fixedStringPart); if (pvNamesForPart != null) { if (namesSubset.isEmpty()) { namesSubset.addAll(pvNamesForPart); } else { namesSubset.retainAll(pvNamesForPart); } } } logger.debug("Using fixed string path matching against names " + namesSubset.size()); Pattern pattern = Pattern.compile(nameToMatch); for (String pvName : namesSubset) { if (pattern.matcher(pvName).matches()) { ret.add(pvName); } } return ret; } else { // The use pattern did not have any fixed elements at all. // In this case we do brute force matching; should take longer. // This is also not optimal but probably don't want yet another list of PV's Pattern pattern = Pattern.compile(nameToMatch); HashSet<String> allNames = new HashSet<String>(); HashSet<String> ret = new HashSet<String>(); logger.debug("Using brute force pattern matching against names"); for (ConcurrentSkipListSet<String> pvNamesForPart : parts2PVNamesForThisAppliance.values()) { allNames.addAll(pvNamesForPart); } for (String pvName : allNames) { if (pattern.matcher(pvName).matches()) { ret.add(pvName); } } return ret; } }
From source file:com.vmware.bdd.manager.ClusterManager.java
private void checkExtraRequiredPackages() { logger.info("check if extra required packages(mailx and wsdl4j) have been installed for Ironfan."); if (!extraPackagesExisted) { File yumRepoPath = new File(Constants.SERENGETI_YUM_REPO_PATH); // use hs to record the packages that have not been added final HashSet<String> hs = new HashSet<String>(); hs.addAll(extraRequiredPackages); // scan the files under the serengeti yum repo directory File[] rpmList = yumRepoPath.listFiles(new FileFilter() { @Override//from ww w. ja va 2s. co m public boolean accept(File f) { String fname = f.getName(); int idx = fname.indexOf("-"); if (idx > 0) { String packName = fname.substring(0, idx); if (extraRequiredPackages.contains(packName)) { String regx = packName + commRegex; Pattern pat = Pattern.compile(regx); if (pat.matcher(fname).matches()) { hs.remove(packName); return true; } } } return false; } }); if (!hs.isEmpty()) { logger.info("cannot find all the needed packages, stop and return error now. "); throw BddException.EXTRA_PACKAGES_NOT_FOUND(hs.toString()); } logger.info("the check is successful: all needed packages are there."); extraPackagesExisted = true; } }