Skip to content

Commit

Permalink
Merge pull request #556 from eclipse/active-pmd
Browse files Browse the repository at this point in the history
Active PMD at Eclipse JNoSQL
  • Loading branch information
otaviojava authored Sep 24, 2024
2 parents 598ae43 + 61943df commit e86469c
Show file tree
Hide file tree
Showing 47 changed files with 299 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public String getNameField() {
*/
public static Condition parse(String condition) {
Objects.requireNonNull(condition, "condition is required");
return Arrays.stream(Condition.values())
return Arrays.stream(values())
.filter(c -> c.getNameField()
.equals(condition)).findFirst()
.orElseThrow(() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected TypeReference() {
*
* @return the type
*/
@Override
public Type get() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public final class ValueWriterDecorator<T, S> implements ValueWriter<T, S> {

private static final ValueWriter INSTANCE = new ValueWriterDecorator();
private static final ValueWriter INSTANCE = new ValueWriterDecorator<>();

private final List<ValueWriter> writers = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

/**
* Class to reads and converts to {@link Enum}
Expand All @@ -35,6 +36,7 @@ public boolean test(Class<?> type) {
return Enum.class.isAssignableFrom(type);
}

@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public <T> T read(Class<T> type, Object value) {

Expand All @@ -57,10 +59,10 @@ public <T> T read(Class<T> type, Object value) {
.orElseThrow(() -> new IllegalArgumentException("There isn't name in enum to value: " + name));
}

@SuppressWarnings({"unchecked", "rawtypes"})
private <T> List<Enum> getEnumList(Class<Enum> type) {
EnumSet enumSet = EnumSet.allOf(type);
Set<Enum> enumSet = EnumSet.allOf(type);
return new ArrayList<>(enumSet);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public boolean test(TypeSupplier<?> typeReference) {
Type collectionType = parameterizedType.getRawType();
Type elementType = parameterizedType.getActualTypeArguments()[0];

boolean isNavigableSet = (NavigableSet.class.equals(collectionType)
boolean isNavigableSet = NavigableSet.class.equals(collectionType)
||
SortedSet.class.equals(collectionType));
SortedSet.class.equals(collectionType);
boolean isElementCompatible = elementType instanceof Class
&& Comparable.class.isAssignableFrom((Class<?>) elementType);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.communication.util;

public final class StringUtils {

private StringUtils() {
}

public static boolean isBlank(final CharSequence cs) {
final int strLen = length(cs);
if (strLen == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}


private static int length(final CharSequence cs) {
return cs == null ? 0 : cs.length();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Apache License v2.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
*
* You may elect to redistribute this code under either of these licenses.
*
* Contributors:
*
* Otavio Santana
*/
package org.eclipse.jnosql.communication.util;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;


class StringUtilsTest {

@Test
void shouldIsBlank() {
Assertions.assertThat(StringUtils.isBlank(null)).isTrue();
Assertions.assertThat(StringUtils.isBlank("")).isTrue();
Assertions.assertThat(StringUtils.isBlank("bob")).isFalse();
Assertions.assertThat(StringUtils.isBlank(" bob ")).isFalse();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public interface BucketManager extends AutoCloseable {
/**
* closes a resource
*/
@Override
void close();

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ public interface BucketManagerFactory extends Function<String, BucketManager>, A
/**
* closes a resource
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private static String processOrderBy(String query) {
String[] tokens = query.split(" ");
boolean afterOrderBy = false;

for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
for (int index = 0; index < tokens.length; index++) {
String token = tokens[index];

if (token.equals("OrderBy")) {
afterOrderBy = true;
Expand All @@ -115,13 +115,13 @@ private static String processOrderBy(String query) {
result.append(token).append(" ");
} else {
// Combine all tokens until "Asc" or "Desc"
while (i < tokens.length && !tokens[i].equals("Asc") && !tokens[i].equals("Desc")) {
result.append(tokens[i]);
i++;
while (index < tokens.length && !tokens[index].equals("Asc") && !tokens[index].equals("Desc")) {
result.append(tokens[index]);
index++;
}
// Add the final Asc or Desc if present
if (i < tokens.length) {
result.append(" ").append(tokens[i]).append(" ");
if (index < tokens.length) {
result.append(" ").append(tokens[index]).append(" ");
}
}
afterOrderBy = false; // Processed the relevant tokens after OrderBy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class CommunicationEntity {
* @throws NullPointerException if the specified list is {@code null}
*/
public void addAll(List<Element> elements) {
Objects.requireNonNull(elements, "The object column is required");
requireNonNull(elements, "The object column is required");
elements.forEach(this::add);
}

Expand All @@ -72,7 +72,7 @@ public void addAll(List<Element> elements) {
* @throws NullPointerException if the specified element is {@code null}
*/
public void add(Element element) {
Objects.requireNonNull(element, "Column is required");
requireNonNull(element, "Column is required");
this.elements.put(element.name(), element);
}

Expand Down Expand Up @@ -183,8 +183,8 @@ public Optional<Element> find(String columnName) {
* @throws NullPointerException if either the specified name or type is {@code null}
*/
public <T> Optional<T> find(String elementName, Class<T> type) {
Objects.requireNonNull(elementName, "elementName is required");
Objects.requireNonNull(type, "type is required");
requireNonNull(elementName, "elementName is required");
requireNonNull(type, "type is required");
return ofNullable(elements.get(elementName))
.map(c -> c.get(type));
}
Expand All @@ -200,8 +200,8 @@ public <T> Optional<T> find(String elementName, Class<T> type) {
* @throws NullPointerException if either the specified name or type supplier is {@code null}
*/
public <T> Optional<T> find(String elementName, TypeSupplier<T> type) {
Objects.requireNonNull(elementName, "elementName is required");
Objects.requireNonNull(type, "type is required");
requireNonNull(elementName, "elementName is required");
requireNonNull(type, "type is required");
return ofNullable(elements.get(elementName))
.map(v -> v.get(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public CriteriaCondition and(CriteriaCondition condition) {
Element newElement = getConditions(condition, Condition.AND);
return new CriteriaCondition(newElement, Condition.AND);
}
return CriteriaCondition.and(this, condition);
return and(this, condition);
}

/**
Expand Down Expand Up @@ -115,11 +115,11 @@ public CriteriaCondition or(CriteriaCondition condition) {
Element newElement = getConditions(condition, Condition.OR);
return new CriteriaCondition(newElement, Condition.OR);
}
return CriteriaCondition.or(this, condition);
return or(this, condition);
}

private Element getConditions(CriteriaCondition criteriaCondition, Condition condition) {
List<CriteriaCondition> conditions = new ArrayList<>(element.get(new TypeReference<List<CriteriaCondition>>() {
var conditions = new ArrayList<>(element.get(new TypeReference<List<CriteriaCondition>>() {
}));
conditions.add(criteriaCondition);
return Element.of(condition.getNameField(), conditions);
Expand Down Expand Up @@ -429,7 +429,7 @@ public static CriteriaCondition not(CriteriaCondition condition) {
public static CriteriaCondition and(CriteriaCondition... conditions) {
Objects.requireNonNull(conditions, "Condition is required");
Element element = Element.of(Condition.AND.getNameField(), Arrays.asList(conditions));
return CriteriaCondition.of(element, Condition.AND);
return of(element, Condition.AND);
}

/**
Expand All @@ -451,7 +451,7 @@ public static CriteriaCondition and(CriteriaCondition... conditions) {
public static CriteriaCondition or(CriteriaCondition... conditions) {
Objects.requireNonNull(conditions, "Condition is required");
Element element = Element.of(Condition.OR.getNameField(), Arrays.asList(conditions));
return CriteriaCondition.of(element, Condition.OR);
return of(element, Condition.OR);
}

private static void checkInClause(Value value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,6 @@ default CursoredPage<CommunicationEntity> selectCursor(SelectQuery query, PageRe
/**
* Closes the database manager and releases any associated resources.
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public interface DatabaseManagerFactory extends Function<String, DatabaseManager
*
* <p>Note: Some databases may not perform any specific actions upon closing.</p>
*/
@Override
void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DefaultDeleteQueryBuilder implements DeleteQueryBuilder {

@Override
public DeleteQueryBuilder delete(String column) {
Objects.requireNonNull(column, "column is required");
requireNonNull(column, "column is required");
this.columns.add(column);
return this;
}
Expand All @@ -49,14 +49,14 @@ public DeleteQueryBuilder delete(String... columns) {

@Override
public DeleteQueryBuilder from(String entity) {
Objects.requireNonNull(entity, "entity is required");
requireNonNull(entity, "entity is required");
this.entity = entity;
return this;
}

@Override
public DeleteQueryBuilder where(CriteriaCondition condition) {
Objects.requireNonNull(condition, "condition is required");
requireNonNull(condition, "condition is required");
this.condition = condition;
return this;
}
Expand All @@ -71,7 +71,7 @@ public DeleteQuery build() {

@Override
public void delete(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
requireNonNull(manager, "manager is required");
manager.delete(build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DefaultFluentDeleteQueryBuilder extends BaseQueryBuilder implements Entity


DefaultFluentDeleteQueryBuilder(List<String> columns) {
super();
this.columns = columns;
}

Expand Down Expand Up @@ -134,4 +135,4 @@ public void delete(DatabaseManager manager) {
manager.delete(this.build());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DefaultFluentSelectQueryBuilderElements extends BaseQueryBuilder implement


DefaultFluentSelectQueryBuilderElements(List<String> columns) {
super();
this.columns = columns;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DefaultQueryBuilder implements SelectQuery.QueryBuilder {

@Override
public SelectQuery.QueryBuilder select(String column) {
Objects.requireNonNull(column, "column is required");
requireNonNull(column, "column is required");
this.columns.add(column);
return this;
}
Expand All @@ -54,7 +54,7 @@ public SelectQuery.QueryBuilder select(String... columns) {

@Override
public SelectQuery.QueryBuilder sort(Sort<?> sort) {
Objects.requireNonNull(sort, "sort is required");
requireNonNull(sort, "sort is required");
this.sorts.add(sort);
return this;
}
Expand All @@ -69,14 +69,14 @@ public SelectQuery.QueryBuilder sort(Sort<?>... sorts) {

@Override
public SelectQuery.QueryBuilder from(String entity) {
Objects.requireNonNull(entity, "entity is required");
requireNonNull(entity, "entity is required");
this.entity = entity;
return this;
}

@Override
public SelectQuery.QueryBuilder where(CriteriaCondition condition) {
Objects.requireNonNull(condition, "condition is required");
requireNonNull(condition, "condition is required");
this.condition = condition;
return this;
}
Expand Down Expand Up @@ -110,13 +110,13 @@ public SelectQuery build() {

@Override
public Stream<CommunicationEntity> getResult(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
requireNonNull(manager, "manager is required");
return manager.select(build());
}

@Override
public Optional<CommunicationEntity> getSingleResult(DatabaseManager manager) {
Objects.requireNonNull(manager, "manager is required");
requireNonNull(manager, "manager is required");
return manager.singleResult(build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static List<Element> of(Map<String, ?> values) {
private static Object getValue(Object value) {

if (value instanceof Map) {
List list = Elements.of((Map.class.cast(value)));
List list = of(Map.class.cast(value));
if(list.size() == 1) {
return list.get(0);
}
Expand Down
Loading

0 comments on commit e86469c

Please sign in to comment.