Example usage for java.lang Integer valueOf

List of usage examples for java.lang Integer valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Integer valueOf(int i) 

Source Link

Document

Returns an Integer instance representing the specified int value.

Usage

From source file:Main.java

public static boolean checkNewVersionApp(String currentVersionName, String versionName) {
    String[] currentVersion = currentVersionName.split("[.]");
    String[] version = versionName.split("[.]");
    int[] currentVersionNum = new int[3];
    int[] versionNum = new int[3];
    for (int i = 0; i < currentVersion.length; i++) {
        currentVersionNum[i] = Integer.valueOf(currentVersion[i]);
    }/*from  w w w . ja  v a2s. c o  m*/
    for (int j = 0; j < version.length; j++) {
        versionNum[j] = Integer.valueOf(version[j]);
    }
    if (versionNum[0] > currentVersionNum[0]) {
        return true;
    } else if (versionNum[0] == currentVersionNum[0]) {
        if (versionNum[1] > currentVersionNum[1]) {
            return true;
        } else if (versionNum[1] == currentVersionNum[1]) {
            if (versionNum[2] > currentVersionNum[2]) {
                return true;
            }
        }
    }
    return false;
}

From source file:Main.java

public static boolean validateCardNumber(String n) {
    n = n.replace(" ", "");
    int j = n.length();

    String[] s1 = new String[j];
    for (int i = 0; i < n.length(); i++)
        s1[i] = "" + n.charAt(i);

    int checksum = 0;

    for (int i = s1.length - 1; i >= 0; i -= 2) {
        int k = 0;

        if (i > 0) {
            k = Integer.valueOf(s1[i - 1]) * 2;
            if (k > 9) {
                String s = "" + k;
                k = Integer.valueOf(s.substring(0, 1)) + Integer.valueOf(s.substring(1));
            }/*from   w  w w.j av  a 2  s  . c  om*/
            checksum += Integer.valueOf(s1[i]) + k;
        } else
            checksum += Integer.valueOf(s1[0]);
    }

    return ((checksum % 10) == 0);
}

From source file:Main.java

/**
 * getNotiPercent//from  w  w w . j a  v a 2  s.  co  m
 * 
 * @param progress
 * @param max
 * @return
 */
public static Integer getNotiPercent(long progress, long max) {
    int rate = 0;
    if (progress <= 0 || max <= 0) {
        rate = 0;
    } else if (progress > max) {
        rate = 100;
    } else {
        rate = (int) ((double) progress / max * 100);
    }
    return Integer.valueOf(new StringBuilder(16).append(rate).toString());
}

From source file:Main.java

/**
 * Gets an integer value of the given attribute
 * @param node/*from   ww w  .  ja  v  a2  s  .  c o  m*/
 * @param attrName
 * @param defaultValue
 * @return
 */
public static int getIntegerValue(Node node, String attrName, int defaultValue) {
    String value = getValue(node, attrName, null);

    if (value == null)
        return defaultValue;

    try {
        return Integer.valueOf(value);
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:edu.msu.cme.rdp.readseq.utils.SequenceTrimmer.java

public static void main(String[] args) throws IOException {
    Options options = new Options();
    options.addOption("r", "ref-seq", true,
            "Trim points are given as positions in a reference sequence from this file");
    options.addOption("i", "inclusive", false, "Trim points are inclusive");
    options.addOption("l", "length", true, "Minimum length of sequence after trimming");
    options.addOption("f", "filled-ratio", true,
            "Minimum ratio of filled model positions of sequence after trimming");
    options.addOption("o", "out", true, "Write sequences to directory (default=cwd)");
    options.addOption("s", "stats", true, "Write stats to file");

    PrintWriter statsOut = new PrintWriter(new NullWriter());
    boolean inclusive = false;
    int minLength = 0;
    int minTrimmedLength = 0;
    int maxNs = 0;
    int maxTrimNs = 0;

    int trimStart = 0;
    int trimStop = 0;
    Sequence refSeq = null;/*  ww w .  j  a  va 2  s. co m*/
    float minFilledRatio = 0;

    int expectedModelPos = -1;
    String[] inputFiles = null;
    File outdir = new File(".");
    try {
        CommandLine line = new PosixParser().parse(options, args);

        if (line.hasOption("ref-seq")) {
            refSeq = readRefSeq(new File(line.getOptionValue("ref-seq")));
        }

        if (line.hasOption("inclusive")) {
            inclusive = true;
        }

        if (line.hasOption("length")) {
            minLength = Integer.valueOf(line.getOptionValue("length"));
        }

        if (line.hasOption("filled-ratio")) {
            minFilledRatio = Float.valueOf(line.getOptionValue("filled-ratio"));
        }

        if (line.hasOption("out")) {
            outdir = new File(line.getOptionValue("out"));
            if (!outdir.isDirectory()) {
                outdir = outdir.getParentFile();
                System.err.println("Output option is not a directory, using " + outdir + " instead");
            }
        }

        if (line.hasOption("stats")) {
            statsOut = new PrintWriter(line.getOptionValue("stats"));
        }

        args = line.getArgs();

        if (args.length < 3) {
            throw new Exception("Unexpected number of arguments");
        }

        trimStart = Integer.parseInt(args[0]);
        trimStop = Integer.parseInt(args[1]);
        inputFiles = Arrays.copyOfRange(args, 2, args.length);

        if (refSeq != null) {
            expectedModelPos = SeqUtils.getMaskedBySeqString(refSeq.getSeqString()).length();
            trimStart = translateCoord(trimStart, refSeq, CoordType.seq, CoordType.model);
            trimStop = translateCoord(trimStop, refSeq, CoordType.seq, CoordType.model);
        }

    } catch (Exception e) {
        new HelpFormatter().printHelp("SequenceTrimmer <trim start> <trim stop> <aligned file> ...", options);
        System.err.println("Error: " + e.getMessage());
    }

    System.err.println("Starting sequence trimmer");
    System.err.println("*  Input files:           " + Arrays.asList(inputFiles));
    System.err.println("*  Minimum Length:        " + minLength);
    System.err.println("*  Trim point inclusive?: " + inclusive);
    System.err.println("*  Trim points:           " + trimStart + "-" + trimStop);
    System.err.println("*  Min filled ratio:      " + minFilledRatio);
    System.err.println("*  refSeq:                "
            + ((refSeq == null) ? "model" : refSeq.getSeqName() + " " + refSeq.getDesc()));

    Sequence seq;
    SeqReader reader;
    TrimStats stats;

    writeStatsHeader(statsOut);

    FastaWriter seqWriter;
    File in;
    for (String infile : inputFiles) {
        in = new File(infile);
        reader = new SequenceReader(in);
        seqWriter = new FastaWriter(new File(outdir, "trimmed_" + in.getName()));

        while ((seq = reader.readNextSequence()) != null) {
            if (seq.getSeqName().startsWith("#")) {
                seqWriter.writeSeq(seq.getSeqName(), "", trimMetaSeq(seq.getSeqString(), trimStart, trimStop));
                continue;
            }

            stats = getStats(seq, trimStart, trimStop);
            boolean passed = didSeqPass(stats, minLength, minTrimmedLength, maxNs, maxTrimNs, minFilledRatio);
            writeStats(statsOut, seq.getSeqName(), stats, passed);
            if (passed) {
                seqWriter.writeSeq(seq.getSeqName(), seq.getDesc(), new String(stats.trimmedBases));
            }
        }

        reader.close();
        seqWriter.close();
    }

    statsOut.close();
}

From source file:Main.java

public static <T> T getData(Context context, String fileName, String key, Class T) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    T result;//  w  w  w.  j  a v  a2  s .co  m
    if (String.class.isAssignableFrom(T)) {
        result = (T) sharedPreferences.getString(key, "");
    } else if (Integer.class.isAssignableFrom(T)) {
        result = (T) Integer.valueOf(sharedPreferences.getInt(key, 0));
    } else if (Float.class.isAssignableFrom(T)) {
        result = (T) Float.valueOf(sharedPreferences.getFloat(key, 0));
    } else if (Long.class.isAssignableFrom(T)) {
        result = (T) Long.valueOf(sharedPreferences.getLong(key, 0));
    } else {
        result = (T) Boolean.valueOf(sharedPreferences.getBoolean(key, false));
    }
    return result;
}

From source file:Main.java

/**
 * @param date/*from  w w w .  jav  a 2s .  c  om*/
 *            Date for which seconds since the epoch date is to be calculated
 * @return Number of seconds after the unix epoch date equivalent to the given date
 */
public static Integer secondsSinceUnixEpoch(final LocalDateTime date) {
    if (date == null) {
        return null;
    }
    final Long timeInSeconds = Long.valueOf(date.toEpochSecond(ZoneOffset.UTC));
    return Integer.valueOf(timeInSeconds.intValue());
}

From source file:Main.java

/**
 * Takes a string of the form [HH:]MM:SS[.mmm] and converts it to
 * milliseconds.//  w  ww  . ja v a2 s . c o  m
 *
 * @throws java.lang.NumberFormatException if the number segments contain invalid numbers.
 */
public static long parseTimeString(final String time) {
    String[] parts = time.split(":");
    long result = 0;
    int idx = 0;
    if (parts.length == 3) {
        // string has hours
        result += Integer.valueOf(parts[idx]) * 3600000L;
        idx++;
    }
    if (parts.length >= 2) {
        result += Integer.valueOf(parts[idx]) * 60000L;
        idx++;
        result += (Float.valueOf(parts[idx])) * 1000L;
    }
    return result;
}

From source file:Main.java

private static String unescapeControlCodes(String text) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        if (c == '&' && i + 1 < text.length() && text.charAt(i + 1) == '#') {
            int semiColonIndex = semiColonIndex(text, i);
            if (semiColonIndex != -1) {
                int value = Integer.valueOf(text.substring(i + 2, semiColonIndex));
                builder.append((char) value);
                i = semiColonIndex;/*from  w  w  w .  ja v  a2s . co  m*/
            }
        } else {
            builder.append(c);
        }
    }
    return builder.toString();
}

From source file:Main.java

public static List<Integer> readSp(Context context, String key) {
    SharedPreferences sp = getSharedPreferences(context);
    List<Integer> result = new ArrayList<Integer>();
    String str = sp.getString(key, "");
    if (str.length() > 0) {
        String[] split = str.split(":");

        for (String string : split) {
            result.add(Integer.valueOf(string));
        }//w ww. j  a v  a2  s .  c  o  m
    }
    return result;
}