Skip to content

Commit

Permalink
fixed some code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Nov 3, 2023
1 parent 6afd12a commit 2016ca9
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ActionResult execute(final Context context) {
public ActionResult process(final Context context, boolean execute) {
ActionResult actionResult = context.createActionResult();
try {
Authorizable authorizable = null;
Authorizable authorizable;
if (shouldBeGroup) {
authorizable = context.getAuthorizableManager().getGroupIfExists(id);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class ActionUtils {
public static final String ASSERTION_FAILED_MSG = "Assertion failed";

private ActionUtils() {
// intentionally empty
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void addEntry(boolean allow, final List<Privilege> privileges,

Map<String, Value> singleValueRestrictions = restrictions.getSingleValueRestrictions(valueFactory);
Map<String, Value[]> multiValueRestrictions = restrictions.getMultiValueRestrictions(valueFactory);
jackrabbitAcl.addEntry(principal, privileges.toArray(new Privilege[privileges.size()]), allow,
jackrabbitAcl.addEntry(principal, privileges.toArray(new Privilege[]{}), allow,
singleValueRestrictions, multiValueRestrictions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public final class ActionUtils {
public static final String EXECUTION_INTERRUPTED_MSG = "Execution interrupted";

private ActionUtils() {
// intentionally empty
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public Message(String text, String type) {
this.type = type;
}

// Gson library needs this
private Message() {
// GSON library needs
}

public String getText() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.cognifide.apm.core.Property;
import com.cognifide.apm.core.grammar.argument.Arguments;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -82,7 +81,7 @@ public List<CommandDescription> getCommandDescriptions() {
}

private void sortReferences(List<CommandDescription> references) {
Collections.sort(references, Comparator.comparing(CommandDescription::getGroup, (o1, o2) -> {
references.sort(Comparator.comparing(CommandDescription::getGroup, (o1, o2) -> {
if (CORE_GROUP.equals(o1) && CORE_GROUP.equals(o2)) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import com.cognifide.apm.main.services.ApmActionsMainService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -92,15 +92,13 @@ public Optional<MapperDescriptor> getMapper(String name) {

@Override
public Collection<MapperDescriptor> getMappers() {
return mappers.get().values()
.stream()
.collect(Collectors.toList());
return new ArrayList<>(mappers.get().values());
}

private static Map<String, MapperDescriptor> createActionMappers(List<Class<?>> classes) {
MapperDescriptorFactory mapperDescriptorFactory = new MapperDescriptorFactory();
Map<String, MapperDescriptor> mappers = Maps.newHashMapWithExpectedSize(classes.size());
for (Class clazz : classes) {
for (Class<?> clazz : classes) {
try {
MapperDescriptor mapperDescriptor = mapperDescriptorFactory.create(clazz);
mappers.put(mapperDescriptor.getName(), mapperDescriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ private Optional<MappingDescriptor> create(Mapper mapper, Method method) {
}

private <T extends Annotation> T getAnnotation(Annotation[] annotations, Class<T> type) {
for (int i = 0; i < annotations.length; i++) {
if (type.isInstance(annotations[i])) {
return (T) annotations[i];
for (Annotation annotation : annotations) {
if (type.isInstance(annotation)) {
return (T) annotation;
}
}
return null;
Expand All @@ -129,16 +129,15 @@ private <T extends Annotation> boolean containsAnnotation(Annotation[] annotatio

private Class<? extends ApmType> getApmType(Type type) {
if (type instanceof Class) {
Class aClass = (Class) type;
if (String.class.equals(aClass)) {
Class<?> clazz = (Class<?>) type;
if (String.class.equals(clazz)) {
return ApmString.class;
}
if (Integer.class.equals(aClass)) {
} else if (Integer.class.equals(clazz)) {
return ApmInteger.class;
}
} else if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
Class rawType = (Class) parameterizedType.getRawType();
Class<?> rawType = (Class<?>) parameterizedType.getRawType();
if (List.class.equals(rawType)) {
return ApmList.class;
} else if (Map.class.equals(rawType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AnnotatedClassRegistry {

private static final Logger LOG = LoggerFactory.getLogger(AnnotatedClassRegistry.class);

private final BundleTracker tracker;
private final BundleTracker<?> tracker;

private final Map<Long, List<Class<?>>> classes = new ConcurrentHashMap<>();

Expand All @@ -62,7 +62,7 @@ public AnnotatedClassRegistry(final BundleContext bundleContext, final String bu
this.bundleHeader = bundleHeader;
this.annotationClass = annotationClass;

this.tracker = new BundleTracker(bundleContext, Bundle.ACTIVE, new BundleTrackerCustomizer<Bundle>() {
this.tracker = new BundleTracker<>(bundleContext, Bundle.ACTIVE, new BundleTrackerCustomizer<Bundle>() {

@Override
public Bundle addingBundle(Bundle bundle, BundleEvent bundleEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ protected void processScripts(List<Script> scripts, ResourceResolver resolver) t
if (!scripts.isEmpty()) {
String scriptPathsStr = scripts.stream()
.map(Script::getPath)
.collect(Collectors.joining("\n"));
logger.info("Launcher will try to run following scripts: {}\n{}", scripts.size(), scriptPathsStr);
.collect(Collectors.joining(", "));
logger.info("Launcher will try to run following scripts ({}): {}", scripts.size(), scriptPathsStr);
for (Script script : scripts) {
processScript(script, resolver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.cognifide.apm.core.Property;
import com.cognifide.apm.core.history.History;
import com.cognifide.apm.core.utils.Pagination;
import com.google.common.primitives.Ints;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.Servlet;
Expand Down Expand Up @@ -64,16 +63,16 @@ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse r

private Pagination createPagination(SlingHttpServletRequest request) {
String[] selectors = request.getRequestPathInfo().getSelectors();
if (selectors == null || selectors.length < 2) {
if (selectors.length < 2) {
return new Pagination(0, DEFAULT_LIMIT + 1);
} else {
Integer offset = Ints.tryParse(selectors[0]);
Integer limit = Ints.tryParse(selectors[1]);
int offset = Integer.parseInt(selectors[0]);
int limit = Integer.parseInt(selectors[1]);
return new Pagination(offset, limit + 1);
}
}

private class ResourceTypeWrapper extends ResourceWrapper {
private static class ResourceTypeWrapper extends ResourceWrapper {

ResourceTypeWrapper(Resource resource) {
super(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
*/
package com.cognifide.apm.core.ui.datasources;

import static com.cognifide.apm.core.ui.models.ScriptsRowModel.SCRIPTS_ROW_RESOURCE_TYPE;

import com.adobe.granite.ui.components.ds.DataSource;
import com.adobe.granite.ui.components.ds.SimpleDataSource;
import com.cognifide.apm.core.Property;
Expand Down Expand Up @@ -68,15 +66,15 @@ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse r
request.setAttribute(DataSource.class.getName(), dataSource);
}

private class ResourceTypeWrapper extends ResourceWrapper {
private static class ResourceTypeWrapper extends ResourceWrapper {

ResourceTypeWrapper(Resource resource) {
super(resource);
}

@Override
public String getResourceType() {
return SCRIPTS_ROW_RESOURCE_TYPE;
return ScriptsRowModel.SCRIPTS_ROW_RESOURCE_TYPE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ private ResourceMixinUtil() {
// empty constructor
}

public static void addMixin(ModifiableValueMap vm, String mixin) {
Set<String> mixins = new HashSet<>(Arrays.asList(vm.get(JcrConstants.JCR_MIXINTYPES, new String[0])));
public static void addMixin(ModifiableValueMap valueMap, String mixin) {
Set<String> mixins = new HashSet<>(Arrays.asList(valueMap.get(JcrConstants.JCR_MIXINTYPES, new String[]{})));
mixins.add(mixin);
vm.put(JcrConstants.JCR_MIXINTYPES, mixins.toArray(new String[]{}));
valueMap.put(JcrConstants.JCR_MIXINTYPES, mixins.toArray(new String[]{}));
}

}

0 comments on commit 2016ca9

Please sign in to comment.