fixes for deepsource

This commit is contained in:
Jörg Prante 2022-08-09 22:30:04 +02:00
parent 01fcfaf16f
commit eac22c3f50
16 changed files with 102 additions and 91 deletions

View file

@ -44,12 +44,12 @@ public final class JsonNodeReader {
}
private static JsonNode readNode(final MappingIterator<JsonNode> 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;
}

View file

@ -139,4 +139,24 @@ public final class JsonPointer extends TreePointer<JsonNode> {
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();
}
}

View file

@ -24,8 +24,7 @@ import java.util.List;
*
* @param <T> the type of the tree
*/
public abstract class TreePointer<T extends TreeNode>
implements Iterable<TokenResolver<T>> {
public abstract class TreePointer<T extends TreeNode> implements Iterable<TokenResolver<T>> {
/**
* The reference token separator.
*/
@ -150,12 +149,12 @@ public abstract class TreePointer<T extends TreeNode>
}
@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<T extends TreeNode>
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<T> tokenResolver : tokenResolvers) {
sb.append('/').append(tokenResolver);

View file

@ -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

View file

@ -6,10 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
/**
*
*/
abstract class SubtagSet implements Cloneable, Iterable<Subtag>, Comparable<SubtagSet> {
abstract class SubtagSet implements Iterable<Subtag>, Comparable<SubtagSet> {
protected final Subtag primary;
@ -104,7 +101,7 @@ abstract class SubtagSet implements Cloneable, Iterable<Subtag>, Comparable<Subt
for (Subtag tag : this) {
tags.add(tag);
}
return tags.toArray(new Subtag[tags.size()]);
return tags.toArray(new Subtag[0]);
}
public List<Subtag> asList() {
@ -123,10 +120,10 @@ abstract class SubtagSet implements Cloneable, Iterable<Subtag>, Comparable<Subt
return c;
}
}
if (e.hasNext() && !i.hasNext()) {
if (e.hasNext()) {
return -1;
}
if (i.hasNext() && !e.hasNext()) {
if (i.hasNext()) {
return 1;
}
return 0;

View file

@ -2,6 +2,7 @@ package org.xbib.content.rdf.internal;
import org.xbib.content.resource.IRI;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
/**
@ -24,6 +25,16 @@ public class DefaultAnonymousResource extends DefaultResource {
super(id);
}
@Override
public boolean equals(Object obj) {
return obj instanceof DefaultAnonymousResource && id().equals(((DefaultAnonymousResource) obj).id());
}
@Override
public int hashCode() {
return Objects.hashCode(id());
}
// for test
public static void reset() {
nodeID.set(0L);

View file

@ -99,7 +99,6 @@ public class DefaultLiteral implements Literal, Comparable<Literal> {
case "xsd:long":
return Long.parseLong(s);
case "xsd:int":
return Integer.parseInt(s);
case "xsd:gYear":
return Integer.parseInt(s);
case "xsd:boolean":

View file

@ -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;
}
}

View file

@ -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(' ');

View file

@ -53,6 +53,7 @@ public abstract class AbstractXmlResourceHandler<P extends RdfContentParams>
@Override
public void addToPredicate(QName parent, String content) {
// do nothing
}
@Override

View file

@ -20,11 +20,11 @@ public class LinkedHashMultiMap<K, V> implements MultiMap<K, V> {
this.map = new LinkedHashMap<>();
}
public LinkedHashMultiMap(MultiMap<K, V> map) {
Objects.requireNonNull(map);
public LinkedHashMultiMap(MultiMap<K, V> 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));
}
}

View file

@ -30,7 +30,7 @@ public final class IRINamespaceContext implements NamespaceContext {
private final SortedMap<String, Set<String>> prefixes;
protected final Object lock;
private final Object lock;
private List<String> sortedNamespacesByPrefixLength;

View file

@ -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();
}

View file

@ -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);

View file

@ -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<String, Map<String, String>> 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<String, String> groupSettings = hashMap.computeIfAbsent(name, k -> TinyMap.builder());
groupSettings.put(value, get(setting));
groupSettings.put(value, get(o));
}
}
TinyMap.Builder<String, Settings> retVal = TinyMap.builder();

View file

@ -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<String, Object> getAsStructuredMap() {
TinyMap.Builder<String, Object> stringObjectMap = TinyMap.builder();
for (String key : map.keySet()) {
String value = map.get(key);
for (Map.Entry<String, String> 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<String, Object> entry : stringObjectMap.entrySet()) {
String key = entry.getKey();
Object object = entry.getValue();
if (object instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> valMap = (Map<String, Object>) 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<String, String> 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<String, Object> innerMap = (Map<String, Object>) map.get(prefix + setting);
if (innerMap != null) {
for (String k : innerMap.keySet()) {
Object v = innerMap.get(k);
for (Map.Entry<String, Object> 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<String, Object> 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
}
}