List of usage examples for java.util HashSet add
public boolean add(E e)
From source file:eionet.cr.api.xmlrpc.XmlRpcServices.java
/** * * @param subjectDTO//from w w w . j a v a 2 s.c o m * @param predicateUri * @param objType * @return */ private static Collection<String> getPredicateValues(SubjectDTO subjectDTO, String predicateUri, ObjectDTO.Type objType) { HashSet<String> result = new HashSet<String>(); Collection<ObjectDTO> objects = subjectDTO.getObjects(predicateUri, objType); if (objects != null && !objects.isEmpty()) { for (Iterator<ObjectDTO> iter = objects.iterator(); iter.hasNext();) { result.add(iter.next().getValue()); } } return result; }
From source file:com.bw.hawksword.wiktionary.ExtendedWikiHelper.java
/** * Format the given wiki-style text into formatted HTML content. This will * create headers, lists, internal links, and style formatting for any wiki * markup found./*from w w w. ja va 2s .c om*/ * * @param wikiText The raw text to format, with wiki-markup included. * @return HTML formatted content, ready for display in {@link WebView}. */ public static String formatWikiText(String wikiText) { if (wikiText == null) { return null; } // Insert a fake last section into the document so our section splitter // can correctly catch the last section. wikiText = wikiText.concat(STUB_SECTION); // Read through all sections, keeping only those matching our filter, // and only including the first entry for each title. HashSet<String> foundSections = new HashSet<String>(); StringBuilder builder = new StringBuilder(); Matcher sectionMatcher = sSectionSplit.matcher(wikiText); while (sectionMatcher.find()) { String title = sectionMatcher.group(1); if (!foundSections.contains(title) && sValidSections.matcher(title).matches()) { String sectionContent = sectionMatcher.group(); foundSections.add(title); builder.append(sectionContent); } } // Our new wiki text is the selected sections only wikiText = builder.toString(); // Apply all formatting rules, in order, to the wiki text for (FormatRule rule : sFormatRules) { wikiText = rule.apply(wikiText); } // Return the resulting HTML with style sheet, if we have content left if (!TextUtils.isEmpty(wikiText)) { return STYLE_SHEET + wikiText; } else { return null; } }
From source file:edu.wpi.margrave.SQSReader.java
protected static Formula handleStatementPAR(Object obj, String varname, String parentsortname, Formula theTarget, MVocab vocab, String prepend) throws MGEUnsupportedSQS, JSONException, MGEBadIdentifierName, MGEUnknownIdentifier, MGEManagerException { // obj may be a JSONObject (Principal examples) // with a child with a value OR array of values //"Principal": { //"AWS": "*"// w w w .j a v a 2 s . c o m //} //"Principal": { //"AWS": ["123456789012","555566667777"] //} // may also be a simple value (Action example) // or an array of values (Resource examples) // "Action": ["SQS:SendMessage","SQS:ReceiveMessage"], // "Resource": "/987654321098/queue1" // TODO: the example principal from "Element Descriptions" doesn't parse... //"Principal":[ // "AWS": "123456789012", // "AWS": "999999999999" // ] // is this just a bad example? // ***************************** // Step 1: Is this a JSONObject? If so, it should have only one key. Prepend that key // to all predicate names produced by its value. if (obj instanceof JSONObject) { JSONObject jobj = (JSONObject) obj; JSONArray names = jobj.names(); if (names.length() != 1) throw new MGEUnsupportedSQS("Number of keys != 1 as expected: " + obj.toString()); Object inner = jobj.get((String) names.get(0)); return handleStatementPAR(inner, varname, parentsortname, theTarget, vocab, prepend + MEnvironment.sIDBSeparator + names.get(0)); } // Now if obj is a simple value, we have a predicate name. // If it is an array of length n, we have n predicate names. if (obj instanceof JSONArray) { JSONArray jarr = (JSONArray) obj; HashSet<Formula> possibleValues = new HashSet<Formula>(); for (int ii = 0; ii < jarr.length(); ii++) { //MEnvironment.errorStream.println(prepend+"="+jarr.get(ii)); Formula theatom = makeSQSAtom(vocab, varname, parentsortname, prepend + "=" + jarr.get(ii)); possibleValues.add(theatom); } theTarget = MFormulaManager.makeAnd(theTarget, MFormulaManager.makeDisjunction(possibleValues)); } else { Formula theatom = makeSQSAtom(vocab, varname, parentsortname, prepend + "=" + obj); theTarget = MFormulaManager.makeAnd(theTarget, theatom); } return theTarget; }
From source file:com.espertech.esper.epl.join.plan.NStreamOuterQueryPlanBuilder.java
private static boolean recursiveHasInnerJoin(int toStream, OuterInnerDirectionalGraph outerInnerGraph, InnerJoinGraph innerJoinGraph, Set<Integer> completedStreams) { // Check if the to-stream is in any of the inner joins boolean hasInnerJoin = innerJoinGraph.hasInnerJoin(toStream); if (hasInnerJoin) { return true; }//from w ww .ja v a 2 s . c o m Set<Integer> innerToToStream = outerInnerGraph.getInner(toStream); if (innerToToStream != null) { for (int nextStream : innerToToStream) { if (completedStreams.contains(nextStream)) { continue; } HashSet<Integer> notConsider = new HashSet<Integer>(completedStreams); notConsider.add(toStream); boolean result = recursiveHasInnerJoin(nextStream, outerInnerGraph, innerJoinGraph, notConsider); if (result) { return true; } } } Set<Integer> outerToToStream = outerInnerGraph.getOuter(toStream); if (outerToToStream != null) { for (int nextStream : outerToToStream) { if (completedStreams.contains(nextStream)) { continue; } HashSet<Integer> notConsider = new HashSet<Integer>(completedStreams); notConsider.add(toStream); boolean result = recursiveHasInnerJoin(nextStream, outerInnerGraph, innerJoinGraph, notConsider); if (result) { return true; } } } return false; }
From source file:org.frat.common.security.BaseSecurityContext.java
/** * @param username/*from w w w .java2 s.co m*/ * @return */ public static HashSet<HttpSession> getSessionByUsername(String username) { @SuppressWarnings("unchecked") HashSet<HttpSession> sessions = (HashSet<HttpSession>) WebUtil.getThreadSession().getServletContext() .getAttribute("loginSessions"); HashSet<HttpSession> httpSessions = new HashSet<HttpSession>(); for (HttpSession session : sessions) { if (null != session && StringUtil.isEqualObj( String.valueOf(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY)), username)) { httpSessions.add(session); } } return httpSessions; }
From source file:main.java.repartition.SimpleTr.java
static double getIncidentSpan(Transaction j, MigrationPlan m) { // Construct A -- for target transaction i Set<Integer> delta_i_A = new HashSet<Integer>(); for (Integer s : m.fromSet) delta_i_A.addAll(m.serverDataSet.get(s)); // Construct b -- for incident transaction j Set<Integer> delta_j_A = new HashSet<Integer>(); for (Integer s : m.fromSet) if (j.getTr_serverSet().containsKey(s)) delta_j_A.addAll(j.getTr_serverSet().get(s)); // Set difference, delta = delta_j_A \ delta_i_A Set<Integer> delta = new HashSet<Integer>(delta_j_A); delta.removeAll(delta_i_A);/*from w w w . jav a2 s .co m*/ HashSet<Integer> psi_delta = new HashSet<Integer>(); for (Entry<Integer, HashSet<Integer>> entry : j.getTr_serverSet().entrySet()) if (!Collections.disjoint(delta, entry.getValue())) // Returns true if the two specified collections have no elements in common. psi_delta.add(entry.getKey()); // Calculate net span improvement for incident transaction j int incident_span = m.fromSet.size() - psi_delta.size(); if (!j.getTr_serverSet().containsKey(m.to)) incident_span -= 1; return (double) (incident_span) * (1 / j.getTr_period()); }
From source file:Main.java
public static void getTop(double[] array, ArrayList<Integer> rankList, int i) { int index = 0; HashSet<Integer> scanned = new HashSet<Integer>(); double max = Double.MIN_VALUE; for (int m = 0; m < i && m < array.length; m++) { max = Double.MIN_VALUE;/*ww w. ja v a2 s. c o m*/ for (int no = 0; no < array.length; no++) { if (!scanned.contains(no)) { if (array[no] > max) { index = no; max = array[no]; } else if (array[no] == max && Math.random() > 0.5) { index = no; max = array[no]; } } } if (!scanned.contains(index)) { scanned.add(index); rankList.add(index); } //System.out.println(m + "\t" + index); } }
From source file:com.yahoo.research.scoring.classifier.NutchOnlineClassifier.java
/** * Implementation of the tokenization process based on the URL-String. A set * of tokens (unique) is returned./*from www .j av a 2s.c o m*/ * * @param string * the String which should be tokenzied. * @return a set of tokens. */ private static Set<String> tokenizer(String string) { HashSet<String> tokens = new HashSet<String>(); if (string != null && !string.equals("")) { // split String tok[] = string.toLowerCase().split("([^a-z0-9])"); // filter for (String t : tok) { // length > 2 if (t.length() < 3) { continue; } // replace number if (t.matches(numPattern)) { tokens.add(numReplacementString); continue; } // filter all string pattern if (t.matches(stringPattern)) { tokens.add(t); continue; } } } return tokens; }
From source file:com.dtolabs.rundeck.plugin.resources.ec2.InstanceToNodeMapper.java
/** * Convert an AWS EC2 Instance to a RunDeck INodeEntry based on the mapping input */// w ww. ja v a2s. c o m @SuppressWarnings("unchecked") static INodeEntry instanceToNode(final Instance inst, final Properties mapping) throws GeneratorException { final NodeEntryImpl node = new NodeEntryImpl(); //evaluate single settings.selector=tags/* mapping if ("tags/*".equals(mapping.getProperty("attributes.selector"))) { //iterate through instance tags and generate settings for (final Tag tag : inst.getTags()) { if (null == node.getAttributes()) { node.setAttributes(new HashMap<String, String>()); } node.getAttributes().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"); // String host = applySelector(inst, hostSel, mapping.getProperty("hostname.default")); // if (null == node.getHostname()) { // System.err.println("Unable to determine hostname for instance: " + inst.getInstanceId()); // return null; // } String name = node.getNodename(); if (null == name || "".equals(name)) { name = node.getHostname(); } if (null == name || "".equals(name)) { name = inst.getInstanceId(); } 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:Main.java
public static void getTop(ArrayList<Double> array, ArrayList<Integer> rankList, int i) { int index = 0; HashSet<Integer> scanned = new HashSet<Integer>(); Double max = Double.MIN_VALUE; for (int m = 0; m < i && m < array.size(); m++) { max = Double.MIN_VALUE;/*w w w . j ava 2s. com*/ for (int no = 0; no < array.size(); no++) { if (!scanned.contains(no)) { if (array.get(no) > max) { index = no; max = array.get(no); } else if (array.get(no).equals(max) && Math.random() > 0.5) { index = no; max = array.get(no); } } } if (!scanned.contains(index)) { scanned.add(index); rankList.add(index); } //System.out.println(m + "\t" + index); } }