Example usage for java.lang Integer decode

List of usage examples for java.lang Integer decode

Introduction

In this page you can find the example usage for java.lang Integer decode.

Prototype

public static Integer decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into an Integer .

Usage

From source file:org.pentaho.reporting.libraries.fonts.encoding.generator.EncodingGenerator.java

public void generatedFormatA(final Properties specifications, final BufferedReader input,
        final OutputStream output) throws IOException {
    if (input == null) {
        throw new NullPointerException();
    }//from w  w  w . ja  va 2s. c  o  m
    if (output == null) {
        throw new NullPointerException();
    }
    if (specifications == null) {
        throw new NullPointerException();
    }

    final Integer[] data = new Integer[256];
    data[0] = ZERO;

    String s = input.readLine();
    while (s != null) {
        if (s.length() > 0 && s.charAt(0) == '#') {
            s = input.readLine();
            continue;
        }

        final StringTokenizer strtok = new StringTokenizer(s);
        if (strtok.hasMoreTokens() == false) {
            s = input.readLine();
            continue;
        }
        final String sourceChar = strtok.nextToken().trim();
        if (sourceChar.length() == 0) {
            s = input.readLine();
            continue;
        }

        final Integer sourceVal = Integer.decode(sourceChar);
        if (strtok.hasMoreTokens()) {
            final String targetChar = strtok.nextToken();
            if ((targetChar.length() > 0 && targetChar.charAt(0) == '#') == false) {
                data[sourceVal.intValue()] = Integer.decode(targetChar);
            }
        }

        s = input.readLine();
    }

    final int[] indices = new int[256];
    final int[] values = new int[256];

    int index = 0;
    int prevIdx = 0;
    for (int i = 1; i < data.length; i++) {
        final Integer integer = data[i];
        if (integer == null) {
            // no entry ... this means, we use the standard mapping ..
            continue;
        }

        final Integer prev = data[prevIdx];
        values[index] = integer.intValue() - prev.intValue();
        indices[index] = i - prevIdx;

        prevIdx = i;
        index += 1;
    }

    final ObjectOutputStream oout = new ObjectOutputStream(output);
    oout.writeObject(new External8BitEncodingData(indices, values));
    oout.flush();
}

From source file:org.qxsched.doc.afp.AfpStructuredFieldDefinitions.java

private AfpStructuredFieldDefinitions() throws AfpException {

    // Get resource
    String resourceName = AfpStructuredFieldDefinitions.class.getName().replace('.', '/') + ".properties";
    if (LOG.isTraceEnabled()) {
        LOG.trace("Loading resource " + resourceName);
    }/*www .  j av  a 2s.  co  m*/

    // Map properties object
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);
    Properties props = new Properties();
    try {
        props.load(is);
    } catch (IOException e) {
        throw new AfpException(e.getMessage(), e);
    }

    // Fill maps
    Set<Object> keys = props.keySet();
    for (Object keyObj : keys) {

        // Cast key
        String key = (String) keyObj;
        String keyLc = key.toLowerCase();

        // Check key
        if (!keyLc.matches("^0x[0-9a-f]+$")) {
            LOG.error("Illegal key '" + key + "' in resource " + resourceName);
        }

        // Make integer key
        Integer keyInt = Integer.decode(key);

        // Get value and split
        String val = props.getProperty(key);
        String[] valSplit = val.split("\\W+", 2);

        // Make abbreviation mapping
        code2abbrev.put(keyInt, valSplit[0].toUpperCase());
        abbrev2code.put(valSplit[0].toUpperCase(), keyInt);

        // Make description string
        if (valSplit.length > 1) {
            code2desc.put(keyInt, valSplit[1]);
        }
    }

    // Make begin/end maps
    // Loop through codes
    Set<Integer> codeSet = code2abbrev.keySet();
    for (Integer codeBegin : codeSet) {

        // Get abbreviation and description
        String abbrev = code2abbrev.get(codeBegin);
        String desc = code2desc.get(codeBegin);

        // Do nothing if not begin
        if (!desc.toLowerCase().startsWith("begin")) {
            continue;
        }

        // Make "end" abbreviation
        String abbrevEnd = abbrev.replaceFirst("^[A-Z]", "E");
        abbrevEnd = abbrevEnd.replaceFirst("^[a-z]", "e");

        // Throw exception if "end" abbreviation does not exist
        Integer codeEnd = abbrev2code.get(abbrevEnd);
        if (codeEnd == null) {
            throw new AfpException("Did not find \"end\" abbreviation for \"begin\" abbreviation " + abbrev
                    + " (" + desc + ")");
        }
        if (LOG.isTraceEnabled()) {
            LOG.trace("code-bigin/code-end:" + hexString(codeBegin, 6) + "/" + hexString(codeEnd, 6));
        }

        // Assert begin2end
        if (begin2end.containsKey(codeBegin)) {
            throw new AfpException("Unexpected state. Code " + hexString(codeBegin, 6)
                    + " defined miltiple times in begin-to-end map.");
        }
        begin2end.put(codeBegin, codeEnd);

        // Assert end2begin
        Integer codeBeginError = end2begin.get(codeEnd);
        if (codeBeginError != null) {

            // Get abbreviations
            String abbrevBegin = code2abbrev.get(codeBegin);
            String abbrevBeginError = code2abbrev.get(codeBeginError);

            throw new AfpException("End-code '" + abbrevEnd + "'/" + hexString(codeEnd, 1)
                    + " matches multiple begin-codes: '" + abbrevBeginError + "'/"
                    + hexString(codeBeginError, 6) + " and '" + abbrevBegin + "'/" + hexString(codeBegin, 6));
        }
        end2begin.put(codeEnd, codeBegin);
    }
}

From source file:NumberUtils.java

/**
 * Parse the given text into a number instance of the given target class,
 * using the corresponding default <code>decode</code> methods. Trims the
 * input <code>String</code> before attempting to parse the number. Supports
 * numbers in hex format (with leading 0x) and in octal format (with leading 0).
 * @param text the text to convert/* w  ww  .  j  a v a 2  s  .  c  om*/
 * @param targetClass the target class to parse into
 * @return the parsed number
 * @throws IllegalArgumentException if the target class is not supported
 * (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte#decode
 * @see java.lang.Short#decode
 * @see java.lang.Integer#decode
 * @see java.lang.Long#decode
 * @see #decodeBigInteger(String)
 * @see java.lang.Float#valueOf
 * @see java.lang.Double#valueOf
 * @see java.math.BigDecimal#BigDecimal(String)
 */
public static Number parseNumber(String text, Class targetClass) {

    String trimmed = text.trim();

    if (targetClass.equals(Byte.class)) {
        return Byte.decode(trimmed);
    } else if (targetClass.equals(Short.class)) {
        return Short.decode(trimmed);
    } else if (targetClass.equals(Integer.class)) {
        return Integer.decode(trimmed);
    } else if (targetClass.equals(Long.class)) {
        return Long.decode(trimmed);
    } else if (targetClass.equals(BigInteger.class)) {
        return decodeBigInteger(trimmed);
    } else if (targetClass.equals(Float.class)) {
        return Float.valueOf(trimmed);
    } else if (targetClass.equals(Double.class)) {
        return Double.valueOf(trimmed);
    } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
        return new BigDecimal(trimmed);
    } else {
        throw new IllegalArgumentException(
                "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]");
    }
}

From source file:com.aurel.track.fieldType.bulkSetters.ItemPickerBulkSetter.java

@Override
public Object fromDisplayString(Map<String, String> displayStringMap, Locale locale) {
    if (displayStringMap == null) {
        return null;
    }/*from   w w  w .  ja  va2  s  . c o m*/
    switch (getRelation()) {
    case BulkRelations.SET_TO:
    case BulkRelations.ADD_ITEMS:
    case BulkRelations.REMOVE_ITEMS:
        String displayString = displayStringMap.get(getKeyPrefix());
        if (displayString != null) {
            try {
                return Integer.decode(displayString);
            } catch (NumberFormatException ex) {
                LOGGER.info("Parsing the parentID " + displayString + " failed with ");
            }
        }
    }
    return null;
}

From source file:org.jbpm.formModeler.core.processing.formProcessing.Functions.java

public Date getDateFromFields(String sDay, String sMonth, String sYear) {
    int day = Integer.decode(sDay).intValue();
    int month = Integer.decode(sMonth).intValue();
    int year = Integer.decode(sYear).intValue();
    GregorianCalendar gc = new GregorianCalendar(year, month, day);
    return gc.getTime();
}

From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.TranscodeRequest.java

public int getMinimumAudioPid() {
    int minimum = Integer.MAX_VALUE;
    for (String pid : audioPids) {
        Integer newPid = Integer.decode(pid);
        minimum = Math.min(newPid, minimum);
    }//  www .j ava  2s  . c  o  m
    return minimum;
}

From source file:org.apache.jackrabbit.core.persistence.bundle.BundleFsPersistenceManager.java

/**
 * Sets the block size of the blob fs and controls how blobs are handled.
 * <br>//  w  w  w  .j a va2  s  . c  o  m
 * If the size is 0, the blobs are stored within the workspace's physical filesystem.
 * <br>
 * Otherwise, the blobs are stored within the item filesystem.
 * <br>
 * Please note that not all binary properties are considered as blobs. They
 * are only stored in the respective blob store, if their size exceeds
 * {@link #getMinBlobSize()}.
 *
 * @param size the block size
 */
public void setBlobFSBlockSize(String size) {
    this.blobFSBlockSize = Integer.decode(size).intValue();
}

From source file:it.cilea.osd.jdyna.web.controller.PropertiesDefinitionController.java

private ModelAndView handleDelete(HttpServletRequest request) {
    Map<String, Object> model = new HashMap<String, Object>();
    String paramOTipologiaProprietaId = request.getParameter("id");
    Integer tipologiaProprietaId = Integer.decode(paramOTipologiaProprietaId);

    try {//from w w w  .j  a v  a2 s .c o  m

        TP tip = applicationService.get(targetModel, tipologiaProprietaId);
        //cancello tutte le proprieta' salvate in passato
        applicationService.deleteAllProprietaByTipologiaProprieta(targetModel, tip);

        //cancello la tipologia di proprieta
        applicationService.delete(targetModel, tipologiaProprietaId);
    } catch (Exception ecc) {

        return new ModelAndView(getErrorView(), model);
    }

    saveMessage(request, getText("action.tipologiaProprietaOpera.deleted", request.getLocale()));

    return new ModelAndView(getListView(), model);
}

From source file:fr.gael.dhus.sync.impl.ODataUserSynchronizer.java

/**
 * Creates a new UserSynchronizer.//ww  w  .  j  a v  a 2 s . c  om
 *
 * @param sc configuration for this synchronizer.
 *
 * @throws java.io.IOException
 * @throws org.apache.olingo.odata2.api.exception.ODataException
 */
public ODataUserSynchronizer(SynchronizerConf sc) throws IOException, ODataException {
    super(sc);
    // Checks if required configuration is set
    String urilit = sc.getConfig("service_uri");
    serviceUser = sc.getConfig("service_username");
    servicePass = sc.getConfig("service_password");

    if (urilit == null || urilit.isEmpty()) {
        throw new IllegalStateException("`service_uri` is not set");
    }

    try {
        client = new ODataClient(urilit, serviceUser, servicePass);
    } catch (URISyntaxException e) {
        throw new IllegalStateException("`service_uri` is malformed");
    }

    String skip = sc.getConfig("skip");
    if (skip != null && !skip.isEmpty()) {
        this.skip = Integer.parseInt(skip);
    } else {
        this.skip = 0;
    }

    String page_size = sc.getConfig("page_size");
    if (page_size != null && !page_size.isEmpty()) {
        pageSize = Integer.decode(page_size);
    } else {
        pageSize = 500;
    }

    String cfgForce = sc.getConfig("force");
    if (cfgForce != null && !cfgForce.isEmpty()) {
        force = Boolean.parseBoolean(cfgForce);
    } else {
        force = false;
    }
}

From source file:uni.bielefeld.cmg.sparkhit.util.ParameterForConverter.java

public DefaultParam importCommandLine() {

    /* Assigning Parameter ID to an ascending number */
    putParameterID();/*from  ww  w  .  j  a  v a2  s.c  o m*/

    /* Assigning parameter descriptions to each parameter ID */
    addParameterInfo();

    /* need a Object parser of PosixParser class for the function parse of CommandLine class */
    PosixParser parser = new PosixParser();

    /* print out help information */
    HelpParam help = new HelpParam(parameter, parameterMap);

    /* check each parameter for assignment */
    try {
        long input_limit = -1;
        int threads = Runtime.getRuntime().availableProcessors();

        /* Set Object cl of CommandLine class for Parameter storage */
        CommandLine cl = parser.parse(parameter, arguments, true);
        if (cl.hasOption(HELP)) {
            help.printConverterHelp();
            System.exit(0);
        }

        if (cl.hasOption(HELP2)) {
            help.printConverterHelp();
            System.exit(0);
        }

        if (cl.hasOption(VERSION)) {
            System.exit(0);
        }

        /* Checking all parameters */

        String value;

        if ((value = cl.getOptionValue(PARTITIONS)) != null) {
            param.partitions = Integer.decode(value);
        }

        if ((value = cl.getOptionValue(INPUT_FASTQ)) != null) {
            param.inputFqPath = value;
        } else {
            help.printConverterHelp();
            System.exit(0);
            //                throw new IOException("Input file not specified.\nUse -help for list of options");
        }

        if ((value = cl.getOptionValue(OUTPUT_FORMAT)) != null) {
            param.outputformat = Integer.decode(value);
        }

        /* not applicable for HDFS and S3 */
        /* using TextFileBufferInput for such purpose */
        //         File inputFastq = new File(param.inputFqPath).getAbsoluteFile();
        //         if (!inputFastq.exists()){
        //            err.println("Input query file not found.");
        //            return;
        //i         }

        if ((value = cl.getOptionValue(OUTPUT_LINE)) != null) {
            param.outputPath = value;
        } else {
            info.readMessage("Output file not set of -outfile options");
            info.screenDump();
        }

        File outfile = new File(param.outputPath).getAbsoluteFile();
        if (outfile.exists()) {
            info.readParagraphedMessages(
                    "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite.");
            info.screenDump();
            Runtime.getRuntime().exec("rm -rf " + param.outputPath);
        }

        // param.bestNas = (param.alignLength * param.readIdentity) / 100;
        // param.bestKmers = param.alignLength - (param.alignLength - param.bestNas) * 4 - 3;

    } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this.
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    } catch (RuntimeException e) {
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    } catch (ParseException e) {
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    }

    return param;
}