Skip to content

Commit

Permalink
#152: Extract trunction function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jenetics committed Nov 13, 2021
1 parent ab77f30 commit 6d3adc1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 30 deletions.
10 changes: 6 additions & 4 deletions jpx/src/main/java/io/jenetics/jpx/format/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static java.lang.Math.abs;
import static java.lang.Math.floor;
import static java.math.RoundingMode.DOWN;
import static java.math.RoundingMode.HALF_EVEN;
import static java.util.Objects.requireNonNull;

import java.math.RoundingMode;
Expand Down Expand Up @@ -60,12 +62,12 @@ abstract class Field implements Format {
void setPrefixSign(final boolean b) {
}

void setFormat(final NumberFormat format) {
_format.set(requireNonNull(format));
void setTruncate(final boolean b) {
_format.get().setRoundingMode(b ? DOWN : HALF_EVEN);
}

void setRoundingMode(final RoundingMode mode) {
_format.get().setRoundingMode(mode);
void setFormat(final NumberFormat format) {
_format.set(requireNonNull(format));
}

int getMinimumFractionDigits() {
Expand Down
6 changes: 0 additions & 6 deletions jpx/src/main/java/io/jenetics/jpx/format/LatitudeDegree.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package io.jenetics.jpx.format;

import static java.lang.Math.abs;
import static java.math.RoundingMode.DOWN;
import static java.math.RoundingMode.HALF_EVEN;

import java.text.DecimalFormat;
import java.text.ParsePosition;
Expand Down Expand Up @@ -54,10 +52,6 @@ boolean isPrefixSign() {
return _prefixSign;
}

void setTruncate(final boolean b) {
setRoundingMode(b ? DOWN : HALF_EVEN);
}

private boolean absolute = false;

void setAbsolute(final boolean b) {
Expand Down
7 changes: 0 additions & 7 deletions jpx/src/main/java/io/jenetics/jpx/format/LatitudeMinute.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package io.jenetics.jpx.format;

import static java.math.RoundingMode.DOWN;
import static java.math.RoundingMode.HALF_EVEN;

import java.text.ParsePosition;
import java.util.Optional;

Expand All @@ -41,10 +38,6 @@ char type() {
return 'M';
}

void setTruncate(final boolean b) {
setRoundingMode(b ? DOWN : HALF_EVEN);
}

@Override
public void parse(
final CharSequence in,
Expand Down
6 changes: 0 additions & 6 deletions jpx/src/main/java/io/jenetics/jpx/format/LongitudeDegree.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
package io.jenetics.jpx.format;

import static java.lang.Math.abs;
import static java.math.RoundingMode.DOWN;
import static java.math.RoundingMode.HALF_EVEN;

import java.text.DecimalFormat;
import java.text.ParsePosition;
Expand Down Expand Up @@ -58,10 +56,6 @@ boolean isPrefixSign() {
return prefixSign;
}

void setTruncate(final boolean b) {
setRoundingMode(b ? DOWN : HALF_EVEN);
}

void setAbsolute(final boolean b) {
absolute = b;
}
Expand Down
7 changes: 0 additions & 7 deletions jpx/src/main/java/io/jenetics/jpx/format/LongitudeMinute.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package io.jenetics.jpx.format;

import static java.math.RoundingMode.DOWN;
import static java.math.RoundingMode.HALF_EVEN;

import java.text.ParsePosition;
import java.util.Optional;

Expand All @@ -41,10 +38,6 @@ char type() {
return 'm';
}

void setTruncate(final boolean b) {
setRoundingMode(b ? DOWN : HALF_EVEN);
}

@Override
public void parse(
final CharSequence in,
Expand Down

0 comments on commit 6d3adc1

Please sign in to comment.