Search in sources :

Example 21 with SortedSet

use of java.util.SortedSet in project mapdb by jankotek.

the class TreeSubSetTest method testSubSetContents2.

public void testSubSetContents2() {
    NavigableSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 22 with SortedSet

use of java.util.SortedSet in project voltdb by VoltDB.

the class TestCOWNavigableSet method testSubSetContents.

//    /**
//     * A deserialized serialized set has same elements
//     */
//    public void testSerialization() throws Exception {
//        NavigableSet x = populatedSet(SIZE);
//        NavigableSet y = serialClone(x);
//
//        assertTrue(x != y);
//        assertEquals(x.size(), y.size());
//        assertEquals(x, y);
//        assertEquals(y, x);
//        while (!x.isEmpty()) {
//            assertFalse(y.isEmpty());
//            assertEquals(x.pollFirst(), y.pollFirst());
//        }
//        assertTrue(y.isEmpty());
//    }
/**
     * subSet returns set with keys in requested range
     */
public void testSubSetContents() {
    COWNavigableSet set = set5();
    SortedSet sm = set.subSet(two, four);
    assertEquals(two, sm.first());
    assertEquals(three, sm.last());
    assertEquals(2, sm.size());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
//        j.remove();
//        assertFalse(set.contains(two));
//        assertEquals(4, set.size());
//        assertEquals(1, sm.size());
//        assertEquals(three, sm.first());
//        assertEquals(three, sm.last());
//        assertTrue(sm.remove(three));
//        assertTrue(sm.isEmpty());
//        assertEquals(3, set.size());
}
Also used : Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 23 with SortedSet

use of java.util.SortedSet in project intellij-community by JetBrains.

the class AddMissingRequiredAnnotationParametersFix method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
    final PsiNameValuePair[] addedParameters = myAnnotation.getParameterList().getAttributes();
    final TObjectIntHashMap<String> annotationsOrderMap = getAnnotationsOrderMap();
    final SortedSet<Pair<String, PsiAnnotationMemberValue>> newParameters = new TreeSet<>(Comparator.comparingInt(o -> annotationsOrderMap.get(o.getFirst())));
    final boolean order = isAlreadyAddedOrdered(annotationsOrderMap, addedParameters);
    if (order) {
        if (addedParameters.length != 0) {
            final PsiAnnotationParameterList parameterList = myAnnotation.getParameterList();
            parameterList.deleteChildRange(addedParameters[0], addedParameters[addedParameters.length - 1]);
            for (final PsiNameValuePair addedParameter : addedParameters) {
                final String name = addedParameter.getName();
                final PsiAnnotationMemberValue value = addedParameter.getValue();
                if (name == null || value == null) {
                    LOG.error(String.format("Invalid annotation parameter name = %s, value = %s", name, value));
                    continue;
                }
                newParameters.add(Pair.create(name, value));
            }
        }
    }
    final PsiExpression nullValue = JavaPsiFacade.getElementFactory(project).createExpressionFromText(PsiKeyword.NULL, null);
    for (final String misssedParameter : myMissedElements) {
        newParameters.add(Pair.create(misssedParameter, nullValue));
    }
    TemplateBuilderImpl builder = null;
    for (final Pair<String, PsiAnnotationMemberValue> newParameter : newParameters) {
        final PsiAnnotationMemberValue value = myAnnotation.setDeclaredAttributeValue(newParameter.getFirst(), newParameter.getSecond());
        if (myMissedElements.contains(newParameter.getFirst())) {
            if (builder == null) {
                builder = new TemplateBuilderImpl(myAnnotation.getParameterList());
            }
            builder.replaceElement(value, new EmptyExpression(), true);
        }
    }
    editor.getCaretModel().moveToOffset(myAnnotation.getParameterList().getTextRange().getStartOffset());
    final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    final Document document = documentManager.getDocument(file);
    if (document == null) {
        throw new IllegalStateException();
    }
    documentManager.doPostponedOperationsAndUnblockDocument(document);
    TemplateManager.getInstance(project).startTemplate(editor, builder.buildInlineTemplate(), null);
}
Also used : QuickFixBundle(com.intellij.codeInsight.daemon.QuickFixBundle) IncorrectOperationException(com.intellij.util.IncorrectOperationException) SortedSet(java.util.SortedSet) StringUtil(com.intellij.openapi.util.text.StringUtil) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) Document(com.intellij.openapi.editor.Document) Collection(java.util.Collection) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) ContainerUtil(com.intellij.util.containers.ContainerUtil) Editor(com.intellij.openapi.editor.Editor) TreeSet(java.util.TreeSet) TemplateManager(com.intellij.codeInsight.template.TemplateManager) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) com.intellij.psi(com.intellij.psi) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Document(com.intellij.openapi.editor.Document) TemplateBuilderImpl(com.intellij.codeInsight.template.TemplateBuilderImpl) TreeSet(java.util.TreeSet) Pair(com.intellij.openapi.util.Pair)

Example 24 with SortedSet

use of java.util.SortedSet in project gerrit by GerritCodeReview.

the class Schema_130 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException {
    SortedSet<Project.NameKey> repoList = repoManager.list();
    SortedSet<Project.NameKey> repoUpgraded = new TreeSet<>();
    ui.message("\tMigrating " + repoList.size() + " repositories ...");
    for (Project.NameKey projectName : repoList) {
        try (Repository git = repoManager.openRepository(projectName);
            MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, projectName, git)) {
            ProjectConfigSchemaUpdate cfg = ProjectConfigSchemaUpdate.read(md);
            cfg.removeForceFromPermission("pushTag");
            if (cfg.isUpdated()) {
                repoUpgraded.add(projectName);
            }
            cfg.save(serverUser, COMMIT_MSG);
        } catch (ConfigInvalidException | IOException ex) {
            throw new OrmException("Cannot migrate project " + projectName, ex);
        }
    }
    ui.message("\tMigration completed:  " + repoUpgraded.size() + " repositories updated:");
    ui.message("\t" + repoUpgraded.stream().map(n -> n.get()).collect(joining(" ")));
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) OrmException(com.google.gwtorm.server.OrmException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SortedSet(java.util.SortedSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) Inject(com.google.inject.Inject) IOException(java.io.IOException) Collectors.joining(java.util.stream.Collectors.joining) TreeSet(java.util.TreeSet) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) GitReferenceUpdated(com.google.gerrit.server.extensions.events.GitReferenceUpdated) Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) IOException(java.io.IOException) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) TreeSet(java.util.TreeSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 25 with SortedSet

use of java.util.SortedSet in project lucene-solr by apache.

the class Config method complainAboutUnknownAttributes.

/**
   * Logs an error and throws an exception if any of the element(s) at the given elementXpath
   * contains an attribute name that is not among knownAttributes. 
   */
public void complainAboutUnknownAttributes(String elementXpath, String... knownAttributes) {
    SortedMap<String, SortedSet<String>> problems = new TreeMap<>();
    NodeList nodeList = getNodeList(elementXpath, false);
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Element element = (Element) nodeList.item(i);
        Set<String> unknownAttributes = getUnknownAttributes(element, knownAttributes);
        if (null != unknownAttributes) {
            String elementName = element.getNodeName();
            SortedSet<String> allUnknownAttributes = problems.get(elementName);
            if (null == allUnknownAttributes) {
                allUnknownAttributes = new TreeSet<>();
                problems.put(elementName, allUnknownAttributes);
            }
            allUnknownAttributes.addAll(unknownAttributes);
        }
    }
    if (problems.size() > 0) {
        StringBuilder message = new StringBuilder();
        for (Map.Entry<String, SortedSet<String>> entry : problems.entrySet()) {
            if (message.length() > 0) {
                message.append(", ");
            }
            message.append('<');
            message.append(entry.getKey());
            for (String attributeName : entry.getValue()) {
                message.append(' ');
                message.append(attributeName);
                message.append("=\"...\"");
            }
            message.append('>');
        }
        message.insert(0, "Unknown attribute(s) on element(s): ");
        String msg = message.toString();
        SolrException.log(log, msg);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, msg);
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) TreeMap(java.util.TreeMap) SortedSet(java.util.SortedSet) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) SolrException(org.apache.solr.common.SolrException)

Aggregations

SortedSet (java.util.SortedSet)377 TreeSet (java.util.TreeSet)174 Iterator (java.util.Iterator)116 HashMap (java.util.HashMap)94 Map (java.util.Map)94 Set (java.util.Set)90 ArrayList (java.util.ArrayList)78 List (java.util.List)78 TreeMap (java.util.TreeMap)61 HashSet (java.util.HashSet)60 IOException (java.io.IOException)58 NavigableSet (java.util.NavigableSet)56 Test (org.junit.Test)50 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 SortedMap (java.util.SortedMap)31 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)30 Comparator (java.util.Comparator)30 File (java.io.File)28 Collection (java.util.Collection)28