Skip to content

Commit

Permalink
Resolved Idea warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev committed May 7, 2024
1 parent e4fe014 commit 92a5cf7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 38 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/github/underscore/Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public JsonStringBuilder append(final String string) {
}

public JsonStringBuilder fillSpaces() {
for (int index = 0; index < indent; index += 1) {
builder.append(identStep == Step.TABS ? '\t' : ' ');
}
builder.append(String.valueOf(identStep == Step.TABS ? '\t' : ' ').repeat(Math.max(0, indent)));
return this;
}

Expand Down Expand Up @@ -458,7 +456,7 @@ public static class JsonParser {
private int line;
private int lineOffset;
private int current;
private StringBuilder captureBuffer = new StringBuilder();
private final StringBuilder captureBuffer = new StringBuilder();
private int captureStart;
private final int maxDepth;

Expand Down
46 changes: 23 additions & 23 deletions src/main/java/com/github/underscore/U.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ public class U<T> extends Underscore<T> {
private static final int BUFFER_LENGTH_1024 = 1024;
private static final int RESPONSE_CODE_400 = 400;
private static final String ROOT = "root";
private static String upper = "[A-Z\\xc0-\\xd6\\xd8-\\xde\\u0400-\\u04FF]";
private static String lower = "[a-z\\xdf-\\xf6\\xf8-\\xff]+";
private static String selfClosing = "-self-closing";
private static String nilKey = "-nil";
private static java.util.regex.Pattern reWords =
private static final String UPPER = "[A-Z\\xc0-\\xd6\\xd8-\\xde\\u0400-\\u04FF]";
private static final String LOWER = "[a-z\\xdf-\\xf6\\xf8-\\xff]+";
private static final String SELF_CLOSING = "-self-closing";
private static final String NIL_KEY = "-nil";
private static final java.util.regex.Pattern RE_WORDS =
java.util.regex.Pattern.compile(
upper
UPPER
+ "+(?="
+ upper
+ lower
+ UPPER
+ LOWER
+ ")|"
+ upper
+ UPPER
+ "?"
+ lower
+ LOWER
+ "|"
+ upper
+ "+|[0-9]+");
+ UPPER
+ "+|\\d+");

static {
String[] deburredLetters =
Expand Down Expand Up @@ -1460,7 +1460,7 @@ public static String deburr(final String string) {
public static List<String> words(final String string) {
final String localString = baseToString(string);
final List<String> result = new ArrayList<>();
final java.util.regex.Matcher matcher = reWords.matcher(localString);
final java.util.regex.Matcher matcher = RE_WORDS.matcher(localString);
while (matcher.find()) {
result.add(matcher.group());
}
Expand Down Expand Up @@ -2885,7 +2885,7 @@ public static Map<String, Object> removeMinusesAndConvertNumbers(Map<String, Obj
} else {
newKey = entry.getKey();
}
if (!entry.getKey().equals(selfClosing)
if (!entry.getKey().equals(SELF_CLOSING)
&& !entry.getKey().equals("#omit-xml-declaration")) {
outMap.put(newKey, makeObject(entry.getValue()));
}
Expand Down Expand Up @@ -2963,7 +2963,7 @@ public static Map<String, Object> replaceSelfClosingWithEmpty(Map<String, Object
public static Object replaceSelfClosingWithValue(Map<String, Object> map, String value) {
Object outMap = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
if (selfClosing.equals(entry.getKey()) && "true".equals(entry.getValue())) {
if (SELF_CLOSING.equals(entry.getKey()) && "true".equals(entry.getValue())) {
if (map.size() == 1) {
outMap = value;
break;
Expand Down Expand Up @@ -3226,9 +3226,9 @@ public static Map<String, Object> replaceFirstLevel(Map<String, Object> map, int
}
if (level == 0 && Xml.XmlValue.getMapValue(outMap) instanceof Map) {
Map<String, Object> outMap2 = (Map<String, Object>) Xml.XmlValue.getMapValue(outMap);
if (selfClosing.equals(Xml.XmlValue.getMapKey(outMap2))
if (SELF_CLOSING.equals(Xml.XmlValue.getMapKey(outMap2))
&& "true".equals(Xml.XmlValue.getMapValue(outMap2))) {
outMap2.remove(selfClosing);
outMap2.remove(SELF_CLOSING);
}
return outMap2;
}
Expand Down Expand Up @@ -3257,11 +3257,11 @@ public static Map<String, Object> replaceNilWithNull(Map<String, Object> map) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
Object outValue = makeReplaceNilWithNull(entry.getValue());
if (outValue instanceof Map
&& (nilKey.equals(Xml.XmlValue.getMapKey(outValue))
&& (NIL_KEY.equals(Xml.XmlValue.getMapKey(outValue))
|| Xml.XmlValue.getMapKey(outValue).endsWith(":nil"))
&& "true".equals(Xml.XmlValue.getMapValue(outValue))
&& ((Map) outValue).containsKey(selfClosing)
&& "true".equals(((Map) outValue).get(selfClosing))) {
&& ((Map) outValue).containsKey(SELF_CLOSING)
&& "true".equals(((Map) outValue).get(SELF_CLOSING))) {
outValue = null;
}
outMap.put(entry.getKey(), outValue);
Expand Down Expand Up @@ -3405,7 +3405,7 @@ public Builder addNull(final String key) {

@SuppressWarnings("unchecked")
public Map<String, Object> build() {
return (Map<String, Object>) ((LinkedHashMap) data).clone();
return (Map<String, Object>) ((LinkedHashMap<?, ?>) data).clone();
}

public String toXml() {
Expand Down Expand Up @@ -3511,13 +3511,13 @@ public ArrayBuilder add(final Builder builder) {

@SuppressWarnings("unchecked")
public ArrayBuilder merge(final List<Object> list) {
U.merge(data, (List<Object>) ((ArrayList) list).clone());
U.merge(data, (List<Object>) ((ArrayList<?>) list).clone());
return this;
}

@SuppressWarnings("unchecked")
public List<Object> build() {
return (List<Object>) ((ArrayList) data).clone();
return (List<Object>) ((ArrayList<?>) data).clone();
}

public String toXml() {
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/com/github/underscore/Underscore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ public static <E> List<List<E>> partition(final Iterable<E> iterable, final Pred

@SuppressWarnings("unchecked")
public static <E> List<E>[] partition(final E[] iterable, final Predicate<E> pred) {
return partition(Arrays.asList(iterable), pred).toArray(new ArrayList[0]);
return partition(Arrays.asList(iterable), pred).toArray(new List[0]);
}

public T singleOrNull() {
Expand Down Expand Up @@ -1482,7 +1482,7 @@ public static <E> List<E> compact(final List<E> list) {
!String.valueOf(arg).equals("null")
&& !String.valueOf(arg).equals("0")
&& !String.valueOf(arg).equals("false")
&& !String.valueOf(arg).equals(""));
&& !String.valueOf(arg).isEmpty());
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -1605,8 +1605,7 @@ public static <K, E> E[] distinctBy(final E[] array, final Function<E, K> func)
*/
@SuppressWarnings("unchecked")
public static <E> List<E> union(final List<E> list, final List<E>... lists) {
final Set<E> union = new LinkedHashSet<>();
union.addAll(list);
final Set<E> union = new LinkedHashSet<>(list);
for (List<E> localList : lists) {
union.addAll(localList);
}
Expand Down Expand Up @@ -2355,8 +2354,7 @@ public static List<String> methods(final Object object) {
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> extend(final Map<K, V> destination, final Map<K, V>... sources) {
final Map<K, V> result = new LinkedHashMap<>();
result.putAll(destination);
final Map<K, V> result = new LinkedHashMap<>(destination);
for (final Map<K, V> source : sources) {
result.putAll(source);
}
Expand Down Expand Up @@ -2735,7 +2733,7 @@ public static <K, V> Template<Map<K, V>> template(final String template) {

public static String format(final String template, final Object... params) {
final java.util.regex.Matcher matcher = FORMAT_PATTERN.matcher(template);
final StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
int index = 0;
while (matcher.find()) {
if (matcher.group(1).isEmpty()) {
Expand Down Expand Up @@ -3526,7 +3524,7 @@ public static <T> List<List<T>> splitAt(final Iterable<T> iterable, final int po
if (position < 0) {
index = 0;
} else {
index = position > size ? size : position;
index = Math.min(position, size);
}
result.add(newArrayList(iterable).subList(0, index));
result.add(newArrayList(iterable).subList(index, size));
Expand Down Expand Up @@ -3855,7 +3853,7 @@ public static void main(String... args) {
System.out.println(message);
}

public static interface Function3<F1, F2, F3, T> {
public interface Function3<F1, F2, F3, T> {
T apply(F1 arg1, F2 arg2, F3 arg3);
}

Expand All @@ -3870,11 +3868,11 @@ public T apply(final F key) {
}
}

public static interface PredicateIndexed<T> {
public interface PredicateIndexed<T> {
boolean test(int index, T arg);
}

public static interface Template<T> extends Function<T, String> {
public interface Template<T> extends Function<T, String> {
List<String> check(T arg);
}
}

0 comments on commit 92a5cf7

Please sign in to comment.