-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on internal libraries
- Loading branch information
1 parent
f5fc5d8
commit 705d8e6
Showing
4 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package enums | ||
|
||
|
||
object EnumUtils { | ||
trait Nameable { | ||
def name: String | ||
} | ||
trait Enumerable[T <: Nameable] { | ||
def values: Iterable[T] | ||
def withName(name: String): Option[T] = values.find(_.name == name) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
ocpp-messages/src/main/scala/enums/reflection/EnumUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package enums.reflection | ||
|
||
/** | ||
* This version of the enum utils can | ||
* only be used in top-level definitions, | ||
* otherwise the reflective .getSimpleName | ||
* call throws an exception. | ||
*/ | ||
object EnumUtils { | ||
|
||
trait Nameable { | ||
def name: String = this.getClass.getSimpleName | ||
.replaceAll("minus", "-").replaceAll("\\$", "")} | ||
|
||
trait Enumerable[T <: Nameable] { | ||
def values: Iterable[T] | ||
def withName(name: String): Option[T] = values.find(_.name == name) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters