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());
}
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());
}
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);
}
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(" ")));
}
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);
}
}
Aggregations