Java Code Examples for java.util.SortedSet#add()

The following examples show how to use java.util.SortedSet#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CanonicalizerPhysical.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
 
Example 2
Source File: MacAddressCompleter.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
    public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    StringsCompleter delegate = new StringsCompleter();
    OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
    Set<MacAddress> set = osNetService.externalPeerRouters().stream()
            .map(ExternalPeerRouter::macAddress)
            .collect(Collectors.toSet());
    SortedSet<String> strings = delegate.getStrings();

    Iterator<MacAddress> it = set.iterator();

    while (it.hasNext()) {
        strings.add(it.next().toString());
    }

    return delegate.complete(session, commandLine, candidates);

}
 
Example 3
Source File: MtasSolrResultUtil.java    From mtas with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the ids from parameters.
 *
 * @param params the params
 * @param prefix the prefix
 * @return the ids from parameters
 */
public static SortedSet<String> getIdsFromParameters(SolrParams params,
    String prefix) {
  SortedSet<String> ids = new TreeSet<>();
  Iterator<String> it = params.getParameterNamesIterator();
  Pattern pattern = Pattern
      .compile("^" + Pattern.quote(prefix) + "\\.([^\\.]+)(\\..*|$)");
  while (it.hasNext()) {
    String item = it.next();
    Matcher m = pattern.matcher(item);
    if (m.matches()) {
      ids.add(m.group(1));
    }
  }
  return ids;
}
 
Example 4
Source File: CanonicalizerPhysical.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the Attr[]s to be output for the given element.
 * <br>
 * The code of this method is a copy of {@link #handleAttributes(Element,
 * NameSpaceSymbTable)},
 * whereas it takes into account that subtree-c14n is -- well -- subtree-based.
 * So if the element in question isRoot of c14n, it's parent is not in the
 * node set, as well as all other ancestors.
 *
 * @param element
 * @param ns
 * @return the Attr[]s to be output
 * @throws CanonicalizationException
 */
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
    throws CanonicalizationException {
    if (!element.hasAttributes()) {
        return null;
    }

    // result will contain all the attrs declared directly on that element
    final SortedSet<Attr> result = this.result;
    result.clear();

    if (element.hasAttributes()) {
        NamedNodeMap attrs = element.getAttributes();
        int attrsLength = attrs.getLength();

        for (int i = 0; i < attrsLength; i++) {
            Attr attribute = (Attr) attrs.item(i);
            result.add(attribute);
        }
    }

    return result.iterator();
}
 
Example 5
Source File: TaskReportRenderer.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void writeTask(TaskDetails task, String prefix) {
    getTextOutput().text(prefix);
    getTextOutput().withStyle(Identifier).text(task.getPath());
    if (GUtil.isTrue(task.getDescription())) {
        getTextOutput().withStyle(Description).format(" - %s", task.getDescription());
    }
    if (detail) {
        SortedSet<Path> sortedDependencies = new TreeSet<Path>();
        for (TaskDetails dependency : task.getDependencies()) {
            sortedDependencies.add(dependency.getPath());
        }
        if (sortedDependencies.size() > 0) {
            getTextOutput().withStyle(Info).format(" [%s]", CollectionUtils.join(", ", sortedDependencies));
        }
    }
    getTextOutput().println();
}
 
Example 6
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sorted list of regions used in the resources with the given language.
 * @param currentLanguage the current language the region must be associated with.
 */
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();

            // get the language
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null && currentLanguage.equals(locale.getLanguage())
                    && locale.getRegion() != null) {
                set.add(locale.getRegion());
            }
        }
    }

    return set;
}
 
Example 7
Source File: LoadStep.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void doit (Collection<SystemInfo> unused,
                  Sheet sheet)
        throws StepException
{
    final Score score = sheet.getScore();
    final File imageFile = score.getImageFile();
    final int index = sheet.getPage()
            .getIndex();
    final SortedSet<Integer> set = new TreeSet<>();
    set.add(index);

    SortedMap<Integer, RenderedImage> images =
            PictureLoader.loadImages(imageFile, set);
    if (images != null) {
        sheet.setImage(images.get(index));
    }
}
 
Example 8
Source File: MemoryStorage.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
@Override
public SortedSet<UUID> getRepairRunIdsForCluster(String clusterName) {
  SortedSet<UUID> repairRunIds = Sets.newTreeSet((u0, u1) -> (int)(u0.timestamp() - u1.timestamp()));
  for (RepairRun repairRun : repairRuns.values()) {
    if (repairRun.getClusterName().equalsIgnoreCase(clusterName)) {
      repairRunIds.add(repairRun.getId());
    }
  }
  return repairRunIds;
}
 
Example 9
Source File: UserSqlLargeStat.java    From dble with GNU General Public License v2.0 5 votes vote down vote up
public void recycle() {
    if (queries.size() > count) {
        SortedSet<SqlLarge> queries2 = new ConcurrentSkipListSet<>();
        List<SqlLarge> keyList = new ArrayList<>(queries);
        int i = 0;
        for (SqlLarge key : keyList) {
            if (i == count) {
                break;
            }
            queries2.add(key);
            i++;
        }
        queries = queries2;
    }
}
 
Example 10
Source File: Operator.java    From pumpernickel with MIT License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Operator convertJoinedAnd(And and) {
	List<Operator> andOperands = new ArrayList(and.getOperands());
	Map<String, SortedSet<Object>> notEqualTos = new HashMap<>();
	Iterator<Operator> iter = andOperands.iterator();
	while (iter.hasNext()) {
		Operator andOperand = iter.next();
		if (andOperand instanceof Not
				&& andOperand.getOperand(0) instanceof EqualTo) {
			iter.remove();
			EqualTo equalTo = (EqualTo) andOperand.getOperand(0);
			SortedSet<Object> c = notEqualTos.get(equalTo.getAttribute());
			if (c == null) {
				c = new TreeSet<>(NULL_SAFE_COMPARATOR);
				notEqualTos.put(equalTo.getAttribute(), c);
			}
			c.add(equalTo.getValue());
		}
	}

	for (Entry<String, SortedSet<Object>> entry : notEqualTos.entrySet()) {
		andOperands
				.add(new Not(In.create(entry.getKey(), entry.getValue())));
	}

	if (andOperands.size() == 1)
		return andOperands.iterator().next();
	return new And(andOperands);
}
 
Example 11
Source File: GradebookManagerImpl.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public SortedSet getReleasedGradebooksByContext(final String context, final String sortBy, final boolean ascending) {
	if (context == null) {
		throw new IllegalArgumentException("Null Argument");
	} else {
		HibernateCallback hcb = session -> {

               Criteria crit = session.createCriteria(GradebookImpl.class).add(
                       Expression.eq(CONTEXT, context)).add(
                       Expression.eq(RELEASED, new Boolean(true)));

               List gbs = crit.list();

               Comparator gbComparator = determineComparator(sortBy, ascending);

               SortedSet gradebooks = new TreeSet(gbComparator);

               Iterator gbIterator = gbs.iterator();

               while (gbIterator.hasNext()) {
                   gradebooks.add((Gradebook) gbIterator.next());

               }

               return gradebooks;
           };

		return (SortedSet) getHibernateTemplate().execute(hcb);
	}
}
 
Example 12
Source File: M2ConfigProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private SortedSet<M2Configuration> createProfilesList() {
        List<String> profs = profileHandler.getAllProfiles();
        SortedSet<M2Configuration> config = new TreeSet<M2Configuration>();
//        config.add(DEFAULT);
        for (String prof : profs) {
            M2Configuration c = new M2Configuration(prof, project.getProjectDirectory());
            c.setActivatedProfiles(Collections.singletonList(prof));
            config.add(c);
        }
        return config;
    }
 
Example 13
Source File: JdbcAssert.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private SortedSet<String> unsortedList(List<String> strings) {
  final SortedSet<String> set = new TreeSet<>();
  for (String string : strings) {
    set.add(string + "\n");
  }
  return set;
}
 
Example 14
Source File: EncapTypeCompleter.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
    // Delegate string completer
    StringsCompleter delegate = new StringsCompleter();
    SortedSet<String> strings = delegate.getStrings();

    for (EncapsulationType encapType : EncapsulationType.values()) {
        strings.add(encapType.toString());
    }

    // Now let the completer do the work for figuring out what to offer.
    return delegate.complete(session, commandLine, candidates);
}
 
Example 15
Source File: TestTraceIdFilter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * Given a TraceIdFilter that passes traceIds included in a set
 * <i>idsToPass</i>, assert that a {@link AbstractTraceEvent} object
 * <i>event</i> with traceId not element of <i>idsToPass</i> IS passed through
 * the filter.
 */
@Test
public void testAssertPassTraceId() {
	final long firstTimestamp = 53222; // any number fits
	final long traceIdToPass = 11L; // (must be element of idsToPass)

	final SortedSet<Long> idsToPass = new TreeSet<>();
	idsToPass.add(0 + traceIdToPass);
	idsToPass.add(1 + traceIdToPass);

	final TraceIdFilter traceidFilter = new TraceIdFilter(false, idsToPass.toArray(new Long[idsToPass.size()]));

	final AbstractTraceEvent[] traceEvents = BookstoreEventRecordFactory
			.validSyncTraceBeforeAfterEvents(firstTimestamp, traceIdToPass, TestTraceIdFilter.SESSION_ID,
					TestTraceIdFilter.HOSTNAME)
			.getTraceEvents();

	for (final AbstractTraceEvent e : traceEvents) {
		Assert.assertTrue("Testcase invalid", idsToPass.contains(e.getTraceId()));
	}

	StageTester.test(traceidFilter).and()
	.send(traceEvents).to(traceidFilter.getMonitoringRecordsCombinedInputPort()).and()
	.start();

	Assert.assertThat(traceidFilter.getMatchingTraceIdOutputPort(), StageTester.produces(traceEvents));
	Assert.assertThat(traceidFilter.getMismatchingTraceIdOutputPort(), StageTester.producesNothing());
}
 
Example 16
Source File: OrphanChainsMonitor.java    From nuls-v2 with MIT License 4 votes vote down vote up
private void copy(Integer chainId, SortedSet<Chain> maintainedOrphanChains, Chain orphanChain) {
    //如果标记为数据错误,orphanChain不会复制到新的孤儿链集合,也不会进入分叉链集合,所有orphanChain的直接子链移除父链引用,标记为ChainTypeEnum.ORPHAN,就是断开与数据错误的链的关联关系
    if (orphanChain.getType().equals(ChainTypeEnum.DATA_ERROR)) {
        orphanChain.getSons().forEach(e -> {e.setType(ChainTypeEnum.ORPHAN);e.setParent(null);});
        return;
    }
    //如果标记为主链重复,orphanChain不会复制到新的孤儿链集合,也不会进入分叉链集合,所有orphanChain的直接子链标记为ChainTypeEnum.MASTER_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.MASTER_DUPLICATE)) {
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.MASTER_FORK));
        return;
    }
    //如果标记为分叉链重复,orphanChain不会复制到新的孤儿链集合,也不会进入分叉链集合,所有orphanChain的直接子链标记为ChainTypeEnum.FORK_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.FORK_DUPLICATE)) {
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.FORK_FORK));
        return;
    }
    //如果标记为孤儿链重复,orphanChain不会复制到新的孤儿链集合,也不会进入分叉链集合,所有orphanChain的直接子链标记为ChainTypeEnum.ORPHAN_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.ORPHAN_DUPLICATE)) {
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.ORPHAN_FORK));
        return;
    }
    //如果标记为与主链相连,orphanChain不会复制到新的孤儿链集合,也不会进入分叉链集合,但是所有orphanChain的直接子链标记为ChainTypeEnum.MASTER_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.MASTER_APPEND)) {
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.MASTER_FORK));
        return;
    }
    //如果标记为从主链分叉,orphanChain不会复制到新的孤儿链集合,但是会进入分叉链集合,所有orphanChain的直接子链标记为ChainTypeEnum.FORK_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.MASTER_FORK)) {
        BlockChainManager.addForkChain(chainId, orphanChain);
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.FORK_FORK));
        return;
    }
    //如果标记为与分叉链相连,orphanChain不会复制到新的孤儿链集合,也不会进入分叉链集合,但是所有orphanChain的直接子链标记为ChainTypeEnum.FORK_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.FORK_APPEND)) {
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.FORK_FORK));
        return;
    }
    //如果标记为从分叉链分叉,orphanChain不会复制到新的孤儿链集合,但是会进入分叉链集合,所有orphanChain的直接子链标记为ChainTypeEnum.FORK_FORK
    if (orphanChain.getType().equals(ChainTypeEnum.FORK_FORK)) {
        BlockChainManager.addForkChain(chainId, orphanChain);
        orphanChain.getSons().forEach(e -> e.setType(ChainTypeEnum.FORK_FORK));
        return;
    }
    //如果标记为与孤儿链相连,不会复制到新的孤儿链集合,所有orphanChain的直接子链会复制到新的孤儿链集合,类型不变
    if (orphanChain.getType().equals(ChainTypeEnum.ORPHAN_APPEND)) {
        return;
    }
    //如果标记为与孤儿链分叉,会复制到新的孤儿链集合,所有orphanChain的直接子链会复制到新的孤儿链集合,类型不变
    if (orphanChain.getType().equals(ChainTypeEnum.ORPHAN_FORK)) {
        maintainedOrphanChains.add(orphanChain);
        return;
    }
    //如果标记为孤儿链(未变化),或者从孤儿链分叉,复制到新的孤儿链集合
    if (orphanChain.getType().equals(ChainTypeEnum.ORPHAN)) {
        maintainedOrphanChains.add(orphanChain);
    }
}
 
Example 17
Source File: AuthoringController.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Extract web from content to taskList item.
    */
   private void extractFormToTaskListItem(HttpServletRequest request, TaskListItemForm itemForm) throws Exception {
/*
 * BE CAREFUL: This method will copy necessary info from request form to a old
 * or new TaskListItem instance. It gets all info EXCEPT TaskListItem.createDate
 * and TaskListItem.createBy, which need be set when persisting this taskList
 * item.
 */

SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession()
	.getAttribute(itemForm.getSessionMapID());
// check whether it is "edit(old item)" or "add(new item)"
SortedSet<TaskListItem> taskListList = getTaskListItemList(sessionMap);
int itemIdx = NumberUtils.stringToInt(itemForm.getItemIndex(), -1);
TaskListItem item = null;

if (itemIdx == -1) { // add
    item = new TaskListItem();
    item.setCreateDate(new Timestamp(new Date().getTime()));
    int maxSeq = 1;
    if (taskListList != null && taskListList.size() > 0) {
	TaskListItem last = taskListList.last();
	maxSeq = last.getSequenceId() + 1;
    }
    item.setSequenceId(maxSeq);
    taskListList.add(item);
} else { // edit
    List<TaskListItem> rList = new ArrayList<>(taskListList);
    item = rList.get(itemIdx);
}

item.setTitle(itemForm.getTitle());
item.setDescription(itemForm.getDescription());
item.setCreateByAuthor(true);

item.setRequired(itemForm.isRequired());
item.setCommentsAllowed(itemForm.isCommentsAllowed());
item.setCommentsRequired(itemForm.isCommentsRequired());
item.setFilesAllowed(itemForm.isFilesAllowed());
item.setFilesRequired(itemForm.isFilesRequired());
item.setChildTask(itemForm.isChildTask());
item.setParentTaskName(itemForm.getParentTaskName());
   }
 
Example 18
Source File: RedissonSortedSetTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testTailSetTreeSet() {
    TreeSet<Integer> set = new TreeSet<Integer>();

    set.add(1);
    set.add(2);
    set.add(3);
    set.add(4);
    set.add(5);

    SortedSet<Integer> hs = set.tailSet(3);
    hs.add(10);

    assertThat(hs).containsExactly(3, 4, 5, 10);

    set.remove(4);

    assertThat(hs).containsExactly(3, 5, 10);

    set.remove(3);

    assertThat(hs).containsExactly(5, 10);

    hs.add(-1);
}
 
Example 19
Source File: SortFilesByPathMethod.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
    ExecutionStatistics.get().begin(NAME);
    if (arguments.size() != 1)
    {
        throw new TemplateModelException("Error, method expects one argument (Iterable<FileModel>)");
    }
    Iterable<Object> pathIterable = getIterable(arguments.get(0));

    Comparator<Object> fileModelComparator = new Comparator<Object>()
    {
        final FilePathComparator filePathComparator = new FilePathComparator();

        @Override
        public int compare(Object o1, Object o2)
        {
            return filePathComparator.compare(getFilePath(o1), getFilePath(o2));
        }

        private String getFilePath(Object o)
        {
            if (o == null)
                return null;
            else if (o instanceof FileModel)
                return ((FileModel)o).getFilePath();
            else if (o instanceof String)
                return (String)o;
            else
                throw new IllegalArgumentException("Unrecognized type: " + o.getClass().getName());
        }
    };

    SortedSet<Object> resultSet = new TreeSet<>(fileModelComparator);
    for (Object fm : pathIterable)
    {
        resultSet.add(fm);
    }

    ExecutionStatistics.get().end(NAME);
    return resultSet;
}
 
Example 20
Source File: OnDisconnectMethodComparatorTest.java    From spring-boot-netty with MIT License 4 votes vote down vote up
@Test(expected = IllegalStateException.class)
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
public void nonAnnotatedMethodSorting() {
    final SortedSet<Method> methods = new TreeSet<>(SpringNettyConfiguration.ON_DISCONNECT_METHOD_COMPARATOR);
    methods.add(NON_ANNOTATED_METHOD);
}