Skip to content

Commit

Permalink
Nummer as counterpart to Text added
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Jan 26, 2018
1 parent 3d10613 commit a0ac589
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@
<artifactId>patterntesting-rt</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.lukehutch</groupId>
<artifactId>fast-classpath-scanner</artifactId>
<version>2.12.0</version>
</dependency>

</dependencies>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/jfachwert/FachwertFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class FachwertFactory {
// Problem).
static {
INSTANCE.register(Text.class);
INSTANCE.register(Nummer.class);
INSTANCE.register(Bankverbindung.class);
INSTANCE.register(BIC.class);
INSTANCE.register(BLZ.class);
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/de/jfachwert/Nummer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2018 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 24.01.2018 by oboehm (ob@oasd.de)
*/
package de.jfachwert;

import de.jfachwert.pruefung.exception.InvalidValueException;

import java.math.BigDecimal;

/**
* Die Klasse Nummer dient zum Abspeichern einer beliebigen Nummer. Sie ist
* die Ergaenzung zur {@link Text}-Klasse.
*
* @author oboehm
* @since x.6 (24.01.2018)
*/
public class Nummer extends AbstractFachwert<BigDecimal> {

/**
* Erzeugt eine Nummer als positive oder negative Ganzzahl.
*
* @param code eine Zahl, z.B. 42
*/
public Nummer(int code) {
this(BigDecimal.valueOf(code));
}

/**
* Wandelt den angegebene String in eine Zahl um.
*
* @param code z.B. "42"
*/
public Nummer(String code) {
this(new BigDecimal(validate(code)));
}

/**
* Erzeugt eine beliebige Gleitkomma- oder Ganzzahl.
*
* @param code eine beliebige Zahl
*/
public Nummer(BigDecimal code) {
super(code);
}

/**
* Ueberprueft, ob der uebergebene String auch tatsaechlich eine Zahl ist.
*
* @param nummer z.B. "4711"
* @return validierter String zur Weiterverarbeitung
*/
public static String validate(String nummer) {
try {
return new BigDecimal(nummer).toString();
} catch (NumberFormatException nfe) {
throw new InvalidValueException(nummer, "number");
}
}

/**
* Liefert die Zahl als Integer zurueck.
*
* @return z.B. 42
*/
public int intValue() {
return this.getCode().intValue();
}

}
45 changes: 45 additions & 0 deletions src/test/java/de/jfachwert/NummerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 26.01.2018 by oboehm (ob@oasd.de)
*/
package de.jfachwert;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* Unit-Tests fuer {@link Nummer}-Klasse.
*
* @author oboehm
*/
public final class NummerTest extends AbstractFachwertTest {

@Override
protected Nummer createFachwert() {
return new Nummer(42);
}

/**
* Test-Methode fuer {@link Nummer#intValue()}.
*/
@Test
public void testGet() {
Nummer nummer = new Nummer("4711");
assertEquals(4711, nummer.intValue());
}

}
7 changes: 6 additions & 1 deletion src/test/java/de/jfachwert/TextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
*
* @author oboehm
*/
public final class TextTest {
public final class TextTest extends AbstractFachwertTest {

@Override
protected Text createFachwert() {
return new Text("Hallo Welt!");
}

/**
* Es sollte nicht moeglich sein, einen Null-Text anzulegen.
Expand Down

0 comments on commit a0ac589

Please sign in to comment.