List of usage examples for java.util TreeSet addAll
public boolean addAll(Collection<? extends E> c)
From source file:uk.ac.horizon.ubihelper.service.LogManager.java
private synchronized void checkSubscriptions() { float period = getLogPeriod(); String cns[] = getChannels(); TreeSet<String> ecns = new TreeSet<String>(); ecns.addAll(subscriptions.keySet()); for (int i = 0; i < cns.length; i++) { String cn = cns[i];//from w ww . java 2s .c o m if (cn.length() == 0) continue; ecns.remove(cn); LogSubscription sub = subscriptions.get(cn); if (sub == null) { // add Log.d(TAG, "Start logging " + cn + " (update)"); sub = new LogSubscription(this, cn); sub.updateConfiguration(period, period / 2, 0); channelManager.addSubscription(sub); subscriptions.put(cn, sub); channelManager.refreshChannel(cn); } else { // update if (Math.abs(sub.getPeriod() - period) > MIN_PERIOD_CHANGE) { Log.d(TAG, "Update period for " + cn + " (update)"); sub.updateConfiguration(period, period / 2, 0); channelManager.refreshChannel(cn); } } } // remove? for (String cn : ecns) { Log.d(TAG, "Stop logging " + cn + " (update)"); LogSubscription sub = subscriptions.remove(cn); if (sub != null) channelManager.removeSubscription(sub); channelManager.refreshChannel(cn); } }
From source file:com.dianping.resource.io.util.MimeType.java
/** * Compares this {@code MediaType} to another alphabetically. * @param other media type to compare to * @see MimeTypeUtils#sortBySpecificity(java.util.List) *//*from ww w .j a v a 2s . c om*/ @Override public int compareTo(MimeType other) { int comp = getType().compareToIgnoreCase(other.getType()); if (comp != 0) { return comp; } comp = getSubtype().compareToIgnoreCase(other.getSubtype()); if (comp != 0) { return comp; } comp = getParameters().size() - other.getParameters().size(); if (comp != 0) { return comp; } TreeSet<String> thisAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); thisAttributes.addAll(getParameters().keySet()); TreeSet<String> otherAttributes = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); otherAttributes.addAll(other.getParameters().keySet()); Iterator<String> thisAttributesIterator = thisAttributes.iterator(); Iterator<String> otherAttributesIterator = otherAttributes.iterator(); while (thisAttributesIterator.hasNext()) { String thisAttribute = thisAttributesIterator.next(); String otherAttribute = otherAttributesIterator.next(); comp = thisAttribute.compareToIgnoreCase(otherAttribute); if (comp != 0) { return comp; } String thisValue = getParameters().get(thisAttribute); String otherValue = other.getParameters().get(otherAttribute); if (otherValue == null) { otherValue = ""; } comp = thisValue.compareTo(otherValue); if (comp != 0) { return comp; } } return 0; }
From source file:com.addthis.hydra.data.query.QueryElementNode.java
public QueryElementNode parse(String tok, MutableInt nextColumn) { if (tok.equals("+..")) { up = true;//w w w .j a v a 2 s .c om column = Integer.toString(nextColumn.intValue()); nextColumn.increment(); return this; } if (tok.equals("..")) { up = true; return this; } List<String> matchList = new ArrayList<>(3); List<String> trapList = new ArrayList<>(3); if (tok.indexOf(';') > 0) { tok = tok.replace(';', ','); flat = true; } if (tok.startsWith("!")) { not = true; regex = true; tok = tok.substring(1); } if (tok.startsWith("|")) { tok = tok.substring(1); regex = true; } tok = extractDefaultValue(tok); QueryElementNode.MODE mode = MODE.MATCH; String[] list = LessStrings.splitArray(tok, ","); for (String component : list) { if (component.startsWith("*")) { component = component.substring(1); mode = MODE.MATCH; } else if (component.startsWith("+")) { component = component.substring(1); if (component.startsWith("+")) { component = component.substring(1); range = true; } if (component.startsWith("@")) { component = component.substring(1); rangeStrict = true; } mode = MODE.MATCH; int close; if (component.startsWith("{") && (close = component.indexOf("}")) > 0) { column = component.substring(1, close); component = component.substring(close + 1); } else { column = Integer.toString(nextColumn.intValue()); nextColumn.increment(); } } else if (component.startsWith("-")) { component = component.substring(1); mode = MODE.TRAP; } if (component.startsWith("%?")) { data = memKey; regex = true; continue; } if (component.startsWith("%") && !(component.startsWith("%2d") || component.startsWith("%2c"))) { String[] kv = LessBytes.urldecode(component.substring(1)).split("=", 2); if (kv.length == 2) { data = kv[0]; dataKey = kv[1]; } else if (kv.length == 1) { data = kv[0]; } continue; } if (component.startsWith("@@")) { path = LessStrings.splitArray(LessBytes.urldecode(component.substring(2)), "/"); continue; } else if (component.startsWith("@")) { component = component.substring(1); mode = MODE.MATCH; rangeStrict = true; } component = LessBytes.urldecode(component); if (component.length() > 0) { if (mode != MODE.TRAP) { matchList.add(component); } else { trapList.add(component); } } } if (matchList.size() > 0) { String[] out = new String[matchList.size()]; match = matchList.toArray(out); if (tok.startsWith(",")) { TreeSet<String> sorted = new TreeSet<>(); sorted.addAll(matchList); match = sorted.toArray(out); } } if (trapList.size() > 0) { trap = trapList.toArray(new String[trapList.size()]); } return this; }
From source file:org.fusesource.mop.support.Database.java
public TreeSet<String> listDependenants(final String artifact) throws IOException { assertOpen();/*from w ww . ja va2 s .com*/ return pageFile.tx().execute(new Transaction.CallableClosure<TreeSet<String>, IOException>() { public TreeSet<String> execute(Transaction tx) throws IOException { RootEntity root = RootEntity.load(tx); BTreeIndex<String, HashSet<String>> artifacts = root.artifacts.get(tx); HashSet<String> deps = artifacts.get(tx, artifact); if (deps == null) { return null; } TreeSet<String> rc = new TreeSet<String>(); rc.addAll(deps); rc.remove(artifact); return rc; } }); }
From source file:info.magnolia.test.mock.MockContentTest.java
/** * This is the mock-equivalent test of {@link info.magnolia.cms.core.DefaultContentTest#testNameFilteringWorksForBothBinaryAndNonBinaryProperties()}. *//*from w w w .j ava 2 s .c o m*/ @Test public void testNameFilteringWorksForBothBinaryAndNonBinaryProperties() throws Exception { String contentProperties = StringUtils.join(Arrays.asList("/somepage/mypage@type=mgnl:content", "/somepage/mypage/paragraphs@type=mgnl:contentNode", "/somepage/mypage/paragraphs/0@type=mgnl:contentNode", "/somepage/mypage/paragraphs/0@type=mgnl:contentNode", // 2 regular props "/somepage/mypage/paragraphs/0/attention=booyah", "/somepage/mypage/paragraphs/0/imaginary=date:2009-10-14T08:59:01.227-04:00", // 3 binaries "/somepage/mypage/paragraphs/0/attachment1@type=mgnl:resource", "/somepage/mypage/paragraphs/0/attachment1.fileName=hello", "/somepage/mypage/paragraphs/0/attachment1.extension=gif", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:data=X", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:mimeType=image/gif", "/somepage/mypage/paragraphs/0/attachment1.jcr\\:lastModified=", "/somepage/mypage/paragraphs/0/attachment2@type=mgnl:resource", "/somepage/mypage/paragraphs/0/attachment2.fileName=test", "/somepage/mypage/paragraphs/0/attachment2.extension=jpeg", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:data=X", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:mimeType=image/jpeg", "/somepage/mypage/paragraphs/0/attachment2.jcr\\:lastModified=", "/somepage/mypage/paragraphs/0/image3@type=mgnl:resource", "/somepage/mypage/paragraphs/0/image3.fileName=third", "/somepage/mypage/paragraphs/0/image3.extension=png", "/somepage/mypage/paragraphs/0/image3.jcr\\:data=X", "/somepage/mypage/paragraphs/0/image3.jcr\\:mimeType=image/png", "/somepage/mypage/paragraphs/0/image3.jcr\\:lastModified=", // and more which should not match "/somepage/mypage/paragraphs/0/foo=bar", "/somepage/mypage/paragraphs/0/mybool=boolean:true", "/somepage/mypage/paragraphs/0/rand@type=mgnl:resource", "/somepage/mypage/paragraphs/0/rand.fileName=randdddd", "/somepage/mypage/paragraphs/0/rand.extension=png", "/somepage/mypage/paragraphs/0/rand.jcr\\:data=X", "/somepage/mypage/paragraphs/0/rand.jcr\\:mimeType=image/png", "/somepage/mypage/paragraphs/0/rand.jcr\\:lastModified="), "\n"); // --- only this line differs from the DefaultContentTest equivalent final MockHierarchyManager hm = MockUtil.createHierarchyManager(contentProperties); // --- final Content content = hm.getContent("/somepage/mypage/paragraphs/0"); final Collection<NodeData> props = content.getNodeDataCollection("att*|ima*"); assertEquals(5, props.size()); // sort by name final TreeSet<NodeData> sorted = new TreeSet<NodeData>(new Comparator<NodeData>() { @Override public int compare(NodeData o1, NodeData o2) { return o1.getName().compareTo(o2.getName()); } }); sorted.addAll(props); // sanity check - just recheck we still have 5 elements assertEquals(5, sorted.size()); final Iterator<NodeData> it = sorted.iterator(); final NodeData a = it.next(); final NodeData b = it.next(); final NodeData c = it.next(); final NodeData d = it.next(); final NodeData e = it.next(); assertEquals("attachment1", a.getName()); assertEquals(PropertyType.BINARY, a.getType()); assertEquals("attachment2", b.getName()); assertEquals(PropertyType.BINARY, b.getType()); assertEquals("image3", d.getName()); assertEquals(PropertyType.BINARY, d.getType()); assertEquals("image3", d.getName()); assertEquals(PropertyType.BINARY, d.getType()); assertEquals("attention", c.getName()); assertEquals(PropertyType.STRING, c.getType()); assertEquals("booyah", c.getString()); assertEquals("imaginary", e.getName()); assertEquals(PropertyType.DATE, e.getType()); assertEquals(true, e.getDate().before(Calendar.getInstance())); }
From source file:edu.ku.brc.specify.datamodel.WorkbenchTemplate.java
/** * @param template/*from w ww .ja v a 2s.c o m*/ * @return return if the template's mappings are a subset of this object's mappings */ public boolean containsAllMappings(WorkbenchTemplate template) { Comparator<WorkbenchTemplateMappingItem> comp = new Comparator<WorkbenchTemplateMappingItem>() { @Override public int compare(WorkbenchTemplateMappingItem arg0, WorkbenchTemplateMappingItem arg1) { int result = arg0.getTableName().compareTo(arg1.getTableName()); if (result == 0) { result = arg0.getFieldName().compareTo(arg1.getFieldName()); } return result; } }; TreeSet<WorkbenchTemplateMappingItem> theseMaps = new TreeSet<WorkbenchTemplateMappingItem>(comp); //TreeSet<WorkbenchTemplateMappingItem> thoseMaps = new TreeSet<WorkbenchTemplateMappingItem>(comp); theseMaps.addAll(workbenchTemplateMappingItems); //thoseMaps.addAll(template.workbenchTemplateMappingItems); //return theseMaps.containsAll(thoseMaps); return theseMaps.containsAll(template.workbenchTemplateMappingItems); }
From source file:org.zaproxy.zap.extension.compare.ExtensionCompare.java
private void compareSessions() { JFileChooser chooser = new JFileChooser(Model.getSingleton().getOptionsParam().getUserDirectory()); File file = null;//www . ja va2 s.co m chooser.setFileFilter(new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } else if (file.isFile() && file.getName().endsWith(".session")) { return true; } return false; } @Override public String getDescription() { return Constant.messages.getString("file.format.zap.session"); } }); int rc = chooser.showOpenDialog(View.getSingleton().getMainFrame()); if (rc == JFileChooser.APPROVE_OPTION) { try { file = chooser.getSelectedFile(); if (file == null) { return; } Model cmpModel = new Model(); Session session = cmpModel.getSession(); //log.info("opening session file " + file.getAbsolutePath()); //WaitMessageDialog waitMessageDialog = View.getSingleton().getWaitMessageDialog("Loading session file. Please wait ..."); cmpModel.openSession(file, this); // TODO support other implementations in the future Database db = new ParosDatabase(); db.open(file.getAbsolutePath()); Map<String, String> curMap = new HashMap<>(); Map<String, String> cmpMap = new HashMap<>(); // Load the 2 sessions into 2 maps this.buildHistoryMap(Model.getSingleton().getDb().getTableHistory(), curMap); this.buildHistoryMap(db.getTableHistory(), cmpMap); File outputFile = this.getOutputFile(); if (outputFile != null) { // Write the result to the specified file try { TreeSet<String> sset = new TreeSet<>(); // Combine the keys for both maps sset.addAll(curMap.keySet()); sset.addAll(cmpMap.keySet()); StringBuilder sb = new StringBuilder(500); sb.append("<?xml version=\"1.0\"?>"); sb.append(CRLF); sb.append("<report>"); sb.append(CRLF); sb.append("<session-names>"); sb.append(CRLF); sb.append("<session1>"); sb.append(Model.getSingleton().getSession().getSessionName()); sb.append("</session1>"); sb.append(CRLF); sb.append("<session2>"); sb.append(session.getSessionName()); sb.append("</session2>"); sb.append(CRLF); sb.append("</session-names>"); sb.append(CRLF); Iterator<String> iter = sset.iterator(); while (iter.hasNext()) { sb.append("<urlrow>"); sb.append(CRLF); String key = iter.next(); String method = key.substring(0, key.indexOf(" ")); String url = key.substring(key.indexOf(" ") + 1); sb.append("<method>"); sb.append(method); sb.append("</method>"); sb.append(CRLF); sb.append("<url>"); sb.append(url); sb.append("</url>"); sb.append(CRLF); sb.append("<code1>"); if (curMap.containsKey(key)) { sb.append(curMap.get(key)); } else { sb.append("---"); } sb.append("</code1>"); sb.append(CRLF); sb.append("<code2>"); if (cmpMap.containsKey(key)) { sb.append(cmpMap.get(key)); } else { sb.append("---"); } sb.append("</code2>"); sb.append(CRLF); sb.append("</urlrow>"); sb.append(CRLF); } sb.append("</report>"); sb.append(CRLF); ReportGenerator.stringToHtml(sb.toString(), Constant.getZapInstall() + File.separator + "xml" + File.separator + "reportCompare.xsl", outputFile.getAbsolutePath()); try { DesktopUtils.openUrlInBrowser(outputFile.toURI()); } catch (Exception e) { log.error(e.getMessage(), e); View.getSingleton() .showMessageDialog(MessageFormat.format( Constant.messages.getString("report.complete.warning"), new Object[] { outputFile.getAbsolutePath() })); } } catch (Exception e1) { log.warn(e1.getMessage(), e1); } } //waitMessageDialog.setVisible(true); } catch (Exception e) { log.warn(e.getMessage(), e); } } }
From source file:fr.paris.lutece.plugins.updater.service.PluginManagerService.java
/** * Runs SQL scripts/*from ww w . ja va 2s. c om*/ * @param strScriptsDirectory The scripts directory * @throws UpdaterScriptException If a script exception occurs */ private void executeScripts(String strScriptsDirectory) throws UpdaterScriptException { File fileScriptsDirectory = new File(strScriptsDirectory); if (fileScriptsDirectory.exists()) { try { // Use a treeset to order files with a comparator TreeSet<File> set = new TreeSet<File>(new FileNameComparator()); File[] files = fileScriptsDirectory.listFiles(); if (files != null) { set.addAll(Arrays.asList(files)); for (File file : set) { SqlUtils.executeSqlFileScript(file.getAbsolutePath(), null); } } } catch (IOException e) { throw new UpdaterScriptException("file not found", e); } catch (SQLException e) { throw new UpdaterScriptException("SQL Error", e); } } }
From source file:net.sourceforge.fenixedu.applicationTier.Servico.person.SearchPerson.java
public CollectionPager<Person> run(SearchParameters searchParameters, Predicate predicate) { if (searchParameters.emptyParameters()) { return new CollectionPager<Person>(new ArrayList<Person>(), 25); }// w w w.ja va 2 s. c o m final Collection<Person> persons; if (searchParameters.getUsername() != null && searchParameters.getUsername().length() > 0) { final Person person = Person.readPersonByUsername(searchParameters.getUsername()); persons = new ArrayList<Person>(); if (person != null) { persons.add(person); } } else if (searchParameters.getDocumentIdNumber() != null && searchParameters.getDocumentIdNumber().length() > 0) { persons = Person.findPersonByDocumentID(searchParameters.getDocumentIdNumber()); } else if (searchParameters.getStudentNumber() != null) { final Student student = Student.readStudentByNumber(searchParameters.getStudentNumber()); persons = new ArrayList<Person>(); if (student != null) { persons.add(student.getPerson()); } } else if (searchParameters.getEmail() != null && searchParameters.getEmail().length() > 0) { final Person person = Person.readPersonByEmailAddress(searchParameters.getEmail()); persons = new ArrayList<Person>(); if (person != null) { persons.add(person); } } else if (searchParameters.getMechanoGraphicalNumber() != null) { final Employee employee = Employee.readByNumber(searchParameters.getMechanoGraphicalNumber()); final Student student = Student.readStudentByNumber(searchParameters.getMechanoGraphicalNumber()); persons = new TreeSet<Person>(); if (employee != null) { persons.add(employee.getPerson()); } if (student != null) { persons.add(student.getPerson()); } } else if (searchParameters.getName() != null) { persons = new ArrayList<Person>(); if (searchParameters.getExternalPersons() == null || !searchParameters.getExternalPersons()) { persons.addAll(Person.findInternalPerson(searchParameters.getName())); final Role roleBd = searchParameters.getRole(); if (roleBd != null) { for (final Iterator<Person> peopleIterator = persons.iterator(); peopleIterator.hasNext();) { final Person person = peopleIterator.next(); if (!person.hasPersonRoles(roleBd)) { peopleIterator.remove(); } } } final Department department = searchParameters.getDepartment(); if (department != null) { for (final Iterator<Person> peopleIterator = persons.iterator(); peopleIterator.hasNext();) { final Person person = peopleIterator.next(); final Teacher teacher = person.getTeacher(); if (teacher == null || teacher.getCurrentWorkingDepartment() != department) { peopleIterator.remove(); } } } } if (searchParameters.getExternalPersons() == null || searchParameters.getExternalPersons()) { persons.addAll(Person.findExternalPerson(searchParameters.getName())); } } else if (!StringUtils.isEmpty(searchParameters.getPaymentCode())) { persons = new ArrayList<Person>(); PaymentCode paymentCode = PaymentCode.readByCode(searchParameters.getPaymentCode()); if (paymentCode != null && paymentCode.getPerson() != null) { persons.add(paymentCode.getPerson()); } } else { persons = new ArrayList<Person>(0); } TreeSet<Person> result = new TreeSet<Person>(Person.COMPARATOR_BY_NAME_AND_ID); result.addAll(CollectionUtils.select(persons, predicate)); return new CollectionPager<Person>(result, 25); }
From source file:org.aika.network.neuron.lattice.AndNode.java
private void computePatternActivationsIntern(Iteration t, LatticeQueue queue, int pos, Iterable<Activation> firstOGActivations, Iterable<Activation> secondOGActivations) { for (Activation firstAct : firstOGActivations) { for (Activation secondAct : secondOGActivations) { Option o = Option.add(t.doc, true, firstAct.key.o, secondAct.key.o); if (o != null) { TreeSet<Activation> inputActs = new TreeSet<>(); if (firstAct.uses != null) { inputActs.addAll(firstAct.uses); }/*from www.ja v a 2s. co m*/ if (secondAct.uses != null) { inputActs.addAll(secondAct.uses); } addActivation(t, queue, new Key(pos, o, Math.max(firstAct.key.fired, secondAct.key.fired)), Math.max(firstAct.recurrentCount, secondAct.recurrentCount), inputActs); } } } }