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.Field330.java

/**
 * Set the component2 from a Number object.
 * <br />/*from  w  ww.jav  a2s  .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 Field330 setComponent2(java.lang.Number component2) {
    if (component2 != null) {
        setComponent(2, "" + component2.intValue());
    }
    return this;
}

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

/**
 * Set the component3 from a Number object.
 * <br />//w w w .  j a va2  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 setComponent3(String) 
 * method.
 * 
 * @see #setComponent3(String)
 *
 * @param component3 the Number with the component3 content to set
 */
public Field330 setComponent3(java.lang.Number component3) {
    if (component3 != null) {
        setComponent(3, "" + component3.intValue());
    }
    return this;
}

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

/**
 * Set the component4 from a Number object.
 * <br />/* 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 setComponent4(String) 
 * method.
 * 
 * @see #setComponent4(String)
 *
 * @param component4 the Number with the component4 content to set
 */
public Field330 setComponent4(java.lang.Number component4) {
    if (component4 != null) {
        setComponent(4, "" + component4.intValue());
    }
    return this;
}

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

/**
 * Set the component5 from a Number object.
 * <br />/*from w w w .  j  av a2s.  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 setComponent5(String) 
 * method.
 * 
 * @see #setComponent5(String)
 *
 * @param component5 the Number with the component5 content to set
 */
public Field330 setComponent5(java.lang.Number component5) {
    if (component5 != null) {
        setComponent(5, "" + component5.intValue());
    }
    return this;
}

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

/**
 * Set the component6 from a Number object.
 * <br />//from  w w w . j  a va2 s  . 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 setComponent6(String) 
 * method.
 * 
 * @see #setComponent6(String)
 *
 * @param component6 the Number with the component6 content to set
 */
public Field330 setComponent6(java.lang.Number component6) {
    if (component6 != null) {
        setComponent(6, "" + component6.intValue());
    }
    return this;
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.DlmsHelperService.java

public TransportServiceType readTransportServiceType(final DataObject resultData, final String description)
        throws ProtocolAdapterException {
    final Number number = this.readNumber(resultData, description, "Enum");
    if (number == null) {
        return null;
    }// w w  w .j  av a  2  s. co  m
    final int enumValue = number.intValue();
    final TransportServiceType transportService = this.getTransportServiceTypeForEnumValue(enumValue);
    if (transportService == null) {
        LOGGER.error("Unexpected Enum value for TransportServiceType: {}", enumValue);
        throw new ProtocolAdapterException("Unknown Enum value for TransportServiceType: " + enumValue);
    }
    return transportService;
}

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

/**
 * Set the component4 from a Number object.
 * <br />/*from  w  ww  . j av  a2s  .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 setComponent4(String) 
 * method.
 * 
 * @see #setComponent4(String)
 *
 * @param component4 the Number with the component4 content to set
 */
public Field98E setComponent4(java.lang.Number component4) {
    if (component4 != null) {
        setComponent(4, "" + component4.intValue());
    }
    return this;
}

From source file:com.gst.infrastructure.core.serialization.JsonParserHelper.java

public Integer convertToInteger(final String numericalValueFormatted, final String parameterName,
        final Locale clientApplicationLocale) {

    if (clientApplicationLocale == null) {

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        final String defaultMessage = new StringBuilder(
                "The parameter '" + parameterName + "' requires a 'locale' parameter to be passed with it.")
                        .toString();//from   w w w . java  2s .  co m
        final ApiParameterError error = ApiParameterError
                .parameterError("validation.msg.missing.locale.parameter", defaultMessage, parameterName);
        dataValidationErrors.add(error);

        throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                "Validation errors exist.", dataValidationErrors);
    }

    try {
        Integer number = null;

        if (StringUtils.isNotBlank(numericalValueFormatted)) {

            String source = numericalValueFormatted.trim();

            final NumberFormat format = NumberFormat.getInstance(clientApplicationLocale);
            final DecimalFormat df = (DecimalFormat) format;
            final DecimalFormatSymbols symbols = df.getDecimalFormatSymbols();
            df.setParseBigDecimal(true);

            // http://bugs.sun.com/view_bug.do?bug_id=4510618
            final char groupingSeparator = symbols.getGroupingSeparator();
            if (groupingSeparator == '\u00a0') {
                source = source.replaceAll(" ", Character.toString('\u00a0'));
            }

            final Number parsedNumber = df.parse(source);

            final double parsedNumberDouble = parsedNumber.doubleValue();
            final int parsedNumberInteger = parsedNumber.intValue();

            if (source.contains(Character.toString(symbols.getDecimalSeparator()))) {
                throw new ParseException(source, 0);
            }

            if (!Double.valueOf(parsedNumberDouble)
                    .equals(Double.valueOf(Integer.valueOf(parsedNumberInteger)))) {
                throw new ParseException(source, 0);
            }

            number = parsedNumber.intValue();
        }

        return number;
    } catch (final ParseException e) {

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        final ApiParameterError error = ApiParameterError.parameterError(
                "validation.msg.invalid.integer.format",
                "The parameter " + parameterName + " has value: " + numericalValueFormatted
                        + " which is invalid integer value for provided locale of ["
                        + clientApplicationLocale.toString() + "].",
                parameterName, numericalValueFormatted, clientApplicationLocale);
        error.setValue(numericalValueFormatted);
        dataValidationErrors.add(error);

        throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
                "Validation errors exist.", dataValidationErrors);
    }
}

From source file:Unsigned.java

/**
 * Parse a binary number into a Number object. If up to 8 bits are parsed,
 * returns a Byte. If more than 8 and up to 16 bits are parsed, return a
 * Short. If more than 16 and up to 32 bits are parsed, return an Integer.
 * If more than 32 and up to 64 bits are parsed, return a Long.
 * // w ww .  java2s  .  co  m
 * @param text
 *            a binary number
 * @param parsePosition
 *            position to start parsing from
 * @return return an integer form of Number object if parse is successful;
 *         <CODE>null</CODE> otherwise
 * 
 * @since 1.0
 */
public Number parse(String text, ParsePosition parsePosition) {
    boolean skipWhitespace = true;
    int startIndex, bits;

    // remove whitespace
    StringCharacterIterator iter = new StringCharacterIterator(text, parsePosition.getIndex());
    for (char c = iter.current(); c != CharacterIterator.DONE; c = iter.next()) {
        if (skipWhitespace && Character.isWhitespace(c)) {
            // skip whitespace
            continue;
        }
    }
    parsePosition.setIndex(iter.getIndex());

    startIndex = parsePosition.getIndex();
    Number result = (Number) parseObject(text, parsePosition);

    if (result == null) {
        return (result);
    }

    bits = parsePosition.getIndex() - startIndex;
    if (bits <= 8) {
        result = new Byte(result.byteValue());
    } else if (bits <= 16) {
        result = new Short(result.shortValue());
    } else if (bits <= 32) {
        result = new Integer(result.intValue());
    } else if (bits <= 64) {
        result = new Long(result.longValue());
    }
    return (result);
}

From source file:com.vuze.plugin.azVPN_PIA.Checker.java

private boolean checkStatusFileForPort(File pathPIAManagerData, StringBuilder sReply) {
    // Read the status_file for forwarding port

    boolean gotValidPort = false;

    File fileStatus = new File(pathPIAManagerData, "status_file.txt");
    if (!fileStatus.isFile() || !fileStatus.canRead()) {
        return false;
    }//from   w ww.j a v a2 s.c  om
    try {
        byte[] statusFileBytes = FileUtil.readFileAsByteArray(fileStatus);

        if (statusFileBytes.length > STATUS_FILE_PORT_INDEX && statusFileBytes[STATUS_FILE_PORT_INDEX] == '{') {
            int endPos = STATUS_FILE_PORT_INDEX;
            while (endPos < statusFileBytes.length && statusFileBytes[endPos] > 1) {
                endPos++;
            }
            boolean gotPort = false;

            String jsonPort = new String(statusFileBytes, STATUS_FILE_PORT_INDEX,
                    endPos - STATUS_FILE_PORT_INDEX);
            Map<?, ?> decodeJSON = JSONUtils.decodeJSON(jsonPort);
            if (decodeJSON.containsKey("single")) {
                Object oPort = decodeJSON.get("single");
                if (oPort == null) {
                    gotPort = true;

                    String user = config.getPluginStringParameter(PluginPIA.CONFIG_USER);
                    byte[] pass = config.getPluginByteParameter(PluginPIA.CONFIG_P);

                    if (user == null || user.length() == 0 || pass == null || pass.length == 0) {

                        boolean portForwardEnabled = false;
                        File fileSettings = new File(pathPIAManagerData, "settings.json");
                        String settingsString = FileUtil.readFileAsString(fileSettings, -1);
                        Map<?, ?> mapSettings = JSONUtils.decodeJSON(settingsString);
                        if (mapSettings != null && mapSettings.containsKey("portforward")) {
                            portForwardEnabled = (Boolean) mapSettings.get("portforward");
                        }

                        addReply(sReply, CHAR_WARN,
                                portForwardEnabled ? "pia.no.forwarding.port" : "pia.no.port.config");
                    }

                }
                if (oPort instanceof Number) {
                    gotPort = true;
                    gotValidPort = true;

                    Number nPort = (Number) oPort;
                    int port = nPort.intValue();

                    addReply(sReply, CHAR_GOOD, "pia.port.in.manager", new String[] { Integer.toString(port) });

                    changePort(port, sReply);
                }
            }

            if (!gotPort) {
                addReply(sReply, CHAR_BAD, "pia.invalid.port.status_file", new String[] { jsonPort });
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return gotValidPort;
}