Example usage for org.apache.commons.lang.math NumberUtils INTEGER_ZERO

List of usage examples for org.apache.commons.lang.math NumberUtils INTEGER_ZERO

Introduction

In this page you can find the example usage for org.apache.commons.lang.math NumberUtils INTEGER_ZERO.

Prototype

Integer INTEGER_ZERO

To view the source code for org.apache.commons.lang.math NumberUtils INTEGER_ZERO.

Click Source Link

Document

Reusable Integer constant for zero.

Usage

From source file:com.livinglogic.ul4.FunctionInt.java

public static Object call(Object obj) {
    if (obj instanceof String) {
        try {/*from   w w w. java 2  s . co  m*/
            return Integer.valueOf((String) obj);
        } catch (NumberFormatException ex1) {
            try {
                return Long.valueOf((String) obj);
            } catch (NumberFormatException ex2) {
                return new BigInteger((String) obj);
            }
        }
    } else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long)
        return obj;
    else if (obj instanceof BigInteger)
        return Utils.narrowBigInteger((BigInteger) obj);
    else if (obj instanceof Boolean)
        return ((Boolean) obj).booleanValue() ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO;
    else if (obj instanceof Float || obj instanceof Double)
        return ((Number) obj).intValue();
    else if (obj instanceof BigDecimal)
        return ((BigDecimal) obj).toBigInteger();
    throw new ArgumentTypeMismatchException("int({})", obj);
}

From source file:com.impetus.kundera.utils.NumericUtils.java

/**
 *  Check if zero//w w w  .j  a  v a  2  s .co  m
 * @param value        value string
 * @param valueClazz   value class 
 * @return             
 */
public static final boolean checkIfZero(String value, Class valueClazz) {
    boolean returnValue = false;
    if (value != null && NumberUtils.isNumber(value) && numberTypes.get(valueClazz) != null) {
        switch (numberTypes.get(valueClazz)) {

        case INTEGER:
            returnValue = Integer.parseInt(value) == (NumberUtils.INTEGER_ZERO);
            break;

        case FLOAT:
            returnValue = Float.parseFloat(value) == (NumberUtils.FLOAT_ZERO);
            break;

        case LONG:
            returnValue = Long.parseLong(value) == (NumberUtils.LONG_ZERO);
            break;

        case BIGDECIMAL:
            returnValue = new BigDecimal(value) == (BigDecimal.ZERO);
            break;

        case BIGINTEGER:
            returnValue = new BigInteger(value) == (BigInteger.ZERO);
            break;

        case SHORT:
            returnValue = new Short(value) == (NumberUtils.SHORT_ZERO);
            break;
        }
    }

    return returnValue;
}

From source file:net.sf.reportengine.core.calc.TestCalculators.java

@Test
public void testCountCalculator() {
    CountGroupCalculator calculator = new CountGroupCalculator();
    assertTrue(calculator.init() instanceof DefaultCalcIntermResult);
    assertTrue(calculator.init().getResult() instanceof Integer);
    assertEquals(calculator.init().getResult(), NumberUtils.INTEGER_ZERO);

    DefaultCalcIntermResult<Integer> testIntermResult = new DefaultCalcIntermResult<Integer>(0);
    DefaultCalcIntermResult<Integer> newResult = calculator.compute(testIntermResult, "first object");

    assertNotNull(newResult);//from  w  ww. ja  va  2 s  . co m
    assertNotNull(newResult.getResult());
    assertEquals(newResult.getResult(), NumberUtils.INTEGER_ONE);

    testIntermResult = new DefaultCalcIntermResult<Integer>(Integer.valueOf(7));
    newResult = calculator.compute(testIntermResult, "another object here");

    assertNotNull(newResult);
    assertNotNull(newResult.getResult());
    assertEquals(newResult.getResult(), Integer.valueOf(8));

}

From source file:net.sf.reportengine.core.calc.CountGroupCalculator.java

/**
 * initializes the counter to zero/*w w w.j  a v  a 2 s.  c o m*/
 */
public DefaultCalcIntermResult<Integer> init() {
    return new DefaultCalcIntermResult<Integer>(NumberUtils.INTEGER_ZERO);
}

From source file:net.sf.reportengine.util.TestCalculatorIntermResultMatrix.java

/**
 * Test method for {@link net.sf.reportengine.util.CalculatorIntermResultsMatrix#initRow(int)}.
 */// w  w  w .ja v a 2s .co  m
@Test
public final void testInitRow() {
    classUnderTest = new CalculatorIntermResultsMatrix(1, TEST_DATA_COLUMNS);

    //call the method under test
    classUnderTest.initRow(0);

    //check the interm results matrix
    Assert.assertNotNull(classUnderTest);
    Assert.assertNotNull(classUnderTest.getIntermResultsMatrix());
    Assert.assertEquals(classUnderTest.getIntermResultsMatrix().length, 1);

    //the first row should be re-initialized
    CalcIntermResult[] row1 = classUnderTest.getIntermResultsMatrix()[0];
    Assert.assertNotNull(row1);
    Assert.assertEquals(row1.length, 2);
    Assert.assertEquals(row1[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertEquals(row1[1].getResult(), BigDecimal.ZERO);
}

From source file:edu.utah.further.core.math.schedule.JobSchedulerGraphImpl.java

@Override
public void onSchedulerStart() {
    final Collection<V> dependents = graph.vertexSet();
    if (dependents != null) {
        boolean atLeastOneJobStarted = false;
        // Encountered a relevant event
        for (final V dependent : dependents) {
            // There must be at least one job which can be started when the schedule
            // starts.
            if (NumberUtils.INTEGER_ZERO.equals(remainingDependencies.get(dependent))) {
                startJob(dependent);//from   w ww. jav  a  2 s.c om
                atLeastOneJobStarted = true;
            }
        }

        // Ensure that a job is started or nothing will happen
        if (!atLeastOneJobStarted) {
            throw new IllegalStateException(
                    "Job scheduling graph is unresolvable, there are no jobs which can start. "
                            + "All jobs have dependencies which must be started first. Expected at least one job with no dependencies that could start");
        }

    } else {
        throw new IllegalStateException(
                "Expected job scheduler graph with dependencies but graph has no dependencies (vertices)");
    }
}

From source file:net.sf.reportengine.util.TestCalculatorIntermResultMatrix.java

@Test
public void testInitFirstXRows() {
    classUnderTest = new CalculatorIntermResultsMatrix(3, TEST_DATA_COLUMNS);
    classUnderTest.initAll();/*  ww  w .  j  a v  a  2s  .  c  o m*/

    classUnderTest.addValuesToEachRow(new NewRowEvent(TEST_VALUES));

    //reinit the first two columns
    classUnderTest.initFirstXRows(2);

    //check the interm results matrix
    Assert.assertNotNull(classUnderTest);
    Assert.assertNotNull(classUnderTest.getIntermResultsMatrix());
    Assert.assertEquals(classUnderTest.getIntermResultsMatrix().length, 3);

    //the first row should be re-initialized
    CalcIntermResult[] row1 = classUnderTest.getIntermResultsMatrix()[0];
    Assert.assertNotNull(row1);
    Assert.assertEquals(row1.length, 2);
    Assert.assertEquals(row1[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertEquals(row1[1].getResult(), BigDecimal.ZERO);

    //the second row should be also re-initialized
    CalcIntermResult[] row2 = classUnderTest.getIntermResultsMatrix()[1];
    Assert.assertNotNull(row2);
    Assert.assertEquals(row2.length, 2);
    Assert.assertEquals(row2[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertEquals(row2[1].getResult(), BigDecimal.ZERO);

    //the third row should not be re-initialized
    CalcIntermResult[] row3 = classUnderTest.getIntermResultsMatrix()[2];
    Assert.assertNotNull(row3);
    Assert.assertEquals(row3.length, 2);
    Assert.assertNotSame(row3[0].getResult(), NumberUtils.INTEGER_ZERO);
    Assert.assertNotSame(row3[1].getResult(), BigDecimal.ZERO);
}

From source file:edu.utah.further.core.math.schedule.JobSchedulerGraphImpl.java

@Override
public void onJobAfterCompleted(final V job) {
    // Update tracking lists
    completedJobs.add(job);/*  w  ww .  j  av  a 2 s. c  o  m*/

    // Remove dependency of job on its dependents and start those that have no
    // remaining dependencies
    final Collection<V> dependents = getDependents(job);
    if (dependents != null) {
        // Encountered a relevant event
        for (final V dependent : dependents) {
            if (job != null) {
                removeDependency(dependent);
            }
            if (NumberUtils.INTEGER_ZERO.equals(remainingDependencies.get(dependent))) {
                startJob(dependent);
            }
        }
    }
}

From source file:jk.wrapper.common.util.BooleanUtils.java

/**
 * <p>Converts a boolean to an Integer using the convention that
 * <code>zero</code> is <code>false</code>.</p>
 * //from  w w w.  j av a2s.co  m
 * <pre>
 *   BooleanUtils.toIntegerObject(true)  = new Integer(1)
 *   BooleanUtils.toIntegerObject(false) = new Integer(0)
 * </pre>
 *
 * @param bool  the boolean to convert
 * @return one if <code>true</code>, zero if <code>false</code>
 */
public static Integer toIntegerObject(boolean bool) {
    return bool ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO;
}

From source file:jk.wrapper.common.util.BooleanUtils.java

/**
 * <p>Converts a Boolean to a Integer using the convention that
 * <code>zero</code> is <code>false</code>.</p>
 *
 * <p><code>null</code> will be converted to <code>null</code>.</p>
 *
 * <pre>/*from w ww.ja  va  2 s  . co  m*/
 *   BooleanUtils.toIntegerObject(Boolean.TRUE)  = new Integer(1)
 *   BooleanUtils.toIntegerObject(Boolean.FALSE) = new Integer(0)
 * </pre>
 *
 * @param bool  the Boolean to convert
 * @return one if Boolean.TRUE, zero if Boolean.FALSE, <code>null</code> if <code>null</code>
 */
public static Integer toIntegerObject(Boolean bool) {
    if (bool == null) {
        return null;
    }
    return bool.booleanValue() ? NumberUtils.INTEGER_ONE : NumberUtils.INTEGER_ZERO;
}