Skip to content

Commit

Permalink
Merge pull request #1713 from apache/OAK-11112
Browse files Browse the repository at this point in the history
OAK-11112 : replaced Maps.newHashMapWithExpectedSize() with new HashM…
  • Loading branch information
rishabhdaim authored Sep 17, 2024
2 parents 5f8fe02 + 0ec3fc8 commit 874052d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.jackrabbit.guava.common.base.Stopwatch;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.api.security.user.Authorizable;
import org.apache.jackrabbit.api.security.user.Group;
import org.apache.jackrabbit.api.security.user.UserManager;
Expand Down Expand Up @@ -298,7 +297,7 @@ private Set<String> updateMembers(boolean isRemove, @NotNull String... memberIds
}

// calculate the contentID for each memberId and remember ids that cannot be processed
Map<String, String> updateMap = Maps.newHashMapWithExpectedSize(memberIds.length);
Map<String, String> updateMap = CollectionUtils.newHashMap(memberIds.length);
MembershipProvider mp = getMembershipProvider();
for (String memberId : memberIds) {
if (Strings.isNullOrEmpty(memberId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package org.apache.jackrabbit.oak.security.user;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.guava.common.collect.Sets;
import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Tree;
Expand Down Expand Up @@ -59,7 +58,7 @@ void setMembershipSizeThreshold(int membershipSizeThreshold) {
* @return {@code true} if the member was added
*/
boolean addMember(@NotNull Tree groupTree, @NotNull String memberContentId) {
Map<String, String> m = Maps.newHashMapWithExpectedSize(1);
Map<String, String> m = new HashMap<>(1);
m.put(memberContentId, "-");
return addMembers(groupTree, m).isEmpty();
}
Expand Down Expand Up @@ -189,7 +188,7 @@ private static String nextRefNodeName(@NotNull Tree membersList) {
* @return {@code true} if the member was removed.
*/
boolean removeMember(@NotNull Tree groupTree, @NotNull String memberContentId) {
Map<String, String> m = Maps.newHashMapWithExpectedSize(1);
Map<String, String> m = new HashMap<>(1);
m.put(memberContentId, "-");
return removeMembers(groupTree, m).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.jackrabbit.guava.common.base.Stopwatch;
import org.apache.jackrabbit.guava.common.collect.Iterables;
import org.apache.jackrabbit.guava.common.collect.Maps;
import org.apache.jackrabbit.guava.common.collect.Sets;
import org.apache.jackrabbit.api.JackrabbitSession;
import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
import org.apache.jackrabbit.api.security.principal.PrincipalManager;
Expand All @@ -33,6 +32,7 @@
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
Expand Down Expand Up @@ -657,7 +657,7 @@ void process() throws RepositoryException {
@NotNull
Map<String, Authorizable> getAuthorizablesToAdd(@NotNull Group gr, @NotNull Map<String, Authorizable> toRemove,
@NotNull Map<String, String> nonExisting) throws RepositoryException {
Map<String, Authorizable> toAdd = Maps.newHashMapWithExpectedSize(members.size());
Map<String, Authorizable> toAdd = CollectionUtils.newHashMap(members.size());
for (String contentId : members) {
// NOTE: no need to check for re-mapped uuids with the referenceTracker because
// ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW is not supported for user/group imports (see line 189)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.jackrabbit.oak.segment;

import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
import static org.apache.jackrabbit.guava.common.collect.Maps.newHashMapWithExpectedSize;
import static java.util.Collections.nCopies;

import java.lang.ref.WeakReference;
Expand All @@ -30,6 +29,7 @@
import java.util.Set;
import java.util.UUID;

import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -130,8 +130,7 @@ void collectReferencedIds(Collection<SegmentId> ids) {

private synchronized Collection<SegmentId> refresh() {
int size = references.size();
Map<SegmentId, WeakReference<SegmentId>> ids =
newHashMapWithExpectedSize(size);
Map<SegmentId, WeakReference<SegmentId>> ids = CollectionUtils.newHashMap(size);

boolean hashCollisions = false;
boolean emptyReferences = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.jackrabbit.oak.segment.file.tar;

import static org.apache.jackrabbit.guava.common.collect.Maps.newHashMapWithExpectedSize;
import static org.apache.jackrabbit.oak.segment.file.tar.TarConstants.GRAPH_MAGIC;

import java.io.IOException;
Expand All @@ -29,6 +28,7 @@
import java.util.zip.CRC32;

import org.apache.jackrabbit.oak.commons.Buffer;
import org.apache.jackrabbit.oak.commons.collections.CollectionUtils;
import org.apache.jackrabbit.oak.segment.util.ReaderAtEnd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -93,7 +93,7 @@ public static Buffer loadGraph(ReaderAtEnd readerAtEnd) throws IOException {
public static Map<UUID, List<UUID>> parseGraph(Buffer buffer) {
int nEntries = buffer.getInt(buffer.limit() - 12);

Map<UUID, List<UUID>> graph = newHashMapWithExpectedSize(nEntries);
Map<UUID, List<UUID>> graph = CollectionUtils.newHashMap(nEntries);

for (int i = 0; i < nEntries; i++) {
long msb = buffer.getLong();
Expand Down

0 comments on commit 874052d

Please sign in to comment.