Example usage for java.lang Number intValue

List of usage examples for java.lang Number intValue

Introduction

In this page you can find the example usage for java.lang Number intValue.

Prototype

public abstract int intValue();

Source Link

Document

Returns the value of the specified number as an int .

Usage

From source file:com.prowidesoftware.swift.model.field.Field27.java

/**
 * Set the component2 from a Number object.
 * <br />// w  w  w  . j  a  va  2 s.com
 * <em>If the component being set is a fixed length number, the argument will not be 
 * padded.</em> It is recommended for these cases to use the setComponent2(String) 
 * method.
 * 
 * @see #setComponent2(String)
 *
 * @param component2 the Number with the component2 content to set
 */
public Field27 setComponent2(java.lang.Number component2) {
    if (component2 != null) {
        setComponent(2, "" + component2.intValue());
    }
    return this;
}

From source file:com.prowidesoftware.swift.model.field.Field27A.java

/**
 * Set the component1 from a Number object.
 * <br />/*from w  w  w .j a v a2 s  . c o  m*/
 * <em>If the component being set is a fixed length number, the argument will not be 
 * padded.</em> It is recommended for these cases to use the setComponent1(String) 
 * method.
 * 
 * @see #setComponent1(String)
 *
 * @param component1 the Number with the component1 content to set
 */
public Field27A setComponent1(java.lang.Number component1) {
    if (component1 != null) {
        setComponent(1, "" + component1.intValue());
    }
    return this;
}

From source file:com.prowidesoftware.swift.model.field.Field27A.java

/**
 * Set the component2 from a Number object.
 * <br />/* w  w w. ja v a 2 s .c om*/
 * <em>If the component being set is a fixed length number, the argument will not be 
 * padded.</em> It is recommended for these cases to use the setComponent2(String) 
 * method.
 * 
 * @see #setComponent2(String)
 *
 * @param component2 the Number with the component2 content to set
 */
public Field27A setComponent2(java.lang.Number component2) {
    if (component2 != null) {
        setComponent(2, "" + component2.intValue());
    }
    return this;
}

From source file:com.prowidesoftware.swift.model.field.Field39A.java

/**
 * Set the component1 from a Number object.
 * <br />/*  w w w .ja va2  s.c o  m*/
 * <em>If the component being set is a fixed length number, the argument will not be 
 * padded.</em> It is recommended for these cases to use the setComponent1(String) 
 * method.
 * 
 * @see #setComponent1(String)
 *
 * @param component1 the Number with the component1 content to set
 */
public Field39A setComponent1(java.lang.Number component1) {
    if (component1 != null) {
        setComponent(1, "" + component1.intValue());
    }
    return this;
}

From source file:com.prowidesoftware.swift.model.field.Field39A.java

/**
 * Set the component2 from a Number object.
 * <br />//w ww  .  j  av  a  2s . co  m
 * <em>If the component being set is a fixed length number, the argument will not be 
 * padded.</em> It is recommended for these cases to use the setComponent2(String) 
 * method.
 * 
 * @see #setComponent2(String)
 *
 * @param component2 the Number with the component2 content to set
 */
public Field39A setComponent2(java.lang.Number component2) {
    if (component2 != null) {
        setComponent(2, "" + component2.intValue());
    }
    return this;
}

From source file:moe.encode.airblock.commands.arguments.types.PrimitiveParser.java

@Override
public Object convert(Executor executor, ArgumentConverter parser, Type type, String value) {
    Class<?> cls = ReflectionUtils.toClass(type);
    if (ClassUtils.isPrimitiveWrapper(cls))
        cls = ClassUtils.wrapperToPrimitive(cls);

    if (cls.equals(boolean.class))
        return this.isTrue(executor, value);
    else if (cls.equals(char.class)) {
        if (value.length() > 0)
            throw new NumberFormatException("Character arguments cannot be longer than one characters");
        return value.charAt(0);
    }/* w ww.j  a v  a 2s.  c om*/

    // Get the locale of the user and get a number-format according to it.
    LocaleResolver resolver = TranslationManager.getResolver(executor);
    Locale locale;
    if (resolver != null)
        locale = resolver.getLocale();
    else
        locale = Locale.ENGLISH;

    NumberFormat nf = NumberFormat.getNumberInstance(locale);
    nf.setGroupingUsed(true);

    // Parse the value.
    Number result;
    try {
        result = nf.parse(value);
    } catch (ParseException e) {
        NumberFormatException nfe = new NumberFormatException("Invalid number");
        nfe.initCause(e);
        throw nfe;
    }

    // Returns the value in the correct type.
    if (cls.equals(int.class))
        return result.intValue();
    else if (cls.equals(float.class))
        return result.floatValue();
    else if (cls.equals(double.class))
        return result.doubleValue();
    else if (cls.equals(byte.class))
        return result.byteValue();
    else if (cls.equals(short.class))
        return result.shortValue();
    else if (cls.equals(long.class))
        return result.longValue();

    throw new NumberFormatException("Unknown primitive type.");
}

From source file:com.tresys.jalop.utils.jnltest.Config.ConfigTest.java

@Test
public void itemAsNumberWorks() throws Exception {
    Config cfg = new Config("/path/to/nothing");
    Number port = cfg.itemAsNumber("port", jsonCfg, true);

    assertEquals(1234, port.intValue());
}

From source file:org.archive.crawler.framework.CheckpointService.java

public synchronized void start() {
    if (isRunning) {
        return;/*from  w  w  w .  j  a v  a2 s  . co  m*/
    }
    // report if checkpoint incomplete/invalid
    if (getRecoveryCheckpoint() != null) {
        File cpDir = getRecoveryCheckpoint().getCheckpointDir().getFile();
        if (!Checkpoint.hasValidStamp(cpDir)) {
            LOGGER.severe(
                    "checkpoint '" + cpDir.getAbsolutePath() + "' missing validity stamp file; checkpoint data "
                            + "may be missing or otherwise corrupt.");
        }
        this.lastCheckpoint = getRecoveryCheckpoint();
        String serial = getRecoveryCheckpoint().getShortName().substring(2);
        try {
            Number lastCheckpointNumber = Checkpoint.INDEX_FORMAT.parse(serial);
            this.nextCheckpointNumber = lastCheckpointNumber.intValue() + 1;
        } catch (ParseException e) {
            LOGGER.warning("failed to parse serial from " + lastCheckpoint.getShortName() + " - " + e);
        }
    }
    this.isRunning = true;
    setupCheckpointTask();
}

From source file:com.amazonaws.metrics.internal.cloudwatch.PredefinedMetricTransformer.java

/**
 * Returns a list with a single metric datum for the specified retry or
 * request count predefined metric; or an empty list if there is none.
 * //from ww  w.  jav  a  2  s .  c  o  m
 * @param metricType
 *            must be either {@link Field#RequestCount} or
 *            {@link Field#RetryCount}; or else GIGO.
 */
protected List<MetricDatum> metricOfRequestOrRetryCount(Field metricType, Request<?> req, Object resp) {
    AWSRequestMetrics m = req.getAWSRequestMetrics();
    TimingInfo ti = m.getTimingInfo();
    // Always retrieve the request count even for retry which is equivalent
    // to the number of requests minus one.
    Number counter = ti.getCounter(Field.RequestCount.name());
    if (counter == null) {
        // this is possible if one of the request handlers screwed up
        return Collections.emptyList();
    }
    int requestCount = counter.intValue();
    if (requestCount < 1) {
        LogFactory.getLog(getClass()).warn("request count must be at least one");
        return Collections.emptyList();
    }
    final double count = metricType == Field.RequestCount ? requestCount : requestCount - 1 // retryCount = requestCount - 1
    ;
    if (count < 1) {
        return Collections.emptyList();
    } else {
        return Collections.singletonList(new MetricDatum().withMetricName(req.getServiceName())
                .withDimensions(
                        new Dimension().withName(Dimensions.MetricType.name()).withValue(metricType.name()))
                .withUnit(StandardUnit.Count).withValue(Double.valueOf(count)).withTimestamp(endTimestamp(ti)));
    }
}

From source file:com.prowidesoftware.swift.model.field.Field38B.java

/**
 * Set the component3 from a Number object.
 * <br />//from w w w.j  av a 2s. co  m
 * <em>If the component being set is a fixed length number, the argument will not be 
 * padded.</em> It is recommended for these cases to use the setComponent3(String) 
 * method.
 * 
 * @see #setComponent3(String)
 *
 * @param component3 the Number with the component3 content to set
 */
public Field38B setComponent3(java.lang.Number component3) {
    if (component3 != null) {
        setComponent(3, "" + component3.intValue());
    }
    return this;
}