diff --git a/build.sbt b/build.sbt
index a379cb2..30cdb1d 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,6 +1,6 @@
organization := "io.sqooba"
scalaVersion := "2.12.7"
-version := "0.3.6.1"
+version := "0.3.7"
name := "sq-conf"
crossScalaVersions := Seq("2.12.7", "2.11.12")
diff --git a/java-test-app/pom.xml b/java-test-app/pom.xml
index 57d2f14..ec04249 100644
--- a/java-test-app/pom.xml
+++ b/java-test-app/pom.xml
@@ -8,7 +8,7 @@
io.sqooba
sq-conf_2.12
- 0.3.6
+ 0.3.6.3
diff --git a/java-test-app/src/main/resources/another.conf b/java-test-app/src/main/resources/another.conf
index d594c0e..807c439 100644
--- a/java-test-app/src/main/resources/another.conf
+++ b/java-test-app/src/main/resources/another.conf
@@ -1,3 +1,5 @@
some.int = 16
some.string = "perses"
-some.intList = [15, 16, 17]
\ No newline at end of file
+some.intList = [15, 16, 17]
+some.stringList = ["string1", "string2", "string3"]
+some.durationList = [10s, 10m, 10h]
\ No newline at end of file
diff --git a/java-test-app/src/main/resources/application.conf b/java-test-app/src/main/resources/application.conf
index 8904b0a..8a86da6 100644
--- a/java-test-app/src/main/resources/application.conf
+++ b/java-test-app/src/main/resources/application.conf
@@ -1,4 +1,6 @@
some.int = 15
some.string = "perse"
some.boolean = false
-some.intList = [15, 16, 17]
\ No newline at end of file
+some.intList = [15, 16, 17]
+some.stringList = ["string1", "string2", "string3"]
+some.durationList = [10s, 10m, 10h]
\ No newline at end of file
diff --git a/java-test-app/src/test/java/io/sqooba/sqconf/someapp/CreateOtherFileConfTest.java b/java-test-app/src/test/java/io/sqooba/sqconf/someapp/CreateOtherFileConfTest.java
index 127f69c..236aefc 100644
--- a/java-test-app/src/test/java/io/sqooba/sqconf/someapp/CreateOtherFileConfTest.java
+++ b/java-test-app/src/test/java/io/sqooba/sqconf/someapp/CreateOtherFileConfTest.java
@@ -2,8 +2,6 @@
import io.sqooba.conf.JavaSqConf;
import io.sqooba.conf.SqConf;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.junit.Test;
@@ -22,12 +20,7 @@ public void getIntCorrectly() {
@Test
public void getIntListCorrectly() {
Iterable someInts = conf.getIterable("some.intList");
- List ints = new ArrayList<>();
- Iterator iter = someInts.iterator();
-
- while (iter.hasNext()) {
- ints.add(iter.next());
- }
+ List ints = Util.fromIterToList(someInts);
assertEquals(3, ints.size());
}
diff --git a/java-test-app/src/test/java/io/sqooba/sqconf/someapp/SomeAppTest.java b/java-test-app/src/test/java/io/sqooba/sqconf/someapp/SomeAppTest.java
index 939fdd0..a184654 100644
--- a/java-test-app/src/test/java/io/sqooba/sqconf/someapp/SomeAppTest.java
+++ b/java-test-app/src/test/java/io/sqooba/sqconf/someapp/SomeAppTest.java
@@ -2,8 +2,8 @@
import io.sqooba.conf.JavaSqConf;
import io.sqooba.conf.SqConf;
-import java.util.HashMap;
-import java.util.Map;
+import java.time.Duration;
+import java.util.*;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -33,4 +33,37 @@ public void useOverWrites() {
String newVal = newConf.getString("some.string");
assertEquals("some.other.string", newVal);
}
+
+ @Test
+ public void getIterableOfStrings() {
+
+ Iterable someStrings = conf.getIterable("some.stringList");
+
+ List asList = Util.fromIterToList(someStrings);
+
+ assertEquals(3, asList.size());
+ assertEquals(asList.get(0), "string1");
+ assertEquals(asList.get(1), "string2");
+ assertEquals(asList.get(2), "string3");
+ }
+
+ @Test
+ public void getListOfStrings() {
+
+ List someStrings = conf.getListOf("some.stringList");
+
+ assertEquals(3, someStrings.size());
+ assertEquals(someStrings.get(0), "string1");
+ assertEquals(someStrings.get(1), "string2");
+ assertEquals(someStrings.get(2), "string3");
+ }
+
+ @Test
+ public void getListOfDuration() {
+
+ Iterable someStrings = conf.getIterable("some.durationList");
+ List asList = Util.fromIterToList(someStrings);
+
+ assertEquals(3, asList.size());
+ }
}
diff --git a/java-test-app/src/test/java/io/sqooba/sqconf/someapp/Util.java b/java-test-app/src/test/java/io/sqooba/sqconf/someapp/Util.java
new file mode 100644
index 0000000..56bec80
--- /dev/null
+++ b/java-test-app/src/test/java/io/sqooba/sqconf/someapp/Util.java
@@ -0,0 +1,18 @@
+package io.sqooba.sqconf.someapp;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class Util {
+
+ public static List fromIterToList(Iterable src) {
+ List res = new ArrayList<>();
+ Iterator iter = src.iterator();
+
+ while (iter.hasNext()) {
+ res.add(iter.next());
+ }
+ return res;
+ }
+}
diff --git a/src/main/scala/io/sqooba/conf/IterToList.java b/src/main/scala/io/sqooba/conf/IterToList.java
new file mode 100644
index 0000000..37bfcb4
--- /dev/null
+++ b/src/main/scala/io/sqooba/conf/IterToList.java
@@ -0,0 +1,17 @@
+package io.sqooba.conf;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class IterToList {
+ public static List fromIterToList(Iterable src) {
+ List res = new ArrayList<>();
+ Iterator iter = src.iterator();
+
+ while (iter.hasNext()) {
+ res.add(iter.next());
+ }
+ return res;
+ }
+}
diff --git a/src/main/scala/io/sqooba/conf/JavaSqConf.scala b/src/main/scala/io/sqooba/conf/JavaSqConf.scala
index 5c767fe..21708cd 100644
--- a/src/main/scala/io/sqooba/conf/JavaSqConf.scala
+++ b/src/main/scala/io/sqooba/conf/JavaSqConf.scala
@@ -1,5 +1,7 @@
package io.sqooba.conf
+import java.util
+
class JavaSqConf(sqConf: SqConf) {
def getSqConf: SqConf = sqConf
@@ -20,6 +22,8 @@ class JavaSqConf(sqConf: SqConf) {
list.asJava
}
+ def getListOf[T](key: String): util.List[T] = IterToList.fromIterToList(getIterable[T](key))
+
def keyAsEnv(key: String): String = sqConf.keyAsEnv(key)
def withOverwrites(ow: java.util.Map[java.lang.String, java.lang.String]): JavaSqConf = {
diff --git a/src/main/scala/io/sqooba/conf/SqConf.scala b/src/main/scala/io/sqooba/conf/SqConf.scala
index 1ba8998..bc06bf6 100644
--- a/src/main/scala/io/sqooba/conf/SqConf.scala
+++ b/src/main/scala/io/sqooba/conf/SqConf.scala
@@ -5,7 +5,6 @@ import java.io.File
import java.time.Duration
import scala.util.Properties
-import collection.JavaConverters._
import scala.collection.JavaConverters._
import com.typesafe.config.Config
@@ -99,22 +98,6 @@ class SqConf(fileName: String = null,
x.asInstanceOf[T]
}).toList
}
- /*
- def getListOfWithConversion[T](key: String, convert: String => T): List[T] = {
- val fullKey = buildKey(key)
-
- def stringToT(string: String): List[T] = string.split(',').map(convert).toList
-
- if (valueOverwrites.contains(fullKey)) {
- stringToT(valueOverwrites(fullKey))
- } else {
- Properties.envOrNone(keyAsEnv(fullKey)) match {
- case Some(env) => stringToT(env)
- case None => getListOf[T](fullKey)
- }
- }
- }
- */
def getListOfInt(key: String): List[Int] = getListOfWithConversion(key, str => str.trim.toInt)
@@ -125,7 +108,7 @@ class SqConf(fileName: String = null,
def getListOfBoolean(key: String): List[Boolean] = getListOfWithConversion(key, str => str.trim.toBoolean)
def getListOfDuration(key: String): List[Duration] = getListOfWithConversion[Duration](key, str =>
- DurationParser.parseDurationString(str, key, "listOfDuration"), false)
+ DurationParser.parseDurationString(str, key, "listOfDuration"), cast = false)
def getListOfWithConversion[T](key: String, convert: String => T, cast: Boolean = true): List[T] = {
val fullKey = buildKey(key)
diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf
index 7c27c8b..7d21964 100644
--- a/src/test/resources/application.conf
+++ b/src/test/resources/application.conf
@@ -5,7 +5,6 @@ some {
testLongValue = 100
testBigIntValue = 123456789
testStringListValue = ["some","list", "last"]
- testIntListValue = [100, 200, 300]
testBooleanListValue = [true, false, true]
testIntListValue = [123, 23, 69]
testDurationValue = 10m
diff --git a/src/test/scala/io/sqooba/conf/JavaWrapperSpec.scala b/src/test/scala/io/sqooba/conf/JavaWrapperSpec.scala
index c752f0b..6ec3d10 100644
--- a/src/test/scala/io/sqooba/conf/JavaWrapperSpec.scala
+++ b/src/test/scala/io/sqooba/conf/JavaWrapperSpec.scala
@@ -45,4 +45,13 @@ class JavaWrapperSpec extends FlatSpec with Matchers {
stringy shouldBe a [java.lang.String]
stringy shouldBe "string thing"
}
+
+ "get list of ints" should "return valid java list" in {
+ // testIntListValue = [123, 23, 69]
+ val listOf = javaWrapper.getListOf[Integer]("some.testIntListValue")
+ listOf.size() shouldBe 3
+ listOf.get(0) shouldBe 123
+ listOf.get(1) shouldBe 23
+ listOf.get(2) shouldBe 69
+ }
}