fixes for deepsource
This commit is contained in:
parent
01fcfaf16f
commit
eac22c3f50
16 changed files with 102 additions and 91 deletions
|
@ -44,12 +44,12 @@ public final class JsonNodeReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonNode readNode(final MappingIterator<JsonNode> iterator) throws IOException {
|
private static JsonNode readNode(final MappingIterator<JsonNode> iterator) throws IOException {
|
||||||
final Object source = iterator.getParser().getInputSource();
|
Object source = iterator.getParser().getInputSource();
|
||||||
final JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(null, source);
|
JsonParseExceptionBuilder builder = new JsonParseExceptionBuilder(null, source);
|
||||||
if (!iterator.hasNextValue()) {
|
if (!iterator.hasNextValue()) {
|
||||||
throw builder.build();
|
throw builder.build();
|
||||||
}
|
}
|
||||||
final JsonNode ret = iterator.nextValue();
|
JsonNode ret = iterator.nextValue();
|
||||||
builder.setLocation(iterator.getCurrentLocation());
|
builder.setLocation(iterator.getCurrentLocation());
|
||||||
try {
|
try {
|
||||||
if (iterator.hasNextValue()) {
|
if (iterator.hasNextValue()) {
|
||||||
|
@ -89,7 +89,7 @@ public final class JsonNodeReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class JsonParseExceptionBuilder {
|
private static class JsonParseExceptionBuilder {
|
||||||
|
|
||||||
private final JsonParser jsonParser;
|
private final JsonParser jsonParser;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public final class JsonNodeReader {
|
||||||
location = new JsonLocation(ContentReference.construct(false, source), 0L, 1, 1);
|
location = new JsonLocation(ContentReference.construct(false, source), 0L, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonParseExceptionBuilder setLocation(final JsonLocation location) {
|
JsonParseExceptionBuilder setLocation(final JsonLocation location) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,4 +139,24 @@ public final class JsonPointer extends TreePointer<JsonNode> {
|
||||||
return size <= 1 ? EMPTY
|
return size <= 1 ? EMPTY
|
||||||
: new JsonPointer(tokenResolvers.subList(0, size - 1));
|
: 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @param <T> the type of the tree
|
* @param <T> the type of the tree
|
||||||
*/
|
*/
|
||||||
public abstract class TreePointer<T extends TreeNode>
|
public abstract class TreePointer<T extends TreeNode> implements Iterable<TokenResolver<T>> {
|
||||||
implements Iterable<TokenResolver<T>> {
|
|
||||||
/**
|
/**
|
||||||
* The reference token separator.
|
* The reference token separator.
|
||||||
*/
|
*/
|
||||||
|
@ -150,12 +149,12 @@ public abstract class TreePointer<T extends TreeNode>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public int hashCode() {
|
||||||
return tokenResolvers.hashCode();
|
return tokenResolvers.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(final Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -165,12 +164,12 @@ public abstract class TreePointer<T extends TreeNode>
|
||||||
if (getClass() != obj.getClass()) {
|
if (getClass() != obj.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final TreePointer<?> other = (TreePointer<?>) obj;
|
TreePointer<?> other = (TreePointer<?>) obj;
|
||||||
return tokenResolvers.equals(other.tokenResolvers);
|
return tokenResolvers.equals(other.tokenResolvers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
for (final TokenResolver<T> tokenResolver : tokenResolvers) {
|
for (final TokenResolver<T> tokenResolver : tokenResolvers) {
|
||||||
sb.append('/').append(tokenResolver);
|
sb.append('/').append(tokenResolver);
|
||||||
|
|
|
@ -445,7 +445,7 @@ public class Range extends SubtagSet {
|
||||||
langs.add(l);
|
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);
|
langs.add(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return langs.toArray(new String[langs.size()]);
|
return langs.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,10 +6,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
/**
|
abstract class SubtagSet implements Iterable<Subtag>, Comparable<SubtagSet> {
|
||||||
*
|
|
||||||
*/
|
|
||||||
abstract class SubtagSet implements Cloneable, Iterable<Subtag>, Comparable<SubtagSet> {
|
|
||||||
|
|
||||||
protected final Subtag primary;
|
protected final Subtag primary;
|
||||||
|
|
||||||
|
@ -104,7 +101,7 @@ abstract class SubtagSet implements Cloneable, Iterable<Subtag>, Comparable<Subt
|
||||||
for (Subtag tag : this) {
|
for (Subtag tag : this) {
|
||||||
tags.add(tag);
|
tags.add(tag);
|
||||||
}
|
}
|
||||||
return tags.toArray(new Subtag[tags.size()]);
|
return tags.toArray(new Subtag[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Subtag> asList() {
|
public List<Subtag> asList() {
|
||||||
|
@ -123,10 +120,10 @@ abstract class SubtagSet implements Cloneable, Iterable<Subtag>, Comparable<Subt
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.hasNext() && !i.hasNext()) {
|
if (e.hasNext()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (i.hasNext() && !e.hasNext()) {
|
if (i.hasNext()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.xbib.content.rdf.internal;
|
||||||
|
|
||||||
import org.xbib.content.resource.IRI;
|
import org.xbib.content.resource.IRI;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +25,16 @@ public class DefaultAnonymousResource extends DefaultResource {
|
||||||
super(id);
|
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
|
// for test
|
||||||
public static void reset() {
|
public static void reset() {
|
||||||
nodeID.set(0L);
|
nodeID.set(0L);
|
||||||
|
|
|
@ -99,7 +99,6 @@ public class DefaultLiteral implements Literal, Comparable<Literal> {
|
||||||
case "xsd:long":
|
case "xsd:long":
|
||||||
return Long.parseLong(s);
|
return Long.parseLong(s);
|
||||||
case "xsd:int":
|
case "xsd:int":
|
||||||
return Integer.parseInt(s);
|
|
||||||
case "xsd:gYear":
|
case "xsd:gYear":
|
||||||
return Integer.parseInt(s);
|
return Integer.parseInt(s);
|
||||||
case "xsd:boolean":
|
case "xsd:boolean":
|
||||||
|
|
|
@ -175,30 +175,4 @@ public class NTripleContentGenerator
|
||||||
}
|
}
|
||||||
return sb.toString();
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@ public final class NTriplesParser implements CharSink {
|
||||||
private static final char SENTENCE_END = '.';
|
private static final char SENTENCE_END = '.';
|
||||||
|
|
||||||
private static final BitSet WHITESPACE = new BitSet() {
|
private static final BitSet WHITESPACE = new BitSet() {
|
||||||
private static final long serialVersionUID = 2369480497714252078L;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
set('\t');
|
set('\t');
|
||||||
set(' ');
|
set(' ');
|
||||||
|
|
|
@ -53,6 +53,7 @@ public abstract class AbstractXmlResourceHandler<P extends RdfContentParams>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToPredicate(QName parent, String content) {
|
public void addToPredicate(QName parent, String content) {
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,11 +20,11 @@ public class LinkedHashMultiMap<K, V> implements MultiMap<K, V> {
|
||||||
this.map = new LinkedHashMap<>();
|
this.map = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedHashMultiMap(MultiMap<K, V> map) {
|
public LinkedHashMultiMap(MultiMap<K, V> multiMap) {
|
||||||
Objects.requireNonNull(map);
|
Objects.requireNonNull(multiMap);
|
||||||
this.map = new LinkedHashMap<>();
|
this.map = new LinkedHashMap<>();
|
||||||
for (K k : map.keySet()) {
|
for (K k : multiMap.keySet()) {
|
||||||
putAll(k, map.get(k));
|
putAll(k, multiMap.get(k));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class IRINamespaceContext implements NamespaceContext {
|
||||||
|
|
||||||
private final SortedMap<String, Set<String>> prefixes;
|
private final SortedMap<String, Set<String>> prefixes;
|
||||||
|
|
||||||
protected final Object lock;
|
private final Object lock;
|
||||||
|
|
||||||
private List<String> sortedNamespacesByPrefixLength;
|
private List<String> sortedNamespacesByPrefixLength;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package org.xbib.content.resource.text;
|
package org.xbib.content.resource.text;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base implementation of a CodepointIterator that filters the output of another CodpointIterator.
|
* Base implementation of a CodepointIterator that filters the output of another CodpointIterator.
|
||||||
*/
|
*/
|
||||||
public abstract class DelegatingCodepointIterator extends CodepointIterator {
|
public abstract class DelegatingCodepointIterator extends CodepointIterator {
|
||||||
|
|
||||||
private CodepointIterator internal;
|
private final CodepointIterator internal;
|
||||||
|
|
||||||
|
private boolean hasNext;
|
||||||
|
|
||||||
protected DelegatingCodepointIterator(CodepointIterator internal) {
|
protected DelegatingCodepointIterator(CodepointIterator internal) {
|
||||||
this.internal = internal;
|
this.internal = internal;
|
||||||
|
@ -23,7 +27,8 @@ public abstract class DelegatingCodepointIterator extends CodepointIterator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return internal.hasNext();
|
hasNext = internal.hasNext();
|
||||||
|
return hasNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +48,9 @@ public abstract class DelegatingCodepointIterator extends CodepointIterator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Codepoint next() {
|
public Codepoint next() {
|
||||||
|
if (!hasNext) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
return internal.next();
|
return internal.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,15 +37,15 @@ public interface Settings extends AutoCloseable {
|
||||||
|
|
||||||
String get(String setting, String defaultValue);
|
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);
|
TimeValue getAsTime(String setting, TimeValue defaultValue);
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float getAsFloat(String setting, Float defaultValue) {
|
public float getAsFloat(String setting, float defaultValue) {
|
||||||
String sValue = get(setting);
|
String sValue = get(setting);
|
||||||
if (sValue == null) {
|
if (sValue == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -206,7 +206,7 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double getAsDouble(String setting, Double defaultValue) {
|
public double getAsDouble(String setting, double defaultValue) {
|
||||||
String sValue = get(setting);
|
String sValue = get(setting);
|
||||||
if (sValue == null) {
|
if (sValue == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -219,7 +219,7 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getAsInt(String setting, Integer defaultValue) {
|
public int getAsInt(String setting, int defaultValue) {
|
||||||
String sValue = get(setting);
|
String sValue = get(setting);
|
||||||
if (sValue == null) {
|
if (sValue == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -232,7 +232,7 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getAsLong(String setting, Long defaultValue) {
|
public long getAsLong(String setting, long defaultValue) {
|
||||||
String sValue = get(setting);
|
String sValue = get(setting);
|
||||||
if (sValue == null) {
|
if (sValue == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -245,7 +245,7 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getAsBoolean(String setting, Boolean defaultValue) {
|
public boolean getAsBoolean(String setting, boolean defaultValue) {
|
||||||
String value = get(setting);
|
String value = get(setting);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -290,7 +290,7 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
if (result.isEmpty()) {
|
if (result.isEmpty()) {
|
||||||
return defaultArray;
|
return defaultArray;
|
||||||
}
|
}
|
||||||
return result.toArray(new String[result.size()]);
|
return result.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -301,20 +301,19 @@ public class ContentSettings implements Settings, AutoCloseable {
|
||||||
}
|
}
|
||||||
// we don't really care that it might happen twice
|
// we don't really care that it might happen twice
|
||||||
TinyMap.Builder<String, Map<String, String>> hashMap = TinyMap.builder();
|
TinyMap.Builder<String, Map<String, String>> hashMap = TinyMap.builder();
|
||||||
for (Object o : this.map.keySet()) {
|
for (String o : this.map.keySet()) {
|
||||||
String setting = (String) o;
|
if (o.startsWith(settingPrefix)) {
|
||||||
if (setting.startsWith(settingPrefix)) {
|
String nameValue = o.substring(settingPrefix.length());
|
||||||
String nameValue = setting.substring(settingPrefix.length());
|
|
||||||
int dotIndex = nameValue.indexOf('.');
|
int dotIndex = nameValue.indexOf('.');
|
||||||
if (dotIndex == -1) {
|
if (dotIndex == -1) {
|
||||||
throw new SettingsException("Failed to get setting group for ["
|
throw new SettingsException("Failed to get setting group for ["
|
||||||
+ settingPrefix
|
+ 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 name = nameValue.substring(0, dotIndex);
|
||||||
String value = nameValue.substring(dotIndex + 1);
|
String value = nameValue.substring(dotIndex + 1);
|
||||||
Map<String, String> groupSettings = hashMap.computeIfAbsent(name, k -> TinyMap.builder());
|
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();
|
TinyMap.Builder<String, Settings> retVal = TinyMap.builder();
|
||||||
|
|
|
@ -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, ',');
|
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) {
|
if (s.length() == 0) {
|
||||||
return EMPTY_ARRAY;
|
return EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
|
@ -88,12 +88,14 @@ public class DatastructureSettings implements Settings {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getAsStructuredMap() {
|
public Map<String, Object> getAsStructuredMap() {
|
||||||
TinyMap.Builder<String, Object> stringObjectMap = TinyMap.builder();
|
TinyMap.Builder<String, Object> stringObjectMap = TinyMap.builder();
|
||||||
for (String key : map.keySet()) {
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
String value = map.get(key);
|
String key = entry.getKey();
|
||||||
|
String value = entry.getValue();
|
||||||
processSetting(stringObjectMap, "", key, value);
|
processSetting(stringObjectMap, "", key, value);
|
||||||
}
|
}
|
||||||
for (String key : stringObjectMap.keySet()) {
|
for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
|
||||||
Object object = stringObjectMap.get(key);
|
String key = entry.getKey();
|
||||||
|
Object object = entry.getValue();
|
||||||
if (object instanceof Map) {
|
if (object instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> valMap = (Map<String, Object>) object;
|
Map<String, Object> valMap = (Map<String, Object>) object;
|
||||||
|
@ -106,8 +108,9 @@ public class DatastructureSettings implements Settings {
|
||||||
@Override
|
@Override
|
||||||
public Settings getByPrefix(String prefix) {
|
public Settings getByPrefix(String prefix) {
|
||||||
DatastructureSettingsBuilder builder = new DatastructureSettingsBuilder();
|
DatastructureSettingsBuilder builder = new DatastructureSettingsBuilder();
|
||||||
for (String key : map.keySet()) {
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
String value = map.get(key);
|
String key = entry.getKey();
|
||||||
|
String value = entry.getValue();
|
||||||
if (key.startsWith(prefix)) {
|
if (key.startsWith(prefix)) {
|
||||||
if (key.length() < prefix.length()) {
|
if (key.length() < prefix.length()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -148,7 +151,7 @@ public class DatastructureSettings implements Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Float getAsFloat(String setting, Float defaultValue) {
|
public float getAsFloat(String setting, float defaultValue) {
|
||||||
String s = get(setting);
|
String s = get(setting);
|
||||||
try {
|
try {
|
||||||
return s == null ? defaultValue : Float.parseFloat(s);
|
return s == null ? defaultValue : Float.parseFloat(s);
|
||||||
|
@ -158,7 +161,7 @@ public class DatastructureSettings implements Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Double getAsDouble(String setting, Double defaultValue) {
|
public double getAsDouble(String setting, double defaultValue) {
|
||||||
String s = get(setting);
|
String s = get(setting);
|
||||||
try {
|
try {
|
||||||
return s == null ? defaultValue : Double.parseDouble(s);
|
return s == null ? defaultValue : Double.parseDouble(s);
|
||||||
|
@ -168,7 +171,7 @@ public class DatastructureSettings implements Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getAsInt(String setting, Integer defaultValue) {
|
public int getAsInt(String setting, int defaultValue) {
|
||||||
String s = get(setting);
|
String s = get(setting);
|
||||||
try {
|
try {
|
||||||
return s == null ? defaultValue : Integer.parseInt(s);
|
return s == null ? defaultValue : Integer.parseInt(s);
|
||||||
|
@ -178,7 +181,7 @@ public class DatastructureSettings implements Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getAsLong(String setting, Long defaultValue) {
|
public long getAsLong(String setting, long defaultValue) {
|
||||||
String s = get(setting);
|
String s = get(setting);
|
||||||
try {
|
try {
|
||||||
return s == null ? defaultValue : Long.parseLong(s);
|
return s == null ? defaultValue : Long.parseLong(s);
|
||||||
|
@ -188,7 +191,7 @@ public class DatastructureSettings implements Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean getAsBoolean(String setting, Boolean defaultValue) {
|
public boolean getAsBoolean(String setting, boolean defaultValue) {
|
||||||
String value = get(setting);
|
String value = get(setting);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
|
@ -283,8 +286,9 @@ public class DatastructureSettings implements Settings {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> innerMap = (Map<String, Object>) map.get(prefix + setting);
|
Map<String, Object> innerMap = (Map<String, Object>) map.get(prefix + setting);
|
||||||
if (innerMap != null) {
|
if (innerMap != null) {
|
||||||
for (String k : innerMap.keySet()) {
|
for (Map.Entry<String, Object> e : innerMap.entrySet()) {
|
||||||
Object v = innerMap.get(k);
|
String k = e.getKey();
|
||||||
|
Object v = e.getValue();
|
||||||
map.put(prefix + setting + "." + k, v);
|
map.put(prefix + setting + "." + k, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,8 +320,9 @@ public class DatastructureSettings implements Settings {
|
||||||
}
|
}
|
||||||
boolean isArray = true;
|
boolean isArray = true;
|
||||||
int maxIndex = -1;
|
int maxIndex = -1;
|
||||||
for (String key : map.keySet()) {
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||||
Object value = map.get(key);
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
if (isArray) {
|
if (isArray) {
|
||||||
try {
|
try {
|
||||||
int index = Integer.parseInt(key);
|
int index = Integer.parseInt(key);
|
||||||
|
@ -356,6 +361,6 @@ public class DatastructureSettings implements Settings {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue