Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Mar 22, 2024
1 parent 53a1ca8 commit 0c7c9f4
Showing 1 changed file with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@

package com.cognifide.apm.main.permissions;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.jcr.PropertyType;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.ValueFormatException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

public class Restrictions {
Expand Down Expand Up @@ -62,17 +60,10 @@ public class Restrictions {

public Restrictions(String glob, List<String> ntNames, List<String> itemNames, Map<String, Object> customRestrictions) {
this.glob = glob;
this.ntNames = notNullCopy(ntNames);
this.itemNames = notNullCopy(itemNames);
this.customRestrictions = notNullCopy(customRestrictions);
}

private List<String> notNullCopy(List<String> strings) {
return strings != null ? ImmutableList.copyOf(strings) : Collections.emptyList();
}

private Map<String, Object> notNullCopy(Map<String, Object> items) {
return items != null ? ImmutableMap.copyOf(items) : Collections.emptyMap();
this.ntNames = ntNames;
this.itemNames = itemNames;
this.customRestrictions = Optional.ofNullable(customRestrictions)
.orElse(Collections.emptyMap());
}

public Map<String, Value> getSingleValueRestrictions(ValueFactory valueFactory) throws ValueFormatException {
Expand All @@ -93,7 +84,7 @@ public Map<String, Value> getSingleValueRestrictions(ValueFactory valueFactory)
}

private void addRestriction(ValueFactory valueFactory, Map<String, Value> result, String key, String value) throws ValueFormatException {
if (StringUtils.isNotBlank(value)) {
if (value != null) {
result.put(key, createValue(valueFactory, key, value));
}
}
Expand Down Expand Up @@ -132,7 +123,7 @@ public Map<String, Value[]> getMultiValueRestrictions(ValueFactory valueFactory)
}

private void addRestrictions(ValueFactory valueFactory, Map<String, Value[]> result, String key, List<String> names) throws ValueFormatException {
if (!CollectionUtils.isEmpty(names)) {
if (names != null) {
result.put(key, createRestrictions(valueFactory, key, names));
}
}
Expand Down

0 comments on commit 0c7c9f4

Please sign in to comment.