Skip to content

Commit

Permalink
Prepare version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
virustotalop committed Apr 29, 2023
1 parent ac8f7f7 commit 8df46ed
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 55 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repositories {
maven { url 'https://jitpack.io' }
}
compile 'com.github.clubobsidian:wrappy:2.6.1'
compile 'com.github.clubobsidian:wrappy:3.0.0'
```

### Maven
Expand All @@ -43,7 +43,7 @@ compile 'com.github.clubobsidian:wrappy:2.6.1'
<dependency>
<groupId>com.github.clubobsidian</groupId>
<artifactId>wrappy</artifactId>
<version>2.6.1</version>
<version>3.0.0</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ dependencies {
}

shadowJar {
baseName = 'wrappy'
classifier = null
version = '2.6.1'
archiveBaseName.set('wrappy')
archiveClassifier.set('')
archiveVersion.set('3.0.0')
}

artifacts {
Expand Down
78 changes: 39 additions & 39 deletions src/main/java/com/clubobsidian/wrappy/ConfigurationSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,38 @@ public String getName() {
return (String) this.node.key();
}

public Object get(String path) {
public Object get(Object path) {
return this.get(path, Object.class);
}

public <T> T get(String path, Class<T> clazz) {
public <T> T get(Object path, Class<T> clazz) {
Object def = DEFAULT_VALUES.get(clazz);
return this.get(path, clazz, def == null ? null : (T) def);
}

public <T> T get(String path, Class<T> clazz, T defaultValue) {
public <T> T get(Object path, Class<T> clazz, T defaultValue) {
return new NodeHelper<T>(this).get(path, clazz, defaultValue);
}

@Deprecated
public <K, V> Map<K, V> getMap(String path) {
public <K, V> Map<K, V> getMap(Object path) {
Object objMap = this.get(path);
if(objMap == null || !(objMap instanceof Map)) {
return null;
}
return (Map<K, V>) objMap;
}

public <K, V> Map<K, V> getMap(String path, Class<K> keyType, Class<V> valueType) {
public <K, V> Map<K, V> getMap(Object path, Class<K> keyType, Class<V> valueType) {
ConfigurationSection virtual = new ConfigurationSection();
virtual.node = BasicConfigurationNode.factory().createNode();
ConfigurationSection section = this.getConfigurationSection(path);
Collection<String> keys = section.getKeys();
Collection<Object> keys = section.getKeys();
if(keys.size() == 0) {
return null;
}
Map<K, V> map = new HashMap<>();
for (String key : keys) {
for (Object key : keys) {
V mapValue = (V) section.get(key, valueType);
String uuid = UUID.randomUUID().toString();
virtual.set(uuid, key);
Expand All @@ -114,103 +114,103 @@ public <K, V> Map<K, V> getMap(String path, Class<K> keyType, Class<V> valueType
return map;
}

public String getString(String path) {
public String getString(Object path) {
return this.get(path, String.class);
}

public int getInteger(String path) {
public int getInteger(Object path) {
return this.get(path, int.class);
}

public long getLong(String path) {
public long getLong(Object path) {
return this.get(path, long.class);
}

public float getFloat(String path) {
public float getFloat(Object path) {
return this.get(path, float.class);
}

public boolean getBoolean(String path) {
public boolean getBoolean(Object path) {
return this.get(path, boolean.class);
}

public double getDouble(String path) {
public double getDouble(Object path) {
return this.get(path, double.class);
}

public <T extends Enum> T getEnum(String path, Class<T> enumClass) {
public <T extends Enum> T getEnum(Object path, Class<T> enumClass) {
return this.get(path, enumClass);
}

public URI getURI(String path) {
public URI getURI(Object path) {
return this.get(path, URI.class);
}

public URL getURL(String path) {
public URL getURL(Object path) {
return this.get(path, URL.class);
}

public UUID getUUID(String path) {
public UUID getUUID(Object path) {
return this.get(path, UUID.class);
}

public Pattern getPattern(String path) {
public Pattern getPattern(Object path) {
return this.get(path, Pattern.class);
}

public List<String> getStringList(String path) {
public List<String> getStringList(Object path) {
return this.getList(path, String.class);
}

public List<Integer> getIntegerList(String path) {
public List<Integer> getIntegerList(Object path) {
return this.getList(path, Integer.class);
}

public List<Long> getLongList(String path) {
public List<Long> getLongList(Object path) {
return this.getList(path, Long.class);
}

public List<Float> getFloatList(String path) {
public List<Float> getFloatList(Object path) {
return this.getList(path, Float.class);
}

public List<Boolean> getBooleanList(String path) {
public List<Boolean> getBooleanList(Object path) {
return this.getList(path, Boolean.class);
}

public List<Double> getDoubleList(String path) {
public List<Double> getDoubleList(Object path) {
return this.getList(path, Double.class);
}

public <T extends Enum> List<T> getEnumList(String path, Class<T> enumClass) {
public <T extends Enum> List<T> getEnumList(Object path, Class<T> enumClass) {
return this.getList(path, enumClass);
}

public List<URI> getURIList(String path) {
public List<URI> getURIList(Object path) {
return this.getList(path, URI.class);
}

public List<URL> getURLList(String path) {
public List<URL> getURLList(Object path) {
return this.getList(path, URL.class);
}

public List<UUID> getUUIDList(String path) {
public List<UUID> getUUIDList(Object path) {
return this.getList(path, UUID.class);
}

public List<Pattern> getPatternList(String path) {
public List<Pattern> getPatternList(Object path) {
return this.getList(path, Pattern.class);
}

public <T> List<T> getList(String path, Class<T> clazz) {
public <T> List<T> getList(Object path, Class<T> clazz) {
return new NodeHelper<T>(this).getList(path, clazz);
}

public ConfigurationSection createConfigurationSection(String path) {
public ConfigurationSection createConfigurationSection(Object path) {
return this.getConfigurationSection(path);
}

public ConfigurationSection getConfigurationSection(String path) {
public ConfigurationSection getConfigurationSection(Object path) {
ConfigurationSection section = new ConfigurationSection();
section.node = NodeUtil.parsePath(this.node, path);
return section;
Expand All @@ -221,11 +221,11 @@ public ConfigurationSection combine(ConfigurationSection from) {
return this;
}

public boolean exists(String path) {
public boolean exists(Object path) {
return !NodeUtil.parsePath(this.node, path).virtual();
}

public void set(String path, Object toSave) {
public void set(Object path, Object toSave) {
Object saveToPath = toSave;
if(saveToPath instanceof List) {
saveToPath = this.convertList(saveToPath);
Expand All @@ -239,17 +239,17 @@ public void set(String path, Object toSave) {
}
}

public List<String> getKeys() {
List<String> keys = new ArrayList<>();
this.node.childrenMap().keySet().forEach(n -> keys.add((String) n));
public List<Object> getKeys() {
List<Object> keys = new ArrayList<>();
this.node.childrenMap().keySet().forEach(n -> keys.add(n));
return keys;
}

public boolean isEmpty() {
return this.getKeys().size() == 0;
}

public boolean hasKey(String key) {
public boolean hasKey(Object key) {
return this.getKeys().contains(key);
}

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/clubobsidian/wrappy/helper/NodeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,18 @@ public NodeHelper(ConfigurationSection section) {
this.section = section;
}

public T get(String path, Class<T> clazz, T defaultValue) {
public T get(Object path, Class<T> clazz, T defaultValue) {
try {
ConfigurationNode parsed = NodeUtil.parsePath(this.section.getNode(), path);
TypeToken<T> type = TypeToken.get(clazz);
if(defaultValue == null) {
return parsed.get(type);
}
return parsed.get(type, defaultValue);
return defaultValue == null ? parsed.get(type) : parsed.get(type, defaultValue);
} catch (SerializationException e) {
e.printStackTrace();
}
return null;
}

public List<T> getList(String path, Class<T> clazz) {
public List<T> getList(Object path, Class<T> clazz) {
try {
ConfigurationNode parsed = NodeUtil.parsePath(this.section.getNode(), path);
return parsed.getList(TypeToken.get(clazz));
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/clubobsidian/wrappy/util/NodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ public final class NodeUtil {

private NodeUtil() {}

public static ConfigurationNode parsePath(ConfigurationNode node, String path) {
public static ConfigurationNode parsePath(ConfigurationNode node, Object path) {
if (!(path instanceof String)) {
return node.node(path);
}
String pathStr = (String) path;
Object[] ar = new Object[1];
if(path.contains(".")) {
String[] split = path.split("\\.");
if(pathStr.contains(".")) {
String[] split = pathStr.split("\\.");
ar = new Object[split.length];
for(int i = 0; i < split.length; i++) {
ar[i] = split[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void testGenericDoubleList() {
@Test
public void testGetKeys() {
config = Configuration.load(testFile);
List<String> keys = config.getKeys();
List<Object> keys = config.getKeys();
assertTrue(keys.size() > 0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.clubobsidian.wrappy.test.config;

import com.clubobsidian.wrappy.Configuration;
import org.junit.Test;

import java.io.File;
import java.util.UUID;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;

public class TestNonStringKeys {

private static File testFile = new File("test", "test-non-string-keys.yml");
private static Configuration config = Configuration.load(testFile);

@Test
public void testIntegerKey() {
assertEquals("bar", config.getConfigurationSection(1).getString("foo"));
}

@Test
public void testGetKeys() {
assertTrue(config.getKeys().size() > 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void getInvalidHash() {
try {
Method method = HashUtil.class.getDeclaredMethod("getHash", String.class, byte[].class);
method.setAccessible(true);
byte[] invoked = (byte[]) method.invoke(null, "INVALID", String.valueOf("test").getBytes());
byte[] invoked = (byte[]) method.invoke(null, "INVALID", "test".getBytes());
assertTrue(invoked.length == 0);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
Expand Down
2 changes: 2 additions & 0 deletions test/test-non-string-keys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1:
foo: bar

0 comments on commit 8df46ed

Please sign in to comment.