From eac22c3f508bdf61af857972cb2b90f5627b8f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 9 Aug 2022 22:30:04 +0200 Subject: [PATCH] fixes for deepsource --- .../content/json/jackson/JsonNodeReader.java | 10 ++--- .../content/json/pointer/JsonPointer.java | 20 +++++++++ .../content/json/pointer/TreePointer.java | 11 +++-- .../java/org/xbib/content/language/Range.java | 4 +- .../org/xbib/content/language/SubtagSet.java | 11 ++--- .../internal/DefaultAnonymousResource.java | 11 +++++ .../content/rdf/internal/DefaultLiteral.java | 1 - .../io/ntriple/NTripleContentGenerator.java | 26 ------------ .../rdf/io/ntriple/NTriplesParser.java | 2 - .../io/xml/AbstractXmlResourceHandler.java | 1 + .../content/rdf/util/LinkedHashMultiMap.java | 8 ++-- .../content/resource/IRINamespaceContext.java | 2 +- .../text/DelegatingCodepointIterator.java | 12 +++++- .../main/java/org/xbib/settings/Settings.java | 10 ++--- .../settings/content/ContentSettings.java | 23 +++++------ .../datastructures/DatastructureSettings.java | 41 +++++++++++-------- 16 files changed, 102 insertions(+), 91 deletions(-) diff --git a/content-json/src/main/java/org/xbib/content/json/jackson/JsonNodeReader.java b/content-json/src/main/java/org/xbib/content/json/jackson/JsonNodeReader.java index ccbba12..1cc9b3d 100644 --- a/content-json/src/main/java/org/xbib/content/json/jackson/JsonNodeReader.java +++ b/content-json/src/main/java/org/xbib/content/json/jackson/JsonNodeReader.java @@ -44,12 +44,12 @@ public final class JsonNodeReader { } private static JsonNode readNode(final MappingIterator iterator) throws IOException { - final Object source = iterator.getParser().getInputSource(); - final JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(null, source); + Object source = iterator.getParser().getInputSource(); + JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(null, source); if (!iterator.hasNextValue()) { throw builder.build(); } - final JsonNode ret = iterator.nextValue(); + JsonNode ret = iterator.nextValue(); builder.setLocation(iterator.getCurrentLocation()); try { if (iterator.hasNextValue()) { @@ -89,7 +89,7 @@ public final class JsonNodeReader { } } - private static final class JsonParseExceptionBuilder { + private static class JsonParseExceptionBuilder { private final JsonParser jsonParser; @@ -100,7 +100,7 @@ public final class JsonNodeReader { location = new JsonLocation(ContentReference.construct(false, source), 0L, 1, 1); } - private JsonParseExceptionBuilder setLocation(final JsonLocation location) { + JsonParseExceptionBuilder setLocation(final JsonLocation location) { this.location = location; return this; } diff --git a/content-json/src/main/java/org/xbib/content/json/pointer/JsonPointer.java b/content-json/src/main/java/org/xbib/content/json/pointer/JsonPointer.java index 03d0ac8..d43e68d 100644 --- a/content-json/src/main/java/org/xbib/content/json/pointer/JsonPointer.java +++ b/content-json/src/main/java/org/xbib/content/json/pointer/JsonPointer.java @@ -139,4 +139,24 @@ public final class JsonPointer extends TreePointer { return size <= 1 ? EMPTY : new JsonPointer(tokenResolvers.subList(0, size - 1)); } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (this == obj) { + return true; + } + if (getClass() != obj.getClass()) { + return false; + } + TreePointer other = (TreePointer) obj; + return tokenResolvers.equals(other.tokenResolvers); + } + + @Override + public int hashCode() { + return tokenResolvers.hashCode(); + } } diff --git a/content-json/src/main/java/org/xbib/content/json/pointer/TreePointer.java b/content-json/src/main/java/org/xbib/content/json/pointer/TreePointer.java index 24747a3..324d75c 100644 --- a/content-json/src/main/java/org/xbib/content/json/pointer/TreePointer.java +++ b/content-json/src/main/java/org/xbib/content/json/pointer/TreePointer.java @@ -24,8 +24,7 @@ import java.util.List; * * @param the type of the tree */ -public abstract class TreePointer - implements Iterable> { +public abstract class TreePointer implements Iterable> { /** * The reference token separator. */ @@ -150,12 +149,12 @@ public abstract class TreePointer } @Override - public final int hashCode() { + public int hashCode() { return tokenResolvers.hashCode(); } @Override - public final boolean equals(final Object obj) { + public boolean equals(final Object obj) { if (obj == null) { return false; } @@ -165,12 +164,12 @@ public abstract class TreePointer if (getClass() != obj.getClass()) { return false; } - final TreePointer other = (TreePointer) obj; + TreePointer other = (TreePointer) obj; return tokenResolvers.equals(other.tokenResolvers); } @Override - public final String toString() { + public String toString() { final StringBuilder sb = new StringBuilder(); for (final TokenResolver tokenResolver : tokenResolvers) { sb.append('/').append(tokenResolver); diff --git a/content-language/src/main/java/org/xbib/content/language/Range.java b/content-language/src/main/java/org/xbib/content/language/Range.java index 3b6a3d0..966d93f 100644 --- a/content-language/src/main/java/org/xbib/content/language/Range.java +++ b/content-language/src/main/java/org/xbib/content/language/Range.java @@ -445,7 +445,7 @@ public class Range extends SubtagSet { langs.add(l); } } - return langs.toArray(new Lang[langs.size()]); + return langs.toArray(new Lang[0]); } /** @@ -460,7 +460,7 @@ public class Range extends SubtagSet { langs.add(l); } } - return langs.toArray(new String[langs.size()]); + return langs.toArray(new String[0]); } @Override diff --git a/content-language/src/main/java/org/xbib/content/language/SubtagSet.java b/content-language/src/main/java/org/xbib/content/language/SubtagSet.java index ca52079..b9b9451 100644 --- a/content-language/src/main/java/org/xbib/content/language/SubtagSet.java +++ b/content-language/src/main/java/org/xbib/content/language/SubtagSet.java @@ -6,10 +6,7 @@ import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; -/** - * - */ -abstract class SubtagSet implements Cloneable, Iterable, Comparable { +abstract class SubtagSet implements Iterable, Comparable { protected final Subtag primary; @@ -104,7 +101,7 @@ abstract class SubtagSet implements Cloneable, Iterable, Comparable asList() { @@ -123,10 +120,10 @@ abstract class SubtagSet implements Cloneable, Iterable, Comparable { case "xsd:long": return Long.parseLong(s); case "xsd:int": - return Integer.parseInt(s); case "xsd:gYear": return Integer.parseInt(s); case "xsd:boolean": diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentGenerator.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentGenerator.java index b26240b..f1355a2 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentGenerator.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTripleContentGenerator.java @@ -175,30 +175,4 @@ public class NTripleContentGenerator } return sb.toString(); } - - - /** - * Translate a literal according to given sort language (e.g. mechanical word order, sort area). - * see http://www.w3.org/International/articles/language-tags/ - * - * @param literal the literal - * @return the process literal - */ - private Literal translateLanguage(Literal literal, String langTag) { - if (literal == null) { - return null; - } - // we assume we have only one sort language. Search for '@' symbol. - String value = literal.object().toString(); - // ignore if on position 0 - int pos = value.indexOf(" @"); - if (pos == 0) { - literal.object(value.substring(1)); - } else if (pos > 0) { - literal.object('\u0098' + value.substring(0, pos + 1) + '\u009c' + value.substring(pos + 2)) - .lang(langTag); - } - return literal; - } - } diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java index 1ef35f0..4c35761 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/ntriple/NTriplesParser.java @@ -22,8 +22,6 @@ public final class NTriplesParser implements CharSink { private static final char SENTENCE_END = '.'; private static final BitSet WHITESPACE = new BitSet() { - private static final long serialVersionUID = 2369480497714252078L; - { set('\t'); set(' '); diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/AbstractXmlResourceHandler.java b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/AbstractXmlResourceHandler.java index 90396f6..0326b0b 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/AbstractXmlResourceHandler.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/io/xml/AbstractXmlResourceHandler.java @@ -53,6 +53,7 @@ public abstract class AbstractXmlResourceHandler

@Override public void addToPredicate(QName parent, String content) { + // do nothing } @Override diff --git a/content-rdf/src/main/java/org/xbib/content/rdf/util/LinkedHashMultiMap.java b/content-rdf/src/main/java/org/xbib/content/rdf/util/LinkedHashMultiMap.java index 4b6e413..6d4e19b 100644 --- a/content-rdf/src/main/java/org/xbib/content/rdf/util/LinkedHashMultiMap.java +++ b/content-rdf/src/main/java/org/xbib/content/rdf/util/LinkedHashMultiMap.java @@ -20,11 +20,11 @@ public class LinkedHashMultiMap implements MultiMap { this.map = new LinkedHashMap<>(); } - public LinkedHashMultiMap(MultiMap map) { - Objects.requireNonNull(map); + public LinkedHashMultiMap(MultiMap multiMap) { + Objects.requireNonNull(multiMap); this.map = new LinkedHashMap<>(); - for (K k : map.keySet()) { - putAll(k, map.get(k)); + for (K k : multiMap.keySet()) { + putAll(k, multiMap.get(k)); } } diff --git a/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java b/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java index ed1f0a0..b033547 100644 --- a/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java +++ b/content-resource/src/main/java/org/xbib/content/resource/IRINamespaceContext.java @@ -30,7 +30,7 @@ public final class IRINamespaceContext implements NamespaceContext { private final SortedMap> prefixes; - protected final Object lock; + private final Object lock; private List sortedNamespacesByPrefixLength; diff --git a/content-resource/src/main/java/org/xbib/content/resource/text/DelegatingCodepointIterator.java b/content-resource/src/main/java/org/xbib/content/resource/text/DelegatingCodepointIterator.java index c422d50..65bd4e6 100644 --- a/content-resource/src/main/java/org/xbib/content/resource/text/DelegatingCodepointIterator.java +++ b/content-resource/src/main/java/org/xbib/content/resource/text/DelegatingCodepointIterator.java @@ -1,11 +1,15 @@ package org.xbib.content.resource.text; +import java.util.NoSuchElementException; + /** * Base implementation of a CodepointIterator that filters the output of another CodpointIterator. */ public abstract class DelegatingCodepointIterator extends CodepointIterator { - private CodepointIterator internal; + private final CodepointIterator internal; + + private boolean hasNext; protected DelegatingCodepointIterator(CodepointIterator internal) { this.internal = internal; @@ -23,7 +27,8 @@ public abstract class DelegatingCodepointIterator extends CodepointIterator { @Override public boolean hasNext() { - return internal.hasNext(); + hasNext = internal.hasNext(); + return hasNext; } @Override @@ -43,6 +48,9 @@ public abstract class DelegatingCodepointIterator extends CodepointIterator { @Override public Codepoint next() { + if (!hasNext) { + throw new NoSuchElementException(); + } return internal.next(); } diff --git a/settings-api/src/main/java/org/xbib/settings/Settings.java b/settings-api/src/main/java/org/xbib/settings/Settings.java index a9af55f..142c809 100644 --- a/settings-api/src/main/java/org/xbib/settings/Settings.java +++ b/settings-api/src/main/java/org/xbib/settings/Settings.java @@ -37,15 +37,15 @@ public interface Settings extends AutoCloseable { String get(String setting, String defaultValue); - Float getAsFloat(String setting, Float defaultValue); + float getAsFloat(String setting, float defaultValue); - Double getAsDouble(String setting, Double defaultValue); + double getAsDouble(String setting, double defaultValue); - Integer getAsInt(String setting, Integer defaultValue); + int getAsInt(String setting, int defaultValue); - Long getAsLong(String setting, Long defaultValue); + long getAsLong(String setting, long defaultValue); - Boolean getAsBoolean(String setting, Boolean defaultValue); + boolean getAsBoolean(String setting, boolean defaultValue); TimeValue getAsTime(String setting, TimeValue defaultValue); diff --git a/settings-content/src/main/java/org/xbib/settings/content/ContentSettings.java b/settings-content/src/main/java/org/xbib/settings/content/ContentSettings.java index d945f24..2ad614c 100644 --- a/settings-content/src/main/java/org/xbib/settings/content/ContentSettings.java +++ b/settings-content/src/main/java/org/xbib/settings/content/ContentSettings.java @@ -193,7 +193,7 @@ public class ContentSettings implements Settings, AutoCloseable { } @Override - public Float getAsFloat(String setting, Float defaultValue) { + public float getAsFloat(String setting, float defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; @@ -206,7 +206,7 @@ public class ContentSettings implements Settings, AutoCloseable { } @Override - public Double getAsDouble(String setting, Double defaultValue) { + public double getAsDouble(String setting, double defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; @@ -219,7 +219,7 @@ public class ContentSettings implements Settings, AutoCloseable { } @Override - public Integer getAsInt(String setting, Integer defaultValue) { + public int getAsInt(String setting, int defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; @@ -232,7 +232,7 @@ public class ContentSettings implements Settings, AutoCloseable { } @Override - public Long getAsLong(String setting, Long defaultValue) { + public long getAsLong(String setting, long defaultValue) { String sValue = get(setting); if (sValue == null) { return defaultValue; @@ -245,7 +245,7 @@ public class ContentSettings implements Settings, AutoCloseable { } @Override - public Boolean getAsBoolean(String setting, Boolean defaultValue) { + public boolean getAsBoolean(String setting, boolean defaultValue) { String value = get(setting); if (value == null) { return defaultValue; @@ -290,7 +290,7 @@ public class ContentSettings implements Settings, AutoCloseable { if (result.isEmpty()) { return defaultArray; } - return result.toArray(new String[result.size()]); + return result.toArray(new String[0]); } @Override @@ -301,20 +301,19 @@ public class ContentSettings implements Settings, AutoCloseable { } // we don't really care that it might happen twice TinyMap.Builder> hashMap = TinyMap.builder(); - for (Object o : this.map.keySet()) { - String setting = (String) o; - if (setting.startsWith(settingPrefix)) { - String nameValue = setting.substring(settingPrefix.length()); + for (String o : this.map.keySet()) { + if (o.startsWith(settingPrefix)) { + String nameValue = o.substring(settingPrefix.length()); int dotIndex = nameValue.indexOf('.'); if (dotIndex == -1) { throw new SettingsException("Failed to get setting group for [" + settingPrefix - + "] setting prefix and setting [" + setting + "] because of a missing '.'"); + + "] setting prefix and setting [" + o + "] because of a missing '.'"); } String name = nameValue.substring(0, dotIndex); String value = nameValue.substring(dotIndex + 1); Map groupSettings = hashMap.computeIfAbsent(name, k -> TinyMap.builder()); - groupSettings.put(value, get(setting)); + groupSettings.put(value, get(o)); } } TinyMap.Builder retVal = TinyMap.builder(); diff --git a/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java b/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java index a890f36..7648c52 100644 --- a/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java +++ b/settings-datastructures/src/main/java/org/xbib/settings/datastructures/DatastructureSettings.java @@ -39,11 +39,11 @@ public class DatastructureSettings implements Settings { } } - public static String[] splitStringByCommaToArray(final String s) { + public static String[] splitStringByCommaToArray(String s) { return splitStringToArray(s, ','); } - public static String[] splitStringToArray(final String s, final char c) { + public static String[] splitStringToArray(String s, char c) { if (s.length() == 0) { return EMPTY_ARRAY; } @@ -88,12 +88,14 @@ public class DatastructureSettings implements Settings { @Override public Map getAsStructuredMap() { TinyMap.Builder stringObjectMap = TinyMap.builder(); - for (String key : map.keySet()) { - String value = map.get(key); + for (Map.Entry entry : map.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); processSetting(stringObjectMap, "", key, value); } - for (String key : stringObjectMap.keySet()) { - Object object = stringObjectMap.get(key); + for (Map.Entry entry : stringObjectMap.entrySet()) { + String key = entry.getKey(); + Object object = entry.getValue(); if (object instanceof Map) { @SuppressWarnings("unchecked") Map valMap = (Map) object; @@ -106,8 +108,9 @@ public class DatastructureSettings implements Settings { @Override public Settings getByPrefix(String prefix) { DatastructureSettingsBuilder builder = new DatastructureSettingsBuilder(); - for (String key : map.keySet()) { - String value = map.get(key); + for (Map.Entry entry : map.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); if (key.startsWith(prefix)) { if (key.length() < prefix.length()) { continue; @@ -148,7 +151,7 @@ public class DatastructureSettings implements Settings { } @Override - public Float getAsFloat(String setting, Float defaultValue) { + public float getAsFloat(String setting, float defaultValue) { String s = get(setting); try { return s == null ? defaultValue : Float.parseFloat(s); @@ -158,7 +161,7 @@ public class DatastructureSettings implements Settings { } @Override - public Double getAsDouble(String setting, Double defaultValue) { + public double getAsDouble(String setting, double defaultValue) { String s = get(setting); try { return s == null ? defaultValue : Double.parseDouble(s); @@ -168,7 +171,7 @@ public class DatastructureSettings implements Settings { } @Override - public Integer getAsInt(String setting, Integer defaultValue) { + public int getAsInt(String setting, int defaultValue) { String s = get(setting); try { return s == null ? defaultValue : Integer.parseInt(s); @@ -178,7 +181,7 @@ public class DatastructureSettings implements Settings { } @Override - public Long getAsLong(String setting, Long defaultValue) { + public long getAsLong(String setting, long defaultValue) { String s = get(setting); try { return s == null ? defaultValue : Long.parseLong(s); @@ -188,7 +191,7 @@ public class DatastructureSettings implements Settings { } @Override - public Boolean getAsBoolean(String setting, Boolean defaultValue) { + public boolean getAsBoolean(String setting, boolean defaultValue) { String value = get(setting); if (value == null) { return defaultValue; @@ -283,8 +286,9 @@ public class DatastructureSettings implements Settings { @SuppressWarnings("unchecked") Map innerMap = (Map) map.get(prefix + setting); if (innerMap != null) { - for (String k : innerMap.keySet()) { - Object v = innerMap.get(k); + for (Map.Entry e : innerMap.entrySet()) { + String k = e.getKey(); + Object v = e.getValue(); map.put(prefix + setting + "." + k, v); } } @@ -316,8 +320,9 @@ public class DatastructureSettings implements Settings { } boolean isArray = true; int maxIndex = -1; - for (String key : map.keySet()) { - Object value = map.get(key); + for (Map.Entry entry : map.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); if (isArray) { try { int index = Integer.parseInt(key); @@ -356,6 +361,6 @@ public class DatastructureSettings implements Settings { @Override public void close() throws IOException { + // do nothing } - }