Example usage for java.lang Long longValue

List of usage examples for java.lang Long longValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public long longValue() 

Source Link

Document

Returns the value of this Long as a long value.

Usage

From source file:com.softlayer.objectstorage.Client.java

/**
 * Utility for creating a request param search string
 * /*from   w  ww.  j a va  2s. c  o  m*/
 * @param base
 *            the base url for objectstorage api
 * @param query
 *            terms for searching
 * @param limit
 *            number of results to return (pass null for default value)
 * @param start
 *            pagination offset for results to return (pass null for default
 *            value)
 * @param field
 *            name of a field to limit the search to (pass null for default
 *            value)
 * @param type
 * @param format
 * @param marker
 * @param recursive
 * @return a string url query
 */
protected static String makeSearchUrl(String query, Long limit, Long start, String field, String type,
        String format, String marker, boolean recursive) {
    ArrayList<String> params = new ArrayList<String>();
    if (query != null) {
        params.add("q=" + query);
    }
    if (limit != null) {
        params.add("limit=" + limit.longValue());
    }
    if (start != null) {
        params.add("start=" + start.longValue());
    }
    if (field != null) {
        params.add("field=" + field);
    }
    if (type != null) {
        params.add("type=" + type);
    }
    if (format != null) {
        params.add("format=" + format);
    }
    if (marker != null) {
        params.add("marker=" + field);
    }
    if (recursive) {
        params.add("recursive=" + recursive);
    }

    String p = "";

    for (String s : params) {

        p += (s + "&");
    }

    String base = "?" + p;
    return base;
}

From source file:com.fengduo.spark.commons.file.FileUtils.java

public static String getHumanReadableFileSize(Long fileSize) {
    if (fileSize == null)
        return null;
    return getHumanReadableFileSize(fileSize.longValue());
}

From source file:net.jradius.packet.attribute.AttributeFactory.java

public static RadiusAttribute newAttribute(Long key) throws Exception {
    RadiusAttribute a = null;// w  w  w.j av a2 s. c o  m

    long val = key.longValue();
    long vendor = val >> 16;
    long type = val & 0xFFFF;

    if (vendor != 0) {
        a = vsa(vendor, type);
    } else {
        a = attr(type);
    }

    // System.err.println("Created "+a.toString() + " " + key + " " + a.getFormattedType());

    return a;
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java

/**
 * Gets the current value of a "persistent" counter
 * @param ctx active PageContext//from w ww  . j av  a2 s .c  o  m
 * @param name name of counter
 * @return current value if counter exists, else -1
 */
public static long getPersistentCounterValue(PageContext ctx, String name) {
    long retval = -1;
    Long counter = (Long) ctx.getAttribute(name);
    if (counter != null) {
        retval = counter.longValue();
    }
    return retval;
}

From source file:fr.landel.utils.commons.ObjectUtils.java

/**
 * Get the primitive value of an {@link Long}. If {@code value} is not
 * {@code null}, returns the primitive value of {@code value} otherwise returns
 * {@code defaultValue}//from ww w. ja v  a 2s  . c om
 * 
 * <pre>
 * Long value = new Long(1l);
 * long value1 = ObjectUtils.toPrimitive(value, 0l); // =&gt; value1 = 1l
 * long value2 = ObjectUtils.toPrimitive((Long) null, 0l); // =&gt; value2 = 0l
 * </pre>
 * 
 * @param value
 *            the {@link Long} value
 * @param defaultValue
 *            the default value
 * @return a primitive long
 */
public static long toPrimitive(final Long value, final long defaultValue) {
    if (value == null) {
        return defaultValue;
    } else {
        return value.longValue();
    }
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a pie graph representing test counts for each product area. 
 *
 * @param   suites   List of test suites
 * @param   areas    List of product areas 
 * //ww  w  . j  a v a 2s .c o m
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageAreaTestTimeChart(Vector<CMnDbBuildData> builds,
        Vector<CMnDbTestSuite> suites, Vector<CMnDbFeatureOwnerData> areas) {
    JFreeChart chart = null;

    // Collect the average of all test types 
    Hashtable timeAvg = new Hashtable();

    DefaultPieDataset dataset = new DefaultPieDataset();
    if ((suites != null) && (suites.size() > 0)) {

        // Collect test data for each of the suites in the list 
        Enumeration suiteList = suites.elements();
        while (suiteList.hasMoreElements()) {

            // Process the data for the current suite
            CMnDbTestSuite suite = (CMnDbTestSuite) suiteList.nextElement();
            Long elapsedTime = new Long(suite.getElapsedTime() / (1000 * 60));
            CMnDbFeatureOwnerData area = null;

            // Iterate through each product area to determine who owns this suite
            CMnDbFeatureOwnerData currentArea = null;
            Iterator iter = areas.iterator();
            while (iter.hasNext()) {
                currentArea = (CMnDbFeatureOwnerData) iter.next();
                if (currentArea.hasFeature(suite.getGroupName())) {
                    Long avgValue = null;
                    String areaName = currentArea.getDisplayName();
                    if (timeAvg.containsKey(areaName)) {
                        Long oldAvg = (Long) timeAvg.get(areaName);
                        avgValue = oldAvg + elapsedTime;
                    } else {
                        avgValue = elapsedTime;
                    }
                    timeAvg.put(areaName, avgValue);

                }
            }

        } // while list has elements

        // Populate the data set with the average values for each metric
        Enumeration keys = timeAvg.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            Long total = (Long) timeAvg.get(key);
            Long avg = new Long(total.longValue() / builds.size());
            dataset.setValue(key, avg);
        }

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Avg Test Time by Area", dataset, true, true, false);

    // get a reference to the plot for further customization...
    PiePlot plot = (PiePlot) chart.getPlot();
    chartFormatter.formatAreaChart(plot, "min");

    return chart;
}

From source file:com.modeln.build.ctrl.charts.CMnBuildListChart.java

/**
 * Generate a pie graph representing average build execution times across 
 * all builds in the list. // www. j  av a  2s.co m
 *
 * @param   builds  List of builds 
 * 
 * @return  Pie graph representing build execution times across all builds 
 */
public static final JFreeChart getAverageMetricChart(Vector<CMnDbBuildData> builds) {
    JFreeChart chart = null;

    // Get a list of all possible build metrics
    int[] metricTypes = CMnDbMetricData.getAllTypes();
    Hashtable metricAvg = new Hashtable(metricTypes.length);

    DefaultPieDataset dataset = new DefaultPieDataset();
    if ((builds != null) && (builds.size() > 0)) {

        // Collect build metrics for each of the builds in the list 
        Enumeration buildList = builds.elements();
        while (buildList.hasMoreElements()) {

            // Process the build metrics for the current build
            CMnDbBuildData build = (CMnDbBuildData) buildList.nextElement();
            Vector metrics = build.getMetrics();
            if ((metrics != null) && (metrics.size() > 0)) {
                // Collect data for each of the build metrics in the current build 
                Enumeration metricList = metrics.elements();
                while (metricList.hasMoreElements()) {
                    CMnDbMetricData currentMetric = (CMnDbMetricData) metricList.nextElement();
                    // Get elapsed time in "minutes"
                    Long elapsedTime = new Long(currentMetric.getElapsedTime() / (1000 * 60));
                    String metricName = CMnDbMetricData.getMetricType(currentMetric.getType());
                    Long avgValue = null;
                    if (metricAvg.containsKey(metricName)) {
                        Long oldAvg = (Long) metricAvg.get(metricName);
                        avgValue = oldAvg + elapsedTime;
                    } else {
                        avgValue = elapsedTime;
                    }
                    metricAvg.put(metricName, avgValue);

                } // while build has metrics

            } // if has metrics

        } // while list has elements

        // Populate the data set with the average values for each metric
        Enumeration keys = metricAvg.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            Long total = (Long) metricAvg.get(key);
            Long avg = new Long(total.longValue() / (long) builds.size());
            //dataset.setValue(key, (Long) metricAvg.get(key));
            dataset.setValue(key, avg);
        }

    } // if list has elements

    // API: ChartFactory.createPieChart(title, data, legend, tooltips, urls)
    chart = ChartFactory.createPieChart("Average Build Metrics", dataset, true, true, false);

    // get a reference to the plot for further customization...
    PiePlot plot = (PiePlot) chart.getPlot();
    chartFormatter.formatMetricChart(plot, "min");

    return chart;
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java

/**
 * Increments a "persistent" counter. These counters are used by column tags
 * to track and increment values across column render passes.
 * @param ctx active PageContext/*from   w ww  . j av a2  s  .c  o  m*/
 * @param name name of counter
 * @return next value
 */
public static Long incrementPersistentCounter(PageContext ctx, String name) {
    Long counter = (Long) ctx.getRequest().getAttribute(name);
    if (counter == null) {
        counter = new Long(1);
    } else {
        counter = new Long(counter.longValue() + 1);
    }
    ctx.getRequest().setAttribute(name, counter);
    return counter;
}

From source file:com.xwtec.xwserver.util.json.util.JSONUtils.java

/**
 * Transforms a Number into a valid javascript number.<br>
 * Float gets promoted to Double.<br>
 * Byte and Short get promoted to Integer.<br>
 * Long gets downgraded to Integer if possible.<br>
 *//*w  w  w  .jav a  2 s.  co m*/
public static Number transformNumber(Number input) {
    if (input instanceof Float) {
        return new Double(input.toString());
    } else if (input instanceof Short) {
        return new Integer(input.intValue());
    } else if (input instanceof Byte) {
        return new Integer(input.intValue());
    } else if (input instanceof Long) {
        Long max = new Long(Integer.MAX_VALUE);
        if (input.longValue() <= max.longValue() && input.longValue() >= Integer.MIN_VALUE) {
            return new Integer(input.intValue());
        }
    }

    return input;
}

From source file:gridool.db.helpers.GridDbUtils.java

public static long invokeCsvLoadJob(final GridKernel kernel, final String csvFileName,
        final HashMap<GridNode, MutableLong> assignMap, final DBPartitioningJobConf jobConf) {
    String connectUrl = jobConf.getConnectUrl();
    String tableName = jobConf.getTableName();
    String createTableDDL = jobConf.getCreateTableDDL();
    String copyIntoQuery = generateCopyIntoQuery(tableName, jobConf);
    String alterTableDDL = jobConf.getAlterTableDDL();

    MonetDBCsvLoadOperation ops = new MonetDBCsvLoadOperation(connectUrl, tableName, csvFileName,
            createTableDDL, copyIntoQuery, alterTableDDL);
    ops.setAuth(jobConf.getUserName(), jobConf.getPassword());
    final Pair<MonetDBCsvLoadOperation, Map<GridNode, MutableLong>> pair = new Pair<MonetDBCsvLoadOperation, Map<GridNode, MutableLong>>(
            ops, assignMap);/*from www .  ja v  a2s .  c  o  m*/

    final GridJobFuture<Long> future = kernel.execute(MonetDBInvokeCsvLoadJob.class, pair);
    final Long numInserted;
    try {
        numInserted = future.get();
    } catch (InterruptedException ie) {
        LOG.error(ie.getMessage(), ie);
        throw new IllegalStateException(ie);
    } catch (ExecutionException ee) {
        LOG.error(ee.getMessage(), ee);
        throw new IllegalStateException(ee);
    }
    return (numInserted == null) ? -1L : numInserted.longValue();
}