Skip to content
This repository was archived by the owner on Apr 25, 2020. It is now read-only.

Commit 1ef6c55

Browse files
committed
Refactor TypedKey to TKey
1 parent 8db7595 commit 1ef6c55

File tree

9 files changed

+172
-121
lines changed

9 files changed

+172
-121
lines changed

src/main/scala/com/ckkloverdos/env/Env.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2011 Christos KK Loverdos
2+
* Copyright 2011-2013 Christos KK Loverdos
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,41 +18,41 @@ package com.ckkloverdos.env
1818

1919
import com.ckkloverdos.key._
2020

21-
final class Env private[env](private[env] val map: Map[TypedKey[_], Any]) extends EnvBase[Env] {
21+
final class Env private[env](private[env] val map: Map[TKey[_], Any]) extends EnvBase[Env] {
2222

23-
protected def newEnv(map: Map[TypedKey[_], Any]): Env = new Env(map)
23+
protected def newEnv(map: Map[TKey[_], Any]): Env = new Env(map)
2424

2525
def +[T : Manifest](
26-
key: TypedKeyOnly[T],
26+
key: TKeyOnly[T],
2727
value: T
2828
): Env = {
2929

3030
new Env(map + (key -> value))
3131
}
3232

3333
def +[T : Manifest](
34-
key: TypedKeyWithDefault[T],
34+
key: TKeyWithDefault[T],
3535
value: Option[T]
3636
): Env = {
3737

3838
new Env(map + (key -> value.getOrElse(key.default)))
3939
}
4040

4141
def +[T : Manifest](
42-
key: TypedKeyWithDefault[T],
42+
key: TKeyWithDefault[T],
4343
value: T
4444
): Env = {
4545

4646
new Env(map + (key -> value))
4747
}
4848

49-
def +[T : Manifest](kv: (TypedKeyOnly[T], T)): Env = new Env(map + kv)
49+
def +[T : Manifest](kv: (TKeyOnly[T], T)): Env = new Env(map + kv)
5050

5151
def ++(other: EnvBase[_]): Env = new Env(other.map ++ map)
5252

53-
def -[T: Manifest](key: TypedKey[T]): Env = new Env(map - key)
53+
def -[T: Manifest](key: TKey[T]): Env = new Env(map - key)
5454

55-
def getRemove[T: Manifest](key: TypedKey[T]): (Option[T], Env) = {
55+
def getRemove[T: Manifest](key: TKey[T]): (Option[T], Env) = {
5656
get(key) match {
5757
case some @ Some(_)
5858
(some, this - key)

src/main/scala/com/ckkloverdos/env/EnvBase.scala

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2012 Christos KK Loverdos
2+
* Copyright 2011-2013 Christos KK Loverdos
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,32 +16,32 @@
1616

1717
package com.ckkloverdos.env
1818

19-
import com.ckkloverdos.key.TypedKey
19+
import com.ckkloverdos.key.TKey
2020

2121
/**
2222
*
2323
* @author Christos KK Loverdos <loverdos@gmail.com>
2424
*/
2525

2626
abstract class EnvBase[E <: EnvBase[E]] { self: E
27-
private[env] def map: Map[TypedKey[_], Any]
28-
protected def newEnv(map: Map[TypedKey[_], Any]): E
27+
private[env] def map: Map[TKey[_], Any]
28+
protected def newEnv(map: Map[TKey[_], Any]): E
2929

3030
def selectName(keyName: String): E =
3131
newEnv(Map(keysOfName(keyName).toSeq.map(tk => (tk, map(tk))): _*))
3232

3333
def selectType[T : Manifest]: E =
3434
newEnv(Map(keysOfType[T].toSeq.map(tk => (tk, map(tk))): _*))
3535

36-
def contains[T : Manifest](key: TypedKey[T]): Boolean = {
36+
def contains[T : Manifest](key: TKey[T]): Boolean = {
3737
map.contains(key)
3838
}
3939

40-
def keysOfType[T : Manifest]: Set[TypedKey[T]] = {
40+
def keysOfType[T : Manifest]: Set[TKey[T]] = {
4141
for {
4242
typedKey <- map.keySet if(manifest[T] == typedKey.keyType)
4343
} yield {
44-
typedKey.asInstanceOf[TypedKey[T]]
44+
typedKey.asInstanceOf[TKey[T]]
4545
}
4646
}
4747

@@ -73,7 +73,7 @@ abstract class EnvBase[E <: EnvBase[E]] { self: E ⇒
7373
*/
7474
@throws(classOf[NoSuchElementException])
7575
@throws(classOf[ClassCastException])
76-
def apply[T : Manifest](key: TypedKey[T]): T = {
76+
def apply[T : Manifest](key: TKey[T]): T = {
7777
map(key).asInstanceOf[T]
7878
}
7979

@@ -83,15 +83,15 @@ abstract class EnvBase[E <: EnvBase[E]] { self: E ⇒
8383
@inline
8484
@throws(classOf[NoSuchElementException])
8585
@throws(classOf[ClassCastException])
86-
def getEx[T : Manifest](key: TypedKey[T]): T = {
86+
def getEx[T : Manifest](key: TKey[T]): T = {
8787
this apply key
8888
}
8989

90-
def get[T : Manifest](key: TypedKey[T]): Option[T] = {
90+
def get[T : Manifest](key: TKey[T]): Option[T] = {
9191
map.get(key).asInstanceOf[Option[T]]
9292
}
9393

94-
def getOrElse[T : Manifest](key: TypedKey[T], default: T): T = {
94+
def getOrElse[T : Manifest](key: TKey[T], default: T): T = {
9595
map.get(key) match {
9696
case Some(value)
9797
value.asInstanceOf[T]
@@ -111,7 +111,7 @@ abstract class EnvBase[E <: EnvBase[E]] { self: E ⇒
111111

112112
def keysIterator = map.keysIterator
113113

114-
def keysOfName(keyName: String): Set[TypedKey[_]] = {
114+
def keysOfName(keyName: String): Set[TKey[_]] = {
115115
for {
116116
typedKey <- map.keySet if(typedKey.name == keyName)
117117
} yield {

src/main/scala/com/ckkloverdos/env/EnvHelpers.scala

+61-45
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,96 @@
1+
/*
2+
* Copyright 2011-2013 Christos KK Loverdos
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package com.ckkloverdos.env
218

3-
import com.ckkloverdos.key.{TypedKeyWithDefault, TypedKeyOnly}
19+
import com.ckkloverdos.key.{TKeyWithDefault, TKeyOnly}
420
import java.util.Date
521

622
/**
723
*
824
* @author Christos KK Loverdos <loverdos@gmail.com>
925
*/
1026
sealed class EnvHelpers {
11-
def newTypedKeyOnly[A](name: String, typ: Class[A]): TypedKeyOnly[A] = {
12-
new TypedKeyOnly[A](name)(Manifest.classType[A](typ))
27+
def newTypedKeyOnly[A](name: String, typ: Class[A]): TKeyOnly[A] = {
28+
new TKeyOnly[A](name)(Manifest.classType[A](typ))
1329
}
1430

15-
def newTypedKeyWithDefault[A](name: String, value: A, typ: Class[A]): TypedKeyWithDefault[A] = {
16-
new TypedKeyWithDefault[A](name, value)((Manifest.classType[A](typ)))
31+
def newTypedKeyWithDefault[A](name: String, value: A, typ: Class[A]): TKeyWithDefault[A] = {
32+
new TKeyWithDefault[A](name, value)((Manifest.classType[A](typ)))
1733
}
1834

19-
def ByteKey(name: String): TypedKeyOnly[Byte] =
20-
new TypedKeyOnly(name)
35+
def ByteKey(name: String): TKeyOnly[Byte] =
36+
new TKeyOnly(name)
2137

22-
def ByteKey(name: String, value: Byte): TypedKeyWithDefault[Byte] =
23-
new TypedKeyWithDefault(name, value)
38+
def ByteKey(name: String, value: Byte): TKeyWithDefault[Byte] =
39+
new TKeyWithDefault(name, value)
2440

25-
def BooleanKey(name: String): TypedKeyOnly[Boolean] =
26-
new TypedKeyOnly(name)
41+
def BooleanKey(name: String): TKeyOnly[Boolean] =
42+
new TKeyOnly(name)
2743

28-
def BooleanKey(name: String, value: Boolean): TypedKeyWithDefault[Boolean] =
29-
new TypedKeyWithDefault(name, value)
44+
def BooleanKey(name: String, value: Boolean): TKeyWithDefault[Boolean] =
45+
new TKeyWithDefault(name, value)
3046

31-
def ShortKey(name: String): TypedKeyOnly[Short] =
32-
new TypedKeyOnly(name)
47+
def ShortKey(name: String): TKeyOnly[Short] =
48+
new TKeyOnly(name)
3349

34-
def ShortKey(name: String, value: Short): TypedKeyWithDefault[Short] =
35-
new TypedKeyWithDefault(name, value)
50+
def ShortKey(name: String, value: Short): TKeyWithDefault[Short] =
51+
new TKeyWithDefault(name, value)
3652

37-
def CharKey(name: String): TypedKeyOnly[Char] =
38-
new TypedKeyOnly(name)
53+
def CharKey(name: String): TKeyOnly[Char] =
54+
new TKeyOnly(name)
3955

40-
def CharKey(name: String, value: Char): TypedKeyWithDefault[Char] =
41-
new TypedKeyWithDefault(name, value)
56+
def CharKey(name: String, value: Char): TKeyWithDefault[Char] =
57+
new TKeyWithDefault(name, value)
4258

43-
def IntKey(name: String): TypedKeyOnly[Int] =
44-
new TypedKeyOnly(name)
59+
def IntKey(name: String): TKeyOnly[Int] =
60+
new TKeyOnly(name)
4561

46-
def IntKey(name: String, value: Int): TypedKeyWithDefault[Int] =
47-
new TypedKeyWithDefault(name, value)
62+
def IntKey(name: String, value: Int): TKeyWithDefault[Int] =
63+
new TKeyWithDefault(name, value)
4864

49-
def LongKey(name: String): TypedKeyOnly[Long] =
50-
new TypedKeyOnly(name)
65+
def LongKey(name: String): TKeyOnly[Long] =
66+
new TKeyOnly(name)
5167

52-
def LongKey(name: String, value: Long): TypedKeyWithDefault[Long] =
53-
new TypedKeyWithDefault(name, value)
68+
def LongKey(name: String, value: Long): TKeyWithDefault[Long] =
69+
new TKeyWithDefault(name, value)
5470

55-
def FloatKey(name: String): TypedKeyOnly[Float] =
56-
new TypedKeyOnly(name)
71+
def FloatKey(name: String): TKeyOnly[Float] =
72+
new TKeyOnly(name)
5773

58-
def FloatKey(name: String, value: Float): TypedKeyWithDefault[Float] =
59-
new TypedKeyWithDefault(name, value)
74+
def FloatKey(name: String, value: Float): TKeyWithDefault[Float] =
75+
new TKeyWithDefault(name, value)
6076

61-
def DoubleKey(name: String): TypedKeyOnly[Double] =
62-
new TypedKeyOnly(name)
77+
def DoubleKey(name: String): TKeyOnly[Double] =
78+
new TKeyOnly(name)
6379

64-
def DoubleKey(name: String, value: Double): TypedKeyWithDefault[Double] =
65-
new TypedKeyWithDefault(name, value)
80+
def DoubleKey(name: String, value: Double): TKeyWithDefault[Double] =
81+
new TKeyWithDefault(name, value)
6682

67-
def StringKey(name: String): TypedKeyOnly[String] =
68-
new TypedKeyOnly(name)
83+
def StringKey(name: String): TKeyOnly[String] =
84+
new TKeyOnly(name)
6985

70-
def StringKey(name: String, value: String): TypedKeyWithDefault[String] =
71-
new TypedKeyWithDefault(name, value)
86+
def StringKey(name: String, value: String): TKeyWithDefault[String] =
87+
new TKeyWithDefault(name, value)
7288

73-
def DateKey(name: String): TypedKeyOnly[Date] =
74-
new TypedKeyOnly(name)
89+
def DateKey(name: String): TKeyOnly[Date] =
90+
new TKeyOnly(name)
7591

76-
def DateKey(name: String, value: Date): TypedKeyWithDefault[Date] =
77-
new TypedKeyWithDefault(name, value)
92+
def DateKey(name: String, value: Date): TKeyWithDefault[Date] =
93+
new TKeyWithDefault(name, value)
7894

7995
}
8096

src/main/scala/com/ckkloverdos/env/EnvKey.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2012 Christos KK Loverdos
2+
* Copyright 2011-2013 Christos KK Loverdos
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,7 +16,7 @@
1616

1717
package com.ckkloverdos.env
1818

19-
import com.ckkloverdos.key.TypedKeyWithDefault
19+
import com.ckkloverdos.key.TKeyWithDefault
2020

2121
/**
2222
* A typed key for an [[com.ckkloverdos.env.Env]] with a default value of an empty `Env`.
@@ -27,4 +27,4 @@ import com.ckkloverdos.key.TypedKeyWithDefault
2727
case class EnvKey(
2828
override val name: String,
2929
override val default: Env = Env()
30-
) extends TypedKeyWithDefault(name, default)
30+
) extends TKeyWithDefault(name, default)

0 commit comments

Comments
 (0)