Example usage for java.lang Long intValue

List of usage examples for java.lang Long intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Long as an int after a narrowing primitive conversion.

Usage

From source file:com.alibaba.otter.shared.arbitrate.impl.manage.helper.ManagePathUtils.java

/**
 * processIdzookeepernode??//from   w w  w  .  j  a v  a  2s .c o m
 */
public static String getProcessNode(Long processId) {
    return StringUtils.leftPad(String.valueOf(processId.intValue()), 10, '0');
}

From source file:Main.java

public static <RET> RET fromBase36(String basecode) {
    Long result = Long.valueOf(basecode, 36);
    long maxInt = new Long(Integer.MAX_VALUE);

    if (result > maxInt) {
        return ((RET) result);
    } else {//from w w w . j  a v a2s. com
        return ((RET) (Integer) result.intValue());
    }

}

From source file:com.dcsquare.hivemq.spi.config.Configurations.java

/**
 * Creates a new Properties file configuration which automatically reloads itself in the given interval.
 * <p/>//from w  w w  .jav  a2 s  . co m
 * Searches for the configuration file in the plugins folder of HiveMQ.
 *
 * @param fileName       the file name of the properties file which is located in the plugins folder of HiveMQ.
 * @param reReadSchedule the time schedule when a reload should occur
 * @param timeUnit       the time unit of the reReadSchedule
 * @return a reloadable properties file configuration
 */
public static AbstractConfiguration newReloadablePropertiesConfiguration(final String fileName,
        final int reReadSchedule, final TimeUnit timeUnit) {
    final PropertiesFileDatasource datasource = new PropertiesFileDatasource(PathUtils.getPluginFolder(),
            fileName);
    final Long scheduleInMillis = timeUnit.toMillis(reReadSchedule);
    final AbstractPollingScheduler scheduler = new FixedDelayPollingScheduler(scheduleInMillis.intValue(),
            scheduleInMillis.intValue(), true);
    return new DynamicConfiguration(datasource, scheduler);
}

From source file:msuresh.raftdistdb.RaftCluster.java

public static void InitPortNumber() {
    try {/*from ww  w.  j ava2s . com*/
        File f = new File(Constants.STATE_LOCATION + "global.info");
        if (!f.exists()) {
            createDefaultGlobal();
        }
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader(Constants.STATE_LOCATION + "global.info"));
        JSONObject jsonObject = (JSONObject) obj;
        Long a = (Long) jsonObject.get("currentCount");
        portId = a.intValue();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:gov.nih.nci.protexpress.util.ManageProtAppInputOutputHelper.java

/**
 * Deletes the element at the specified index from the list.
 *
 * @param lst the list./*  w  w w . j a  v  a2 s .  c  om*/
 * @param index the index of the object to be deleted.
 */
private static void deleteElementFromList(List<InputOutputObject> lst, Long deleteIndex) {
    if ((lst != null) && (deleteIndex.intValue() >= 0) && (lst.size() > 0)) {
        lst.remove(deleteIndex.intValue());
    }
}

From source file:msuresh.raftdistdb.TestAtomix.java

private static void InitPortNumber() {
    try {//  w  w  w  .j a  va 2 s  .co m
        File f = new File(Constants.STATE_LOCATION + "global.info");
        if (!f.exists()) {
            RaftCluster.createDefaultGlobal();
        }
        JSONParser parser = new JSONParser();
        Object obj = parser.parse(new FileReader(Constants.STATE_LOCATION + "global.info"));
        JSONObject jsonObject = (JSONObject) obj;
        Long a = (Long) jsonObject.get("currentCount");
        portId = a.intValue();
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}

From source file:com.github.rinde.rinsim.scenario.generator.PoissonProcessTest.java

/**
 * Checks whether the observations conform to a Poisson process with the
 * specified intensity. Uses a chi square test with the specified confidence.
 * The null hypothesis is that the observations are the result of a poisson
 * process./*  w  w  w.j a  v  a  2s .com*/
 * @param observations
 * @param intensity
 * @param confidence
 * @return <code>true</code> if the observations
 */
static boolean isPoissonProcess(Frequency observations, double intensity, double length, double confidence) {
    final PoissonDistribution pd = new PoissonDistribution(length * intensity);

    final Iterator<?> it = observations.valuesIterator();
    final long[] observed = new long[observations.getUniqueCount()];
    final double[] expected = new double[observations.getUniqueCount()];

    int index = 0;
    while (it.hasNext()) {
        final Long l = (Long) it.next();
        observed[index] = observations.getCount(l);
        expected[index] = pd.probability(l.intValue()) * observations.getSumFreq();
        if (expected[index] == 0) {
            return false;
        }
        index++;
    }
    final double chi = TestUtils.chiSquareTest(expected, observed);
    return !(chi < confidence);
}

From source file:com.evolveum.openicf.lotus.util.DominoUtils.java

public static Integer getDays(Long endDate) {
    if (endDate == null) {
        return null;
    }/*from   w w w.  ja  va2  s  . co m*/

    Long days = (endDate - System.currentTimeMillis()) / 86400000L;
    return days.intValue();
}

From source file:com.lostad.app.base.util.DownloadUtil.java

public static void downFileAsyn(final Activity ctx, final String upgradeUrl, final String savedPath,
        final MyCallback<Boolean> callback) {
    final ProgressDialog xh_pDialog = new ProgressDialog(ctx);
    // ?/*from  w  w w .j a v  a  2 s  . c o  m*/
    xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    // ProgressDialog 
    xh_pDialog.setTitle("???");
    // ProgressDialog???
    xh_pDialog.setMessage("...");
    // ProgressDialog
    // xh_pDialog.setIcon(R.drawable.img2);
    // ProgressDialog ??? false ??
    xh_pDialog.setIndeterminate(false);
    // ProgressDialog ?
    // xh_pDialog.setProgress(100);
    // ProgressDialog ???
    xh_pDialog.setCancelable(true);
    // ProgressDialog
    xh_pDialog.show();

    new Thread() {
        public void run() {

            boolean downloadSuccess = true;
            FileOutputStream fileOutputStream = null;
            try {
                Looper.prepare();
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(upgradeUrl);

                File f = new File(savedPath);
                if (!f.exists()) {
                    f.createNewFile();
                }

                HttpResponse response = client.execute(get);
                HttpEntity entity = response.getEntity();
                // ?
                Long length = entity.getContentLength();
                xh_pDialog.setMax(length.intValue());
                //
                InputStream is = entity.getContent();
                fileOutputStream = null;

                if (is != null && length > 0) {

                    fileOutputStream = new FileOutputStream(f);

                    byte[] buf = new byte[1024];
                    int ch = -1;
                    int count = 0;
                    while ((ch = is.read(buf)) != -1) {

                        if (xh_pDialog.isShowing()) {
                            fileOutputStream.write(buf, 0, ch);
                            // ?
                            count += ch;
                            xh_pDialog.setProgress(count);
                        } else {
                            downloadSuccess = false;
                            break;// ?
                        }
                    }

                } else {
                    callback.onCallback(false);
                }

                if (downloadSuccess && fileOutputStream != null) {
                    xh_pDialog.dismiss();
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    callback.onCallback(true);// ?
                }
                Looper.loop();
            } catch (FileNotFoundException e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
                xh_pDialog.dismiss();
            } catch (Exception e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
            } finally {
                try {
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }.start();

}

From source file:configuration.Key.java

/**
 * Returns the keys provided in the JSON array.
 * /*from   www .j a v a 2 s .c om*/
 * @param array
 *            the JSON array to parse for keys.
 * @return the keys provided in the JSON array.
 */
public static Key[] parseKeys(JSONArray array) {
    List<Key> keys = new LinkedList<Key>();

    if (array == null) {
        throw new NullPointerException("array may not be null!");
    }

    for (int i = 0; i < array.size(); i++) {
        JSONObject object = (JSONObject) array.get(i);
        String key = (String) object.get(KEY_KEY);
        Long version = (Long) object.get(KEY_VERSION);
        int versionInt = version.intValue();
        String algorithm = (String) object.get(KEY_ALGORITHM);
        /*
         * getEncoded() returns the raw bytes of the key (s.
         * http://docs.oracle
         * .com/javase/7/docs/api/javax/crypto/SecretKey.html)
         */
        try {
            byte[] rawKey = Coder.decodeBASE64(key);
            SecretKey secretKey = new SecretKeySpec(rawKey, getSecretKeyAlgorithm(algorithm));
            keys.add(new Key(secretKey, versionInt, algorithm));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return keys.toArray(new Key[0]);
}