Skip to content

Commit

Permalink
#172: Max and Min extends Number
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciofx committed Jun 28, 2017
1 parent 7a25baa commit 38919dc
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
49 changes: 48 additions & 1 deletion src/main/java/org/cactoos/math/Max.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* @version $Id$
* @since 0.7
*/
public final class Max implements Scalar<Number> {
@SuppressWarnings("serial")
public final class Max extends Number implements Scalar<Number> {

/**
* Numbers.
Expand All @@ -46,6 +47,7 @@ public final class Max implements Scalar<Number> {
* @param numbers The numbers
*/
public Max(final Number... numbers) {
super();
this.numbers = numbers;
}

Expand All @@ -59,4 +61,49 @@ public Number asValue() throws Exception {
}
return max;
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public int intValue() {
try {
return this.asValue().intValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public long longValue() {
try {
return this.asValue().longValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public float floatValue() {
try {
return this.asValue().floatValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public double doubleValue() {
try {
return this.asValue().doubleValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

}
49 changes: 48 additions & 1 deletion src/main/java/org/cactoos/math/Min.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
* @version $Id$
* @since 0.7
*/
public final class Min implements Scalar<Number> {
@SuppressWarnings("serial")
public final class Min extends Number implements Scalar<Number> {

/**
* Numbers.
Expand All @@ -46,6 +47,7 @@ public final class Min implements Scalar<Number> {
* @param numbers The numbers
*/
public Min(final Number... numbers) {
super();
this.numbers = numbers;
}

Expand All @@ -59,4 +61,49 @@ public Number asValue() throws Exception {
}
return min;
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public int intValue() {
try {
return this.asValue().intValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public long longValue() {
try {
return this.asValue().longValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public float floatValue() {
try {
return this.asValue().floatValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

@Override
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public double doubleValue() {
try {
return this.asValue().doubleValue();
// @checkstyle IllegalCatchCheck (1 line)
} catch (final Exception ex) {
throw new IllegalStateException(ex);
}
}

}

0 comments on commit 38919dc

Please sign in to comment.