Example usage for java.lang Float longValue

List of usage examples for java.lang Float longValue

Introduction

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

Prototype

public long longValue() 

Source Link

Document

Returns value of this Float as a long after a narrowing primitive conversion.

Usage

From source file:Main.java

public static void main(String[] args) {
    Float floatObject = new Float("10.01");
    long l = floatObject.longValue();
    System.out.println("long:" + l);
}

From source file:org.apache.hadoop.hive.ql.udf.UDFToLong.java

public Long evaluate(Float i) {
    if (i == null) {
        return null;
    } else {//from  ww w .j  a  v a 2 s .  co m
        return Long.valueOf(i.longValue());
    }
}

From source file:de.digiway.rapidbreeze.server.model.download.ThrottledInputStream.java

/**
 * Returns the duration in ms when the next transfer can be executed for the
 * given chunksize./*from  ww  w . j  ava  2s  .c o m*/
 *
 * @return
 */
public int nextTransfer(long chunksize) {
    Float idle = (1 / throttleBytesPerMillis) * (float) chunksize;
    long alreadyWaited = System.currentTimeMillis() - lastRead;
    long toWait = idle.longValue() - alreadyWaited + autoCorrection;
    return (int) (toWait < 0 ? 0 : toWait);
}

From source file:org.jahia.utils.maven.plugin.contentgenerator.wise.FileAndFolderService.java

private String getRandomJcrDate(long timestampDifference) {
    Float f = rand.nextFloat();
    f = f * timestampDifference;//from  w w  w  . j a v  a 2  s.c  om
    f = f + startTimestamp;
    Date d = new Date(f.longValue());
    Calendar c = GregorianCalendar.getInstance();
    c.setTime(d);
    return org.apache.jackrabbit.util.ISO8601.format(c);
}

From source file:iddb.core.util.Functions.java

public static Long time2minutes(String time) {
    if (time == null || "".trim().equals(time))
        return 0L;

    Float value;

    char last = time.charAt(time.length() - 1);
    try {/*  w w w  . j  a va2s  .co  m*/
        switch (last) {
        case 'h':
            value = Float.parseFloat(time.substring(0, time.length() - 1)) * 60;
            break;
        case 'm':
            value = Float.parseFloat(time.substring(0, time.length() - 1));
            break;
        case 's':
            value = Float.parseFloat(time.substring(0, time.length() - 1)) / 60;
            break;
        case 'd':
            value = Float.parseFloat(time.substring(0, time.length() - 1)) * 60 * 24;
            break;
        case 'w':
            value = Float.parseFloat(time.substring(0, time.length() - 1)) * 60 * 24 * 7;
            break;
        case 'M':
            value = Float.parseFloat(time.substring(0, time.length() - 1)) * 60 * 24 * 31;
            break;
        case 'y':
            value = Float.parseFloat(time.substring(0, time.length() - 1)) * 60 * 24 * 365;
            break;
        default:
            value = Float.parseFloat(time);
            break;
        }
    } catch (NumberFormatException e) {
        value = 0f;
    }
    return value.longValue();
}

From source file:org.runnerup.export.RunKeeperSynchronizer.java

private String parseForNext(JSONObject resp, List<SyncActivityItem> items) throws JSONException {
    if (resp.has("items")) {
        JSONArray activities = resp.getJSONArray("items");
        for (int i = 0; i < activities.length(); i++) {
            JSONObject item = activities.getJSONObject(i);
            SyncActivityItem ai = new SyncActivityItem();

            String startTime = item.getString("start_time");
            SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US);
            try {
                ai.setStartTime(TimeUnit.MILLISECONDS.toSeconds(format.parse(startTime).getTime()));
            } catch (ParseException e) {
                Log.e(Constants.LOG, e.getMessage());
                return null;
            }/* ww w. jav  a  2  s .c om*/
            Float time = Float.parseFloat(item.getString("duration"));
            ai.setDuration(time.longValue());
            BigDecimal dist = new BigDecimal(Float.parseFloat(item.getString("total_distance")));
            dist = dist.setScale(2, BigDecimal.ROUND_UP);
            ai.setDistance(dist.floatValue());
            ai.setURI(REST_URL + item.getString("uri"));
            ai.setId((long) items.size());
            String sport = item.getString("type");
            if (runkeeper2sportMap.containsKey(sport)) {
                ai.setSport(runkeeper2sportMap.get(sport).getDbValue());
            } else {
                ai.setSport(Sport.OTHER.getDbValue());
            }
            items.add(ai);
        }
    }
    if (resp.has("next")) {
        return REST_URL + resp.getString("next");
    }
    return null;
}

From source file:ru.histone.v2.evaluator.Evaluator.java

private CompletableFuture<EvalNode> processAddNode(ExpAstNode node, Context context) {
    CompletableFuture<List<EvalNode>> leftRight = evalAllNodesOfCurrent(node, context);
    return leftRight.thenCompose(lr -> {
        EvalNode left = lr.get(0);//from   w w w . j  av  a  2 s . c o m
        EvalNode right = lr.get(1);
        if (!(left instanceof StringEvalNode || right instanceof StringEvalNode)) {
            if (isNumberNode(left) && isNumberNode(right)) {
                Float res = getValue(left).orElse(null) + getValue(right).orElse(null);
                if (res % 1 == 0 && res <= Long.MAX_VALUE) {
                    return EvalUtils.getValue(res.longValue());
                } else {
                    return EvalUtils.getValue(res);
                }
            }

            if (left instanceof MapEvalNode && right instanceof MapEvalNode) {
                throw new NotImplementedException();
            }
        }

        CompletableFuture<List<EvalNode>> lrFutures = sequence(
                context.call(TO_STRING_FUNC_NAME, Collections.singletonList(left)),
                context.call(TO_STRING_FUNC_NAME, Collections.singletonList(right)));
        return lrFutures.thenCompose(futures -> {
            StringEvalNode l = (StringEvalNode) futures.get(0);
            StringEvalNode r = (StringEvalNode) futures.get(1);
            return EvalUtils.getValue(l.getValue() + r.getValue());
        });
    });
}

From source file:ru.histone.v2.evaluator.Evaluator.java

private CompletableFuture<EvalNode> processArithmetical(ExpAstNode node, Context context) {
    CompletableFuture<List<EvalNode>> leftRightDone = evalAllNodesOfCurrent(node, context);
    return leftRightDone.thenApply(futures -> {
        EvalNode left = futures.get(0);//  w w  w  .ja  v  a2  s.  c om
        EvalNode right = futures.get(1);

        if ((isNumberNode(left) || left instanceof StringEvalNode)
                && (isNumberNode(right) || right instanceof StringEvalNode)) {
            Float leftValue = getValue(left).orElse(null);
            Float rightValue = getValue(right).orElse(null);
            if (leftValue == null || rightValue == null) {
                return EmptyEvalNode.INSTANCE;
            }

            Float res;
            AstType type = node.getType();
            if (type == AstType.AST_SUB) {
                res = leftValue - rightValue;
            } else if (type == AstType.AST_MUL) {
                res = leftValue * rightValue;
            } else if (type == AstType.AST_DIV) {
                res = leftValue / rightValue;
            } else {
                res = leftValue % rightValue;
            }
            if (res % 1 == 0 && res <= Long.MAX_VALUE) {
                return new LongEvalNode(res.longValue());
            } else {
                return new FloatEvalNode(res);
            }
        }
        return EmptyEvalNode.INSTANCE;
    });
}

From source file:com.android.tradefed.device.NativeDevice.java

/**
 * Parses a partition's available space from the 'table-formatted' output of a toolbox 'df'
 * command, used from gingerbread to lollipop.
 * <p/>// w w  w .j a v  a  2s  .c o m
 * Assumes output format of:
 * <br/>
 * <code>
 * Filesystem             Size   Used   Free   Blksize
 * <br/>
 * [partition]:              3G   790M  2G     4096
 * </code>
 * @param dfOutput the output of df command to parse
 * @return the available space in kilobytes or <code>null</code> if output could not be parsed
 */
Long parseFreeSpaceFromFree(String externalStorePath, String dfOutput) {
    Long freeSpace = null;
    final Pattern freeSpaceTablePattern = Pattern.compile(String.format(
            //fs   Size         Used         Free
            "%s\\s+[\\w\\d\\.]+\\s+[\\w\\d\\.]+\\s+([\\d\\.]+)(\\w)", externalStorePath));
    Matcher tablePatternMatcher = freeSpaceTablePattern.matcher(dfOutput);
    if (tablePatternMatcher.find()) {
        String numericValueString = tablePatternMatcher.group(1);
        String unitType = tablePatternMatcher.group(2);
        try {
            Float freeSpaceFloat = Float.parseFloat(numericValueString);
            if (unitType.equals("M")) {
                freeSpaceFloat = freeSpaceFloat * 1024;
            } else if (unitType.equals("G")) {
                freeSpaceFloat = freeSpaceFloat * 1024 * 1024;
            }
            freeSpace = freeSpaceFloat.longValue();
        } catch (NumberFormatException e) {
            // fall through
        }
    }
    return freeSpace;
}