Skip to content

Commit

Permalink
yegor256#459 NumberOf
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 8, 2017
1 parent e263590 commit f806833
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 394 deletions.
74 changes: 0 additions & 74 deletions src/main/java/org/cactoos/scalar/DoubleOf.java

This file was deleted.

69 changes: 0 additions & 69 deletions src/main/java/org/cactoos/scalar/IntOf.java

This file was deleted.

69 changes: 0 additions & 69 deletions src/main/java/org/cactoos/scalar/LongOf.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.cactoos.scalar;

import java.io.IOException;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.text.TextOf;
Expand All @@ -42,33 +41,93 @@
* @version $Id$
* @since 0.2
*/
public final class FloatOf implements Scalar<Float> {
public final class NumberOf extends Number implements Scalar<Number> {

/**
* Source text.
* Serialization marker.
*/
private final Text origin;
private static final long serialVersionUID = -1924406337256921883L;

/**
* The LONG number.
*/
private final Scalar<Long> lnum;

/**
* The INT number.
*/
private final Scalar<Integer> inum;

/**
* The FLOAT number.
*/
private final Scalar<Float> fnum;

/**
* The DOUBLE number.
*/
private final Scalar<Double> dnum;

/**
* Ctor.
*
* @param string Number-string
* @param txt Number-string
*/
public FloatOf(final String string) {
this(new TextOf(string));
public NumberOf(final String txt) {
this(new TextOf(txt));
}

/**
* Ctor.
*
* @param text Number-text
*/
public FloatOf(final Text text) {
this.origin = text;
public NumberOf(final Text text) {
super();
this.lnum = new SyncScalar<>(
new StickyScalar<>(
() -> Long.parseLong(text.asString())
)
);
this.inum = new SyncScalar<>(
new StickyScalar<>(
() -> Integer.parseInt(text.asString())
)
);
this.fnum = new SyncScalar<>(
new StickyScalar<>(
() -> Float.parseFloat(text.asString())
)
);
this.dnum = new SyncScalar<>(
new StickyScalar<>(
() -> Double.parseDouble(text.asString())
)
);
}

@Override
public Number value() {
return this;
}

@Override
public int intValue() {
return new UncheckedScalar<>(this.inum).value();
}

@Override
public long longValue() {
return new UncheckedScalar<>(this.lnum).value();
}

@Override
public float floatValue() {
return new UncheckedScalar<>(this.fnum).value();
}

@Override
public Float value() throws IOException {
return Float.valueOf(this.origin.asString());
public double doubleValue() {
return new UncheckedScalar<>(this.dnum).value();
}
}
55 changes: 0 additions & 55 deletions src/test/java/org/cactoos/scalar/FloatOfTest.java

This file was deleted.

Loading

0 comments on commit f806833

Please sign in to comment.