Skip to content

Commit

Permalink
Fixed Sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Feb 4, 2024
1 parent 7980377 commit 452832e
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ public boolean equals(final Object obj) {
if (!amount.equals(other.amount)) {
return false;
}
if (!currency.getCurrencyCode().equals(other.currency.getCurrencyCode())) {
return false;
}
return true;
return currency.getCurrencyCode().equals(other.currency.getCurrencyCode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
if (value == null) {
return true;
}
if (value.length() == 0) {
if (value.isEmpty()) {
return false;
}
try {
Expand Down
15 changes: 3 additions & 12 deletions core/src/main/java/org/fuin/objects4j/core/DayOfTheWeek.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,8 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
DayOfTheWeek other = (DayOfTheWeek) obj;
if (id != other.id) {
return false;
}
return true;
final DayOfTheWeek other = (DayOfTheWeek) obj;
return id == other.id;
}

/**
Expand All @@ -208,13 +205,7 @@ public final int length() {

@Override
public int compareTo(final DayOfTheWeek other) {
if (id > other.id) {
return 1;
}
if (id < other.id) {
return -1;
}
return 0;
return Integer.compare(id, other.id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid string else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return DayOfTheWeek.isValid(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,7 @@ public final boolean equals(final Object obj) {
} else if (!range.equals(other.range)) {
return false;
}
if (type != other.type) {
return false;
}
return true;
return type == other.type;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid string representation else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return DayOpeningHours.isValid(value);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/fuin/objects4j/core/Hour.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public Hour(@NotNull @HourStr final String hour) {
super();
Contract.requireArgNotEmpty("hour", hour);
requireArgValid("hour", hour);
this.hourValue = Integer.valueOf(hour.substring(0, 2));
this.minuteValue = Integer.valueOf(hour.substring(3));
this.hourValue = Integer.parseInt(hour.substring(0, 2));
this.minuteValue = Integer.parseInt(hour.substring(3));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid string representation else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return HourRange.isValid(value);
}

Expand Down
17 changes: 7 additions & 10 deletions core/src/main/java/org/fuin/objects4j/core/HourRanges.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public final List<HourRanges> normalize() {
}
}
final List<HourRanges> list = new ArrayList<>();
list.add(new HourRanges(today.toArray(new HourRange[today.size()])));
if (tommorrow.size() > 0) {
list.add(new HourRanges(tommorrow.toArray(new HourRange[tommorrow.size()])));
list.add(new HourRanges(today.toArray(new HourRange[0])));
if (!tommorrow.isEmpty()) {
list.add(new HourRanges(tommorrow.toArray(new HourRange[0])));
}
return list;
}
Expand Down Expand Up @@ -379,7 +379,7 @@ public final String toString() {
private static String asStr(final List<HourRange> ranges) {
final StringBuilder sb = new StringBuilder();
for (final HourRange range : ranges) {
if (sb.length() > 0) {
if (!sb.isEmpty()) {
sb.append("+");
}
sb.append(range.toString());
Expand Down Expand Up @@ -478,7 +478,7 @@ private static HourRanges valueOf(@Nullable final BitSet minutes, final int max)
ranges.add(createHourRange(startHour, startMinute, minutes.length()));
}

return new HourRanges(ranges.toArray(new HourRange[ranges.size()]));
return new HourRanges(ranges.toArray(new HourRange[0]));

}

Expand Down Expand Up @@ -518,7 +518,7 @@ public static void requireArgValid(@NotNull final String name, @NotNull final St
/**
* Types of changes.
*/
public static enum ChangeType {
public enum ChangeType {

/** An hour range was added. */
ADDED,
Expand Down Expand Up @@ -599,10 +599,7 @@ public final boolean equals(final Object obj) {
} else if (!range.equals(other.range)) {
return false;
}
if (type != other.type) {
return false;
}
return true;
return type == other.type;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid string representation else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return HourRanges.isValid(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid Hourd else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return Hour.isValid(value);
}

Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/fuin/objects4j/core/KeyValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ public static String replace(final String message, final KeyValue... keyValue) {
}
final Map<String, String> map = new HashMap<String, String>();
for (final KeyValue kv : keyValue) {
if (kv.getValue() instanceof Collection) {
if (kv.getValue() instanceof Collection<?> coll) {
final StringBuilder sb = new StringBuilder();
final Collection<?> coll = (Collection<?>) kv.getValue();
int count = 0;
for (final Object entry : coll) {
if (count > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public MultiDayOfTheWeek(@NotNull @MultiDayOfTheWeekStr final String multipleDay
if (p > -1) {
final DayOfTheWeek from = DayOfTheWeek.valueOf(part.substring(0, p));
final DayOfTheWeek to = DayOfTheWeek.valueOf(part.substring(p + 1));
for (final DayOfTheWeek dow : DayOfTheWeek.getPart(from, to)) {
this.multipleDayOfTheWeek.add(dow);
}
this.multipleDayOfTheWeek.addAll(DayOfTheWeek.getPart(from, to));
} else {
this.multipleDayOfTheWeek.add(DayOfTheWeek.valueOf(part));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid string representation else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return MultiDayOfTheWeek.isValid(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ private static String toHex(final byte[] hash) {
final int l = hash.length;
final char[] out = new char[l << 1];
int j = 0;
for (int i = 0; i < l; i++) {
out[j++] = DIGITS[(0xF0 & hash[i]) >>> 4];
out[j++] = DIGITS[0x0F & hash[i]];
for (byte b : hash) {
out[j++] = DIGITS[(0xF0 & b) >>> 4];
out[j++] = DIGITS[0x0F & b];
}
return String.copyValueOf(out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's an allowed password else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
if (value == null) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class PropertiesContainValidator implements ConstraintValidator<Pro

@Override
public final void initialize(final PropertiesContain constraintAnnotation) {
expectedKeys = new HashSet<String>();
expectedKeys = new HashSet<>();
expectedKeys.addAll(Arrays.asList(constraintAnnotation.value()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
if (value == null) {
return true;
}
return value.trim().length() > 0;
return !value.trim().isEmpty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid UUIDd else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
if (value == null) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public WeeklyOpeningHours normalize() {

Collections.sort(days);

return new WeeklyOpeningHours(days.toArray(new DayOpeningHours[days.size()]));
return new WeeklyOpeningHours(days.toArray(new DayOpeningHours[0]));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final boolean isValid(final String value, final ConstraintValidatorContex
*
* @return Returns {@literal true} if it's a valid string representation else {@literal false} is returned.
*/
public static final boolean isValid(final String value) {
public static boolean isValid(final String value) {
return WeeklyOpeningHours.isValid(value);
}

Expand Down

0 comments on commit 452832e

Please sign in to comment.