List of usage examples for java.util HashSet addAll
boolean addAll(Collection<? extends E> c);
From source file:com.espertech.esper.epl.fafquery.FireAndForgetQueryExec.java
public static Collection<EventBean> snapshot(FilterSpecCompiled optionalFilter, Annotation[] annotations, VirtualDWView virtualDataWindow, EventTableIndexRepository indexRepository, boolean queryPlanLogging, Log queryPlanLogDestination, String objectName, AgentInstanceContext agentInstanceContext) { if (optionalFilter == null || optionalFilter.getParameters().length == 0) { if (virtualDataWindow != null) { Pair<IndexMultiKey, EventTable> pair = virtualDataWindow .getFireAndForgetDesc(Collections.<String>emptySet(), Collections.<String>emptySet()); return virtualDataWindow.getFireAndForgetData(pair.getSecond(), new Object[0], new RangeIndexLookupValue[0], annotations); }/* w ww .j a v a 2s . co m*/ return null; } // Determine what straight-equals keys and which ranges are available. // Widening/Coercion is part of filter spec compile. Set<String> keysAvailable = new HashSet<String>(); Set<String> rangesAvailable = new HashSet<String>(); if (optionalFilter.getParameters().length == 1) { for (FilterSpecParam param : optionalFilter.getParameters()[0]) { if (!(param instanceof FilterSpecParamConstant || param instanceof FilterSpecParamRange || param instanceof FilterSpecParamIn)) { continue; } if (param.getFilterOperator() == FilterOperator.EQUAL || param.getFilterOperator() == FilterOperator.IS || param.getFilterOperator() == FilterOperator.IN_LIST_OF_VALUES) { keysAvailable.add(param.getLookupable().getExpression()); } else if (param.getFilterOperator().isRangeOperator() || param.getFilterOperator().isInvertedRangeOperator() || param.getFilterOperator().isComparisonOperator()) { rangesAvailable.add(param.getLookupable().getExpression()); } else if (param.getFilterOperator().isRangeOperator()) { rangesAvailable.add(param.getLookupable().getExpression()); } } } // Find an index that matches the needs Pair<IndexMultiKey, EventTableAndNamePair> tablePair; if (virtualDataWindow != null) { Pair<IndexMultiKey, EventTable> tablePairNoName = virtualDataWindow.getFireAndForgetDesc(keysAvailable, rangesAvailable); tablePair = new Pair<IndexMultiKey, EventTableAndNamePair>(tablePairNoName.getFirst(), new EventTableAndNamePair(tablePairNoName.getSecond(), null)); } else { IndexHint indexHint = IndexHint.getIndexHint(annotations); List<IndexHintInstruction> optionalIndexHintInstructions = null; if (indexHint != null) { optionalIndexHintInstructions = indexHint.getInstructionsFireAndForget(); } tablePair = indexRepository.findTable(keysAvailable, rangesAvailable, optionalIndexHintInstructions); } QueryPlanIndexHook hook = QueryPlanIndexHookUtil.getHook(annotations); if (queryPlanLogging && (queryPlanLogDestination.isInfoEnabled() || hook != null)) { String prefix = "Fire-and-forget from " + objectName + " "; String indexName = tablePair != null && tablePair.getSecond() != null ? tablePair.getSecond().getIndexName() : null; String indexText = indexName != null ? "index " + indexName + " " : "full table scan "; indexText += "(snapshot only, for join see separate query plan)"; if (tablePair == null) { queryPlanLogDestination.info(prefix + indexText); } else { queryPlanLogDestination .info(prefix + indexText + tablePair.getSecond().getEventTable().toQueryPlan()); } if (hook != null) { hook.fireAndForget( new QueryPlanIndexDescFAF(new IndexNameAndDescPair[] { new IndexNameAndDescPair(indexName, tablePair != null ? tablePair.getSecond().getEventTable().getClass().getSimpleName() : null) })); } } if (tablePair == null) { return null; // indicates table scan } // Compile key sets which contain key index lookup values String[] keyIndexProps = IndexedPropDesc.getIndexProperties(tablePair.getFirst().getHashIndexedProps()); boolean hasKeyWithInClause = false; Object[] keyValues = new Object[keyIndexProps.length]; for (int keyIndex = 0; keyIndex < keyIndexProps.length; keyIndex++) { for (FilterSpecParam param : optionalFilter.getParameters()[0]) { if (param.getLookupable().getExpression().equals(keyIndexProps[keyIndex])) { if (param.getFilterOperator() == FilterOperator.IN_LIST_OF_VALUES) { Object[] keyValuesList = ((MultiKeyUntyped) param.getFilterValue(null, agentInstanceContext)).getKeys(); if (keyValuesList.length == 0) { continue; } else if (keyValuesList.length == 1) { keyValues[keyIndex] = keyValuesList[0]; } else { keyValues[keyIndex] = keyValuesList; hasKeyWithInClause = true; } } else { keyValues[keyIndex] = param.getFilterValue(null, agentInstanceContext); } break; } } } // Analyze ranges - these may include key lookup value (EQUALS semantics) String[] rangeIndexProps = IndexedPropDesc.getIndexProperties(tablePair.getFirst().getRangeIndexedProps()); RangeIndexLookupValue[] rangeValues; if (rangeIndexProps.length > 0) { rangeValues = compileRangeLookupValues(rangeIndexProps, optionalFilter.getParameters()[0], agentInstanceContext); } else { rangeValues = new RangeIndexLookupValue[0]; } EventTable eventTable = tablePair.getSecond().getEventTable(); IndexMultiKey indexMultiKey = tablePair.getFirst(); // table lookup without in-clause if (!hasKeyWithInClause) { return fafTableLookup(virtualDataWindow, indexMultiKey, eventTable, keyValues, rangeValues, annotations); } // table lookup with in-clause: determine combinations Object[][] combinations = new Object[keyIndexProps.length][]; for (int i = 0; i < keyValues.length; i++) { if (keyValues[i] instanceof Object[]) { combinations[i] = (Object[]) keyValues[i]; } else { combinations[i] = new Object[] { keyValues[i] }; } } // enumerate combinations CombinationEnumeration enumeration = new CombinationEnumeration(combinations); HashSet<EventBean> events = new HashSet<EventBean>(); for (; enumeration.hasMoreElements();) { Object[] keys = enumeration.nextElement(); Collection<EventBean> result = fafTableLookup(virtualDataWindow, indexMultiKey, eventTable, keys, rangeValues, annotations); events.addAll(result); } return events; }
From source file:com.dtolabs.rundeck.plugin.resources.gcp.InstanceToNodeMapper.java
/** * Convert an GCP GCE Instance to a RunDeck INodeEntry based on the mapping input *//* w ww .j a va 2s. c om*/ @SuppressWarnings("unchecked") static INodeEntry instanceToNode(final Instance inst, final Properties mapping) throws GeneratorException { final NodeEntryImpl node = new NodeEntryImpl(); logger.error("instancetoNode call"); //evaluate single settings.selector=tags/* mapping if ("tags/*".equals(mapping.getProperty("attributes.selector"))) { //iterate through instance tags and generate settings /*for (final String tag : inst.getTags().getItems()) { if (null == node.getAttributes()) { node.setAttribute(new HashMap<String, String>()); } node.getAttribute().put(tag.getKey(), tag.getValue()); }*/ } if (null != mapping.getProperty("tags.selector")) { final String selector = mapping.getProperty("tags.selector"); final String value = applySelector(inst, selector, mapping.getProperty("tags.default"), true); if (null != value) { final String[] values = value.split(","); final HashSet<String> tagset = new HashSet<String>(); for (final String s : values) { tagset.add(s.trim()); } if (null == node.getTags()) { node.setTags(tagset); } else { final HashSet orig = new HashSet(node.getTags()); orig.addAll(tagset); node.setTags(orig); } } } if (null == node.getTags()) { node.setTags(new HashSet()); } final HashSet orig = new HashSet(node.getTags()); //apply specific tag selectors final Pattern tagPat = Pattern.compile("^tag\\.(.+?)\\.selector$"); //evaluate tag selectors for (final Object o : mapping.keySet()) { final String key = (String) o; final String selector = mapping.getProperty(key); //split selector by = if present final String[] selparts = selector.split("="); final Matcher m = tagPat.matcher(key); if (m.matches()) { final String tagName = m.group(1); if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } final String value = applySelector(inst, selparts[0], null); if (null != value) { if (selparts.length > 1 && !value.equals(selparts[1])) { continue; } //use add the tag if the value is not null orig.add(tagName); } } } node.setTags(orig); //apply default values which do not have corresponding selector final Pattern attribDefPat = Pattern.compile("^([^.]+?)\\.default$"); //evaluate selectors for (final Object o : mapping.keySet()) { final String key = (String) o; final String value = mapping.getProperty(key); final Matcher m = attribDefPat.matcher(key); if (m.matches() && (!mapping.containsKey(key + ".selector") || "".equals(mapping.getProperty(key + ".selector")))) { final String attrName = m.group(1); if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } if (null != value) { node.getAttributes().put(attrName, value); } } } final Pattern attribPat = Pattern.compile("^([^.]+?)\\.selector$"); //evaluate selectors for (final Object o : mapping.keySet()) { final String key = (String) o; final String selector = mapping.getProperty(key); final Matcher m = attribPat.matcher(key); if (m.matches()) { final String attrName = m.group(1); if (attrName.equals("tags")) { //already handled continue; } if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } final String value = applySelector(inst, selector, mapping.getProperty(attrName + ".default")); if (null != value) { //use nodename-settingname to make the setting unique to the node node.getAttributes().put(attrName, value); } } } String hostSel = mapping.getProperty("hostname.selector"); //logger.error("This is the hostSel variable " + hostSel); String host = applySelector(inst, hostSel, mapping.getProperty("hostname.default")); //logger.error("This is the host variable " + host); //logger.error("This is the hostname.default mapping param " + mapping.getProperty("hostname.default")); if (null == node.getHostname()) { System.err.println("Unable to determine hostname for instance: " + inst.getId()); return null; } String name = node.getNodename(); if (null == name || "".equals(name)) { name = node.getHostname(); } if (null == name || "".equals(name)) { name = inst.getId().toString(); } node.setNodename(name); // Set ssh port on hostname if not 22 String sshport = node.getAttributes().get("sshport"); if (sshport != null && !sshport.equals("") && !sshport.equals("22")) { node.setHostname(node.getHostname() + ":" + sshport); } return node; }
From source file:org.lgna.common.ComponentThread.java
static public java.util.Collection<ComponentThread> getAllChildThreads(ComponentThread parent, boolean inclusive) { if (parent != null) { java.util.HashSet<ComponentThread> rv = new java.util.HashSet<ComponentThread>(); java.util.Collection<ComponentThread> children = parent.getChildrenThreads(); if ((children != null) && !children.isEmpty()) { for (ComponentThread t : children) { rv.addAll(getAllChildThreads(t, true)); }/* w ww .j a va2 s . co m*/ } if (inclusive) { rv.add(parent); } return rv; } else { return null; } }
From source file:org.apache.sling.distribution.packaging.impl.DistributionPackageUtils.java
public static void acquire(File file, @Nonnull String[] holderNames) throws IOException { if (holderNames.length == 0) { throw new IllegalArgumentException("holder name cannot be null or empty"); }/*from w ww. j ava2 s .c o m*/ synchronized (filelock) { try { HashSet<String> set = new HashSet<String>(); if (file.exists()) { ObjectInputStream inputStream = getSafeObjectInputStream(new FileInputStream(file)); set = (HashSet<String>) inputStream.readObject(); IOUtils.closeQuietly(inputStream); } set.addAll(Arrays.asList(holderNames)); ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file)); outputStream.writeObject(set); IOUtils.closeQuietly(outputStream); } catch (ClassNotFoundException e) { log.error("Cannot release file", e); } } }
From source file:com.ibm.amc.data.filter.QueryFilterEngine.java
@SuppressWarnings("unchecked") public static <T> List<T> filter(List<T> objects, Set<Map.Entry<String, List<String>>> queryParams) { if (logger.isEntryEnabled()) logger.entry("filter", objects, queryParams); /* use a HashSet to remove duplicates */ HashSet<T> filteredObjects = new HashSet<T>(); QueryFilter filter = QueryFilterFactory.build(queryParams); if (filter.getOperator().equals(Operator.AND)) { if (logger.isDebugEnabled()) logger.debug("filter", "Filter operator: AND"); for (Predicate predicate : filter.getClauses()) { CollectionUtils.filter(objects, predicate); }/*w w w. j a v a2 s.c o m*/ /* need to muck about to get compatible types */ ArrayList<T> temp; if (objects instanceof ArrayList) { temp = (ArrayList<T>) objects; } else { temp = new ArrayList<T>(objects); } filteredObjects.addAll(temp); } else { if (logger.isDebugEnabled()) logger.debug("filter", "Filter operator: OR"); for (Predicate predicate : filter.getClauses()) { filteredObjects.addAll(CollectionUtils.select(objects, predicate)); } } if (logger.isEntryEnabled()) logger.exit("filter", filteredObjects); return new ArrayList<T>(filteredObjects); }
From source file:edu.cens.loci.classes.LociWifiFingerprint.java
/** * Calculated Tanimoto score between to Wifi fingerprints * @param sig1 is a Wifi fingerprint//from w ww . j a v a2 s .co m * @param sig2 is a Wifi fingerprint * @param repAP1 * @param repAP2 * @param rrThreshold is used to filter low response rate APs * @param isDebugOn * @return */ public static double tanimotoScore(LociWifiFingerprint sig1, LociWifiFingerprint sig2, HashSet<String> repAP1, HashSet<String> repAP2, double rrThreshold, boolean isDebugOn) { if (repAP1 == null) MyLog.i(LociConfig.D.Classes.LOG_WIFI, TAG, "tanimotoScore: use all."); else MyLog.i(LociConfig.D.Classes.LOG_WIFI, TAG, "tanimotoScore: use rep."); // use every beacon when repAP is empty if (repAP1 == null || repAP1.isEmpty()) repAP1 = sig1.getBssids(); if (repAP2 == null || repAP2.isEmpty()) repAP2 = sig2.getBssids(); // use only the union of both representative set HashSet<String> union = new HashSet<String>(repAP1); union.addAll(repAP2); // two arrays to save RSS values double a[] = new double[union.size()]; double b[] = new double[union.size()]; // fill in the arrays with RSS values Iterator<String> iterator = union.iterator(); int cnt = 0; String debugSsids = " "; String debugRssA = "rss (a) : "; String debugRssB = "rss (b) : "; String debugNorA = "nor (a) : "; String debugNorB = "nor (b) : "; String debugCntA = "cnt (a) : "; String debugCntB = "cnt (b) : "; String debugRRA = "rr (a) : "; String debugRRB = "rr (b) : "; while (iterator.hasNext()) { String bssid = iterator.next(); int aIntVal = sig1.getAvgRss(bssid); int bIntVal = sig2.getAvgRss(bssid); double rr1 = sig1.getResponseRate(bssid); double rr2 = sig2.getResponseRate(bssid); if (rr1 >= rrThreshold) a[cnt] = raw2normal(aIntVal, pMinRss, pMaxRss); else a[cnt] = raw2normal(0, pMinRss, pMaxRss); if (rr2 >= rrThreshold) b[cnt] = raw2normal(bIntVal, pMinRss, pMaxRss); else b[cnt] = raw2normal(0, pMinRss, pMaxRss); cnt++; if (isDebugOn) { String ssid = sig1.getSsid(bssid); if (ssid == null) ssid = sig2.getSsid(bssid); if (ssid == null) ssid = "unknown"; int count1 = sig1.getCount(bssid); int count2 = sig2.getCount(bssid); debugSsids = debugSsids + String.format("%10s", ssid.substring(0, Math.min(ssid.length(), 9))); debugRssA = debugRssA + String.format("%10d", aIntVal); debugRssB = debugRssB + String.format("%10d", bIntVal); debugNorA = debugNorA + String.format("%10.2f", a[cnt - 1]); debugNorB = debugNorB + String.format("%10.2f", b[cnt - 1]); debugCntA = debugCntA + String.format("%10d", count1); debugCntB = debugCntB + String.format("%10d", count2); debugRRA = debugRRA + String.format("%10.2f", rr1); debugRRB = debugRRB + String.format("%10.2f", rr2); } } MyLog.d(isDebugOn, TAG, debugSsids); MyLog.d(isDebugOn, TAG, debugRssA); MyLog.d(isDebugOn, TAG, debugRssB); MyLog.d(isDebugOn, TAG, debugNorA); MyLog.d(isDebugOn, TAG, debugNorB); MyLog.d(isDebugOn, TAG, debugCntA); MyLog.d(isDebugOn, TAG, debugCntB); MyLog.d(isDebugOn, TAG, debugRRA); MyLog.d(isDebugOn, TAG, debugRRB); return tanimotoSimilarity(a, b); }
From source file:org.ihtsdo.utils.FileHelper.java
/** * Gets the files from folder./*w w w . j a va 2 s . com*/ * * @param folder the folder * @param mustHave the must have * @param doesntMustHave the doesnt must have * @param isPrevious the is previous * @return the files from folder * @throws IOException Signals that an I/O exception has occurred. * @throws Exception the exception */ private static HashSet<String> getFilesFromFolder(String folder, String mustHave, String doesntMustHave, boolean isPrevious) throws IOException, Exception { HashSet<String> result = new HashSet<String>(); File dir = new File(folder); HashSet<String> files = new HashSet<String>(); findAllFiles(dir, files, mustHave, doesntMustHave, isPrevious); result.addAll(files); return result; }
From source file:com.termmed.utils.FileHelper.java
/** * Gets the files from folder.//from ww w . ja v a2 s .c om * * @param folder the folder * @param mustHave the must have * @param doesntMustHave the doesnt must have * @param isPrevious the is previous * @return the files from folder * @throws IOException Signals that an I/O exception has occurred. * @throws Exception the exception */ public static HashSet<String> getFilesFromFolder(String folder, String mustHave, String doesntMustHave, boolean isPrevious) throws IOException, Exception { HashSet<String> result = new HashSet<String>(); File dir = new File(folder); HashSet<String> files = new HashSet<String>(); findAllFiles(dir, files, mustHave, doesntMustHave, isPrevious); result.addAll(files); return result; }
From source file:org.apache.accumulo.server.init.Initialize.java
private static void addVolumes(VolumeManager fs) throws IOException { String[] volumeURIs = VolumeConfiguration.getVolumeUris(SiteConfiguration.getInstance()); HashSet<String> initializedDirs = new HashSet<String>(); initializedDirs.addAll(Arrays.asList(ServerConstants.checkBaseUris(volumeURIs, true))); HashSet<String> uinitializedDirs = new HashSet<String>(); uinitializedDirs.addAll(Arrays.asList(volumeURIs)); uinitializedDirs.removeAll(initializedDirs); Path aBasePath = new Path(initializedDirs.iterator().next()); Path iidPath = new Path(aBasePath, ServerConstants.INSTANCE_ID_DIR); Path versionPath = new Path(aBasePath, ServerConstants.VERSION_DIR); UUID uuid = UUID.fromString(ZooUtil.getInstanceIDFromHdfs(iidPath, SiteConfiguration.getInstance())); for (Pair<Path, Path> replacementVolume : ServerConstants.getVolumeReplacements()) { if (aBasePath.equals(replacementVolume.getFirst())) log.error(aBasePath + " is set to be replaced in " + Property.INSTANCE_VOLUMES_REPLACEMENTS + " and should not appear in " + Property.INSTANCE_VOLUMES + ". It is highly recommended that this property be removed as data could still be written to this volume."); }/*from w w w.jav a2 s . co m*/ if (ServerConstants.DATA_VERSION != Accumulo.getAccumuloPersistentVersion( versionPath.getFileSystem(CachedConfiguration.getInstance()), versionPath)) { throw new IOException("Accumulo " + Constants.VERSION + " cannot initialize data version " + Accumulo.getAccumuloPersistentVersion(fs)); } initDirs(fs, uuid, uinitializedDirs.toArray(new String[uinitializedDirs.size()]), true); }
From source file:jef.tools.collection.CollectionUtil.java
/** * ??//w w w .j a va2s .c o m * * @param <T> * @param a * @param b * @return */ public static <T> Collection<T> union(Collection<T> a, Collection<T> b) { HashSet<T> s = new HashSet<T>(a.size() + b.size()); s.addAll(a); s.addAll(b); return s; }