Skip to content

Commit

Permalink
Merge pull request apache#1802 from apache/OAK-11205
Browse files Browse the repository at this point in the history
OAK-11205 : removed usage of Maps.newTreeMap
  • Loading branch information
rishabhdaim authored Oct 17, 2024
2 parents f664d88 + 0b7ac04 commit 243ec60
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.apache.jackrabbit.guava.common.base.Preconditions.checkState;
import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static org.apache.jackrabbit.guava.common.collect.Maps.newTreeMap;
import static java.util.Collections.emptyList;
import static org.apache.jackrabbit.JcrConstants.JCR_HASORDERABLECHILDNODES;
import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
Expand Down Expand Up @@ -54,6 +53,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Predicate;

import javax.jcr.PropertyType;
Expand Down Expand Up @@ -187,7 +187,7 @@ public String getPrimaryItemName() {
*/
@Override @NotNull
public PropertyDefinition[] getDeclaredPropertyDefinitions() {
Map<Integer, PropertyDefinition> definitions = newTreeMap();
Map<Integer, PropertyDefinition> definitions = new TreeMap<>();
for (Tree child : Iterables.filter(definition.getChildren(), PrimaryTypePredicate.PROPERTY_DEF_PREDICATE::test)) {
definitions.put(getIndex(child), new PropertyDefinitionImpl(child, this, mapper));
}
Expand All @@ -201,7 +201,7 @@ public PropertyDefinition[] getDeclaredPropertyDefinitions() {
*/
@Override @NotNull
public NodeDefinition[] getDeclaredChildNodeDefinitions() {
Map<Integer, NodeDefinition> definitions = newTreeMap();
Map<Integer, NodeDefinition> definitions = new TreeMap<>();
for (Tree child : Iterables.filter(definition.getChildren(), PrimaryTypePredicate.CHILDNODE_DEF_PREDICATE::test)) {
definitions.put(getIndex(child), new NodeDefinitionImpl(child, this, mapper));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.jackrabbit.guava.common.base.Joiner;
import org.apache.jackrabbit.guava.common.collect.ArrayListMultimap;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.ListMultimap;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.guava.common.hash.Hashing;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.commons.IOUtils;
Expand Down Expand Up @@ -228,7 +228,7 @@ private Map<String, List<LocalIndexDir>> getIndexesPerPath() throws IOException
pathToDirMap.get(localIndexDir.getJcrPath()).add(localIndexDir);
}

Map<String, List<LocalIndexDir>> result = Maps.newTreeMap();
Map<String, List<LocalIndexDir>> result = new TreeMap<>();
for (Map.Entry<String, Collection<LocalIndexDir>> e : pathToDirMap.asMap().entrySet()){
List<LocalIndexDir> sortedDirs = new ArrayList<>(e.getValue());
Collections.sort(sortedDirs, Collections.<LocalIndexDir>reverseOrder());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import com.mongodb.ReadPreference;
import org.apache.jackrabbit.guava.common.collect.Maps;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.client.MongoCollection;
Expand Down Expand Up @@ -65,8 +65,7 @@ public static void repair(MongoDocumentStore store, String path) {
}
}

SortedMap<Revision, String> commitRoot = Maps
.newTreeMap(NodeDocumentHelper.getLocalCommitRoot(doc));
SortedMap<Revision, String> commitRoot = new TreeMap<>(NodeDocumentHelper.getLocalCommitRoot(doc));
if (!commitRoot.keySet().retainAll(changes)) {
System.out.println("Nothing to repair on " + path);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package org.apache.jackrabbit.oak.explorer;

import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;

import static org.apache.jackrabbit.guava.common.collect.Maps.newTreeMap;
import static org.apache.jackrabbit.guava.common.collect.Sets.intersection;
import static org.apache.jackrabbit.guava.common.escape.Escapers.builder;
import static java.util.Collections.sort;
Expand All @@ -42,6 +40,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.UUID;

Expand Down Expand Up @@ -274,7 +273,7 @@ private void updateStats(DefaultMutableTreeNode parent) {

sb.append("Properties (count: ").append(state.getPropertyCount()).append(")");
sb.append(newline);
Map<String, String> propLines = newTreeMap();
Map<String, String> propLines = new TreeMap<>();
for (PropertyState ps : state.getProperties()) {
StringBuilder l = new StringBuilder();
l.append(" - ").append(ps.getName()).append(" = {").append(ps.getType()).append("} ");
Expand Down Expand Up @@ -317,7 +316,7 @@ private void updateStats(DefaultMutableTreeNode parent) {

sb.append("Child nodes (count: ").append(state.getChildNodeCount(Long.MAX_VALUE)).append(")");
sb.append(newline);
Map<String, String> childLines = newTreeMap();
Map<String, String> childLines = new TreeMap<>();
for (ChildNodeEntry ce : state.getChildNodeEntries()) {
StringBuilder l = new StringBuilder();
l.append(" + ").append(ce.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;

import org.apache.jackrabbit.guava.common.collect.Maps;
import java.util.TreeMap;

import static org.apache.jackrabbit.oak.plugins.document.Checkpoints.Info;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
Expand All @@ -35,7 +34,7 @@ public abstract class CheckpointsHelper {
public static SortedMap<Revision, Long> getCheckpoints(
DocumentNodeStore store) {
SortedMap<Revision, Info> checkpoints = store.getCheckpoints().getCheckpoints();
SortedMap<Revision, Long> map = Maps.newTreeMap(checkpoints.comparator());
SortedMap<Revision, Long> map = new TreeMap<>(checkpoints.comparator());
for (Map.Entry<Revision, Info> entry : checkpoints.entrySet()) {
map.put(entry.getKey(), entry.getValue().getExpiryTime());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.jackrabbit.oak.segment.file.tar;

import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static org.apache.jackrabbit.guava.common.collect.Maps.newTreeMap;
import static java.util.Collections.singletonList;
import static org.apache.jackrabbit.oak.segment.file.tar.GCGeneration.newGCGeneration;

Expand All @@ -36,6 +35,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Predicate;
Expand Down Expand Up @@ -83,7 +83,7 @@ static TarReader open(String file, SegmentArchiveManager archiveManager) throws
* @return An instance of {@link TarReader}.
*/
static TarReader open(Map<Character, String> files, TarRecovery recovery, SegmentArchiveManager archiveManager) throws IOException {
SortedMap<Character, String> sorted = newTreeMap();
SortedMap<Character, String> sorted = new TreeMap<>();
sorted.putAll(files);

List<String> list = newArrayList(sorted.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
Expand Down Expand Up @@ -177,7 +178,7 @@ SortedMap<Revision, Info> getCheckpoints() {
if (cdoc != null) {
data = (SortedMap<Revision, String>) cdoc.get(PROP_CHECKPOINT);
}
SortedMap<Revision, Info> checkpoints = Maps.newTreeMap(StableRevisionComparator.REVERSE);
SortedMap<Revision, Info> checkpoints = new TreeMap<>(StableRevisionComparator.REVERSE);
if (data != null) {
for (Map.Entry<Revision, String> entry : data.entrySet()) {
checkpoints.put(entry.getKey(), Info.fromString(entry.getValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ Iterator<NodeDocument> getPreviousDocLeaves() {
return Collections.emptyIterator();
}
// create a mutable copy
final NavigableMap<Revision, Range> ranges = Maps.newTreeMap(getPreviousRanges());
final NavigableMap<Revision, Range> ranges = new TreeMap<>(getPreviousRanges());
return new AbstractIterator<NodeDocument>() {
@Override
protected NodeDocument computeNext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
Expand Down Expand Up @@ -154,7 +155,7 @@ public BackgroundWriteStats persist(@NotNull DocumentStore store,
Map<Path, Revision> pending;
try {
snapshot.acquiring(getMostRecentRevision());
pending = Maps.newTreeMap(PathComparator.INSTANCE);
pending = new TreeMap<>(PathComparator.INSTANCE);
pending.putAll(map);
sweepRev = sweepRevision.get();
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
Expand All @@ -97,7 +98,6 @@
import org.apache.jackrabbit.guava.common.base.Throwables;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;

import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
Expand Down Expand Up @@ -4479,8 +4479,7 @@ public void propertyAdded(PropertyState after)
*/
private boolean isDocDeleted(NodeDocument doc, RevisionContext context) {
boolean latestDeleted = false;
SortedMap<Revision, String> localDeleted =
Maps.newTreeMap(StableRevisionComparator.REVERSE);
SortedMap<Revision, String> localDeleted = new TreeMap<>(StableRevisionComparator.REVERSE);
localDeleted.putAll(doc.getLocalDeleted());

for (Map.Entry<Revision, String> entry : localDeleted.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;

Expand All @@ -47,7 +48,6 @@
import org.apache.jackrabbit.oak.spi.state.NodeStore;
import org.junit.Test;

import static org.apache.jackrabbit.guava.common.collect.Maps.newTreeMap;
import static java.lang.System.currentTimeMillis;
import static java.util.Collections.singletonList;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
Expand Down Expand Up @@ -315,7 +315,7 @@ public void getPreviousDocLeavesAfterGC2() throws Exception {
@Test
public void testPurgeUncommittedRevisions() {

final SortedMap<Revision, String> localRevisionMap = newTreeMap(REVERSE);
final SortedMap<Revision, String> localRevisionMap = new TreeMap<>(REVERSE);
for (int i = 0; i < 140; i++) {
localRevisionMap.putIfAbsent(new Revision(currentTimeMillis(), i, 1), "nc");
}
Expand All @@ -336,7 +336,7 @@ public void testPurgeUncommittedRevisions() {
@Test
public void testPurgeUncommittedRevisionsWithLaterRevisions() {

final SortedMap<Revision, String> localRevisionMap = newTreeMap(REVERSE);
final SortedMap<Revision, String> localRevisionMap = new TreeMap<>(REVERSE);
for (int i = 0; i < 140; i++) {
localRevisionMap.putIfAbsent(new Revision(currentTimeMillis(), i, 1), "nc");
}
Expand All @@ -361,7 +361,7 @@ public void testPurgeUncommittedRevisionsWithLaterRevisions() {
@Test
public void testPurgeUncommittedRevisionsWithOlderRevisions() {

final SortedMap<Revision, String> localRevisionMap = newTreeMap(REVERSE);
final SortedMap<Revision, String> localRevisionMap = new TreeMap<>(REVERSE);
for (int i = 0; i < 140; i++) {
localRevisionMap.putIfAbsent(new Revision(currentTimeMillis(), i, 1), "nc");
}
Expand All @@ -386,7 +386,7 @@ public void testPurgeUncommittedRevisionsWithOlderRevisions() {
@Test
public void testPurgeCollisionMarkers() {

final SortedMap<Revision, String> collisions = newTreeMap(REVERSE);
final SortedMap<Revision, String> collisions = new TreeMap<>(REVERSE);
for (int i = 0; i < 140; i++) {
collisions.putIfAbsent(new Revision(currentTimeMillis(), i, 1), "nc");
}
Expand All @@ -405,7 +405,7 @@ public void testPurgeCollisionMarkers() {
@Test
public void testPurgeCollisionMarkersWithLaterRevisions() {

final SortedMap<Revision, String> collisions = newTreeMap(REVERSE);
final SortedMap<Revision, String> collisions = new TreeMap<>(REVERSE);
for (int i = 0; i < 140; i++) {
collisions.putIfAbsent(new Revision(currentTimeMillis(), i, 1), "nc");
}
Expand All @@ -428,7 +428,7 @@ public void testPurgeCollisionMarkersWithLaterRevisions() {
@Test
public void testPurgeCollisionMarkersWithOlderRevisions() {

final SortedMap<Revision, String> collisions = newTreeMap(REVERSE);
final SortedMap<Revision, String> collisions = new TreeMap<>(REVERSE);
for (int i = 0; i < 140; i++) {
collisions.putIfAbsent(new Revision(currentTimeMillis(), i, 1), "nc");
}
Expand Down

0 comments on commit 243ec60

Please sign in to comment.