Skip to content

Commit

Permalink
Support CurrencyID.valueOf(String s) for well known properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dexX7 committed Jan 29, 2015
1 parent a8729e9 commit 804c402
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/foundation/omni/CurrencyID.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ public final class CurrencyID extends Number implements Cloneable {
public static final CurrencyID MaidSafeCoin = new CurrencyID(MaidSafeCoin_VALUE);
public static final CurrencyID TetherUS = new CurrencyID(TetherUS_VALUE);

public static CurrencyID valueOf(String s) {
switch (s) {
case "BTC":
return BTC;
case "MSC":
return MSC;
case "TMSC":
return TMSC;
case "MaidSafeCoin":
return MaidSafeCoin;
case "TetherUS":
return TetherUS;
}
throw new NumberFormatException();
}

public CurrencyID(long value) {
if (value < MIN_VALUE) {
throw new NumberFormatException();
Expand Down
17 changes: 17 additions & 0 deletions src/test/groovy/foundation/omni/CurrencyIDSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package foundation.omni

import spock.lang.Specification
import spock.lang.Unroll

/**
* User: sean
Expand Down Expand Up @@ -152,4 +153,20 @@ class CurrencyIDSpec extends Specification {
4294967295 | "CurrencyID:4294967295"
}

@Unroll
def "The String \"#str\" can be used to create CurrencyID:#value"() {

expect:
CurrencyID currency = CurrencyID.valueOf(str)
currency.longValue() == value

where:
str | value
"BTC" | CurrencyID.BTC_VALUE
"MSC" | CurrencyID.MSC_VALUE
"TMSC" | CurrencyID.TMSC_VALUE
"MaidSafeCoin" | CurrencyID.MaidSafeCoin_VALUE
"TetherUS" | CurrencyID.TetherUS_VALUE
}

}

0 comments on commit 804c402

Please sign in to comment.