Example usage for java.lang Integer toString

List of usage examples for java.lang Integer toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this Integer 's value.

Usage

From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java

/**
 * Safely converts a number to a BigInteger. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    object to parse//from ww w .j  av  a2  s.  c o  m
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static BigInteger toBigInteger(Object obj) {

    /* Switch on class and convert to BigInteger */

    String type = obj.getClass().getSimpleName();
    BigInteger parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = new BigInteger(by.toString());
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = new BigInteger(sh.toString());
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = new BigInteger(in.toString());
        break;

    case "Long":
        Long lo = (Long) obj;
        parsed = new BigInteger(lo.toString());
        break;

    case "Float":
        Float fl = (Float) obj;
        parsed = new BigInteger(fl.toString());
        break;

    case "BigInteger":
        parsed = (BigInteger) obj;
        break;

    case "BigDecimal":
        parsed = ((BigDecimal) obj).toBigInteger();
        break;

    case "Double":
        Double db = (Double) obj;
        parsed = new BigInteger(db.toString());
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java

/**
 * Safely converts a number to a BigInteger. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    object to parse/*from ww w. java 2 s  . c  o m*/
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static BigInteger toBigInteger(Number number) {

    /* Switch on class and convert to BigInteger */

    String type = number.getClass().getSimpleName();
    BigInteger parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = new BigInteger(by.toString());
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = new BigInteger(sh.toString());
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = new BigInteger(in.toString());
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = new BigInteger(lo.toString());
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = new BigInteger(fl.toString());
        break;

    case "BigInteger":
        parsed = (BigInteger) number;
        break;

    case "BigDecimal":
        parsed = ((BigDecimal) number).toBigInteger();
        break;

    case "Double":
        Double db = (Double) number;
        parsed = new BigInteger(db.toString());
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.kenai.redminenb.issue.JournalDisplay.java

private static String formatTracker(RedmineRepository repo, String value) {
    if (value == null) {
        return null;
    }/* w w  w.  j a  va  2s.c o m*/
    try {
        Integer id = Integer.valueOf(value);
        for (Tracker t : repo.getTrackers()) {
            if (t.getId().equals(id)) {
                return t.getName() + " (ID: " + id.toString() + ")";
            }
        }
    } catch (NumberFormatException ex) {
    }
    return "(ID: " + value + ")";
}

From source file:com.clustercontrol.jobmanagement.util.ParameterUtil.java

/**
 * #[RETURN:jobId:facilityId]??/*from   w  w w  .j  a  v a 2  s  .  c  om*/
 * @param sessionId
 * @param jobunitId
 * @param jobId
 * @param source
 * @return
 */
public static String replaceReturnCodeParameter(String sessionId, String jobunitId, String source) {
    String regex = "#\\[RETURN:([^:]*):([^:]*)\\]";
    Pattern pattern = Pattern.compile(regex);
    String ret = source;
    for (int i = 0; i < 100; i++) { //??????????
        Matcher matcher = pattern.matcher(ret);
        if (matcher.find()) {
            String rJobId = matcher.group(1);
            String rFacilityId = matcher.group(2);
            try {
                JobSessionNodeEntity node = QueryUtil.getJobSessionNodePK(sessionId, jobunitId, rJobId,
                        rFacilityId);
                Integer endValue = node.getEndValue();
                if (endValue != null) {
                    ret = ret.replaceFirst(regex, endValue.toString());
                } else {
                    // ??????
                    ret = ret.replaceFirst(regex, "null");
                }
            } catch (JobInfoNotFound e) {
                m_log.warn("replaceReturnCodeParameter : jobId=" + rJobId + ", facilityId=" + rFacilityId);
                // ?ID????
                ret = ret.replaceFirst(regex, "null");
            }
            /*
             * for test
             * ?(??main?)??
             */
            // ret = ret.replaceFirst(regex, "12345");
        } else {
            break;
        }
    }
    return ret;
}

From source file:com.kenai.redminenb.issue.JournalDisplay.java

private static String formatStatus(RedmineRepository repo, String value) {
    if (value == null) {
        return null;
    }/*from  w  w w. j  a va 2 s  .  c o  m*/
    try {
        Integer id = Integer.valueOf(value);
        for (IssueStatus is : repo.getStatuses()) {
            if (is.getId().equals(id)) {
                return is.getName() + " (ID: " + id.toString() + ")";
            }
        }
    } catch (NumberFormatException ex) {
    }
    return "(ID: " + value + ")";
}

From source file:bioLockJ.AppController.java

private static String twoDigitVal(final Integer input) {
    String val = input.toString();
    if (val.length() == 1) {
        val = "0" + val;
    }//from w  w w.j  av  a2s  .co m
    return val;
}

From source file:com.kenai.redminenb.issue.JournalDisplay.java

private static String formatPriority(RedmineRepository repo, String value) {
    if (value == null) {
        return null;
    }/*ww w .  j  a  v  a  2s  .c  o m*/
    try {
        Integer id = Integer.valueOf(value);
        for (IssuePriority ip : repo.getIssuePriorities()) {
            if (ip.getId().equals(id)) {
                return ip.getName() + " (ID: " + id.toString() + ")";
            }
        }
    } catch (NumberFormatException ex) {
    }
    return "(ID: " + value + ")";
}

From source file:com.chiorichan.util.WebUtils.java

public static String createTable(List<Object> tableData, List<String> headerArray, String tableId,
        String altTableClass) {//from  w  ww  .  j a va  2  s. co  m
    Map<Object, Object> newData = Maps.newLinkedHashMap();

    Integer x = 0;
    for (Object o : tableData) {
        newData.put(x.toString(), o);
        x++;
    }

    return createTable(newData, headerArray, tableId, altTableClass);
}

From source file:com.act.lcms.db.analysis.ChemicalToMapOfMetlinIonsToIntensityTimeValues.java

/**
 * This function plots a combination of positive and negative control intensity-time values.
 * @param searchMzs A list of mass charge values
 * @param plottingPath The wells used for the analysis. This variable is mainly used for
 * @param peakDataPos The postive intensity-time value
 * @param peakDataNegs The negative controls intensity-time values
 * @param plottingDirectory The directory where the plots are going to be placed in
 * @return/*from  w  ww . j av  a  2  s  .  c  o  m*/
 * @throws IOException
 */
public static Map<String, String> plotPositiveAndNegativeControlsForEachMZ(Set<Pair<String, Double>> searchMzs,
        String plottingPath, ChemicalToMapOfMetlinIonsToIntensityTimeValues peakDataPos,
        List<ChemicalToMapOfMetlinIonsToIntensityTimeValues> peakDataNegs, String plottingDirectory)
        throws IOException {

    Map<String, String> result = new HashMap<>();
    Map<String, Double> individualMaxIntensities = new HashMap<>();
    WriteAndPlotMS1Results plottingUtil = new WriteAndPlotMS1Results();

    for (Pair<String, Double> mz : searchMzs) {
        LinkedHashMap<String, List<XZ>> ms1s = new LinkedHashMap<>();
        Map<String, Double> metlinMasses = new HashMap<>();
        Double maxIntensity = 0.0d;

        String chemicalAndIonName = mz.getLeft();
        Double massChargeValue = mz.getRight();

        // Get positive ion results
        String positiveChemicalName = AnalysisHelper.constructChemicalAndScanTypeName(chemicalAndIonName,
                ScanData.KIND.POS_SAMPLE);
        List<XZ> ionValuesPos = peakDataPos.peakData.get(positiveChemicalName).get(chemicalAndIonName);
        ms1s.put(positiveChemicalName, ionValuesPos);
        Double localMaxIntensityPos = findPeakMaxIntensity(ionValuesPos);
        maxIntensity = Math.max(maxIntensity, localMaxIntensityPos);
        individualMaxIntensities.put(positiveChemicalName, localMaxIntensityPos);
        metlinMasses.put(positiveChemicalName, massChargeValue);

        // Get negative control results
        Integer negNameCounter = 0;
        for (ChemicalToMapOfMetlinIonsToIntensityTimeValues peakDataNeg : peakDataNegs) {
            String negativeChemicalName = AnalysisHelper.constructChemicalAndScanTypeName(chemicalAndIonName,
                    ScanData.KIND.NEG_CONTROL);
            String negativeChemicalNameId = negativeChemicalName + "_" + negNameCounter.toString();
            List<XZ> ionValuesNeg = peakDataNeg.peakData.get(negativeChemicalName).get(chemicalAndIonName);
            ms1s.put(negativeChemicalNameId, ionValuesNeg);
            Double localMaxIntensityNeg = findPeakMaxIntensity(ionValuesNeg);
            maxIntensity = Math.max(maxIntensity, localMaxIntensityNeg);
            individualMaxIntensities.put(negativeChemicalNameId, localMaxIntensityNeg);
            metlinMasses.put(negativeChemicalNameId, massChargeValue);
            negNameCounter++;
        }

        String relativePath = massChargeValue.toString() + "_" + plottingPath + "_" + chemicalAndIonName;
        File absolutePathFileWithoutExtension = new File(plottingDirectory, relativePath);
        String absolutePathWithoutExtension = absolutePathFileWithoutExtension.getAbsolutePath();
        String absolutePathWithExtension = absolutePathWithoutExtension + "." + FMT;

        // Check if the plotting file already exists. If it does, we should not overwrite it. Instead, we just change
        // the path name by appending a counter till the collision no longer exists.
        // TODO: Implement an elegant solution to this problem.
        File duplicateFile = new File(absolutePathWithExtension);
        Integer fileDuplicateCounter = 0;
        while (duplicateFile.exists() && !duplicateFile.isDirectory()) {
            LOGGER.warn("Duplicate file exists for %s, writing to another file",
                    duplicateFile.getAbsolutePath());
            fileDuplicateCounter++;
            relativePath = relativePath + "_" + fileDuplicateCounter.toString();
            absolutePathFileWithoutExtension = new File(plottingDirectory, relativePath);
            absolutePathWithoutExtension = absolutePathFileWithoutExtension.getAbsolutePath();
            absolutePathWithExtension = absolutePathWithoutExtension + "." + FMT;
            duplicateFile = new File(absolutePathWithExtension);
        }

        LOGGER.info("Wrote plot to %s", absolutePathWithoutExtension);

        plottingUtil.plotSpectra(ms1s, maxIntensity, individualMaxIntensities, metlinMasses,
                absolutePathWithoutExtension, FMT, false, false);

        result.put(mz.getLeft(), relativePath + "." + FMT);
    }

    return result;
}

From source file:com.kenai.redminenb.issue.JournalDisplay.java

private static String formatVersion(RedmineRepository repo, RedmineIssue issue, String value) {
    if (value == null) {
        return null;
    }/*  www.  j  a  v a 2  s  . c om*/
    try {
        Integer id = Integer.valueOf(value);
        for (Version v : repo.getVersions(ProjectFactory.create(issue.getIssue().getProjectId()))) {
            if (v.getId().equals(id)) {
                return v.getName() + " (ID: " + id.toString() + ")";
            }
        }
    } catch (NumberFormatException ex) {
    }
    return "(ID: " + value + ")";
}