Skip to content
This repository was archived by the owner on Aug 17, 2019. It is now read-only.

Commit 7613371

Browse files
committed
Add subsetForKeyPrefix
1 parent 5298d8d commit 7613371

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/main/scala/com/ckkloverdos/props/Props.scala

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Props(val map: Map[String, String])(implicit conv: Converters = Converters
3737

3838
val converters = conv
3939

40+
def subsetForKeyPrefix(prefix: String): Props = {
41+
val _prefix = prefix + "."
42+
filterKeys(_.startsWith(_prefix))
43+
}
44+
4045
def getBoolean(key: String): Maybe[Boolean] = map.get(key) match {
4146
case Some(value) conv.convertToBoolean(value)
4247
case None NoVal

src/main/scala/com/ckkloverdos/props/PropsBase.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.ckkloverdos.props
1818

1919
import com.ckkloverdos.convert.Converters
20-
import com.ckkloverdos.maybe.{MaybeOption, NoVal, Maybe}
20+
import com.ckkloverdos.maybe.Maybe
2121

2222

2323
/**
@@ -35,12 +35,12 @@ trait PropsBase[K, V, P <: PropsBase[K, V, P]] {
3535

3636
def contains(key: K) = map contains key
3737

38-
def filterKeys(f: K => Boolean) = newProps(map filterKeys f)
38+
def filterKeys(f: K Boolean) = newProps(map filterKeys f)
3939

40-
def filterValues(f: V => Boolean) = newProps(map filter {case (k, v) => f(v)})
40+
def filterValues(f: V Boolean) = newProps(map filter { case (_, v) f(v) })
4141

4242
/**
43-
* Get a value or throw an exception if it doesnot exist.
43+
* Get a value or throw an exception if it does not exist.
4444
*/
4545
@throws(classOf[NoSuchElementException])
4646
def getEx(key: K): V = map apply key
@@ -54,4 +54,6 @@ trait PropsBase[K, V, P <: PropsBase[K, V, P]] {
5454
def keySet: Set[K] = map.keySet
5555

5656
def keysIterator: Iterator[K] = map.keysIterator
57+
58+
def isEmpty = size == 0
5759
}

0 commit comments

Comments
 (0)