List of usage examples for java.lang Double longValue
public long longValue()
From source file:org.webcurator.core.harvester.coordinator.BandwidthCalculatorImpl.java
/** * Calculate the allocated bandwith for a list of target instances that have a * no bandwidth percentage override set. * @param aResults he result list to populate * @param aStandardTIs the target instances to calaculate for * @param aRemainingBandwidth tha amount of bandwidth to split between these target instances *///from w w w. j av a 2 s .co m private static void processStandardTargetInstances(HashMap<Long, TargetInstance> aResults, ArrayList<TargetInstance> aStandardTIs, double aRemainingBandwidth) { if (aStandardTIs == null || aStandardTIs.isEmpty()) { return; } TargetInstance ti = null; Double allocatedbw = null; Iterator it = aStandardTIs.iterator(); while (it.hasNext()) { ti = (TargetInstance) it.next(); allocatedbw = new Double(aRemainingBandwidth / aStandardTIs.size()); ti.setAllocatedBandwidth(new Long(allocatedbw.longValue())); aResults.put(ti.getOid(), ti); } }
From source file:de.iteratec.svg.SvgGraphicWriter.java
/** * Scales down the width used to set the size of a resulting raster image export. * The width is scaled down so that the product of width and height does not exceed * the value given by the RASTER_TRANSCODER_MAX_AREA. This is necessary, so that * image transcoding does not throw an exception and no heap space issues occur. * //from w w w . j a v a 2s . co m * @param width * The original width of the SVG graphic. * @param height * The original height of the SVG graphic. */ private static void setScaledImageTranscoderDimensions(ImageTranscoder transcoder, Double width, Double height) { if (width != null && height != null) { long scaledWidth = width.longValue(); long scaledHeight = height.longValue(); if (scaledHeight * scaledWidth > RASTER_TRANSCODER_MAX_AREA) { double aspectRatio = (double) scaledHeight / scaledWidth; while (scaledHeight * scaledWidth > RASTER_TRANSCODER_MAX_AREA) { scaledWidth = scaledWidth - RASTER_TRANSCODER_STEP; scaledHeight = (long) Math.ceil(scaledWidth * aspectRatio); } } transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, Float.valueOf(scaledWidth)); transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, Float.valueOf(scaledHeight)); } }
From source file:org.webcurator.core.harvester.coordinator.BandwidthCalculatorImpl.java
/** * Calculate the allocated bandwith for a list of target instances that have a * bandwidth percentage override set.//from w w w .j av a 2 s .c o m * @param aResults the result list to populate * @param aBandwidthPercentTIs the target instances to calaculate for * @param aRemainingBandwidth the amount of bandwith that can be allowcated * @param aMaxBandwidthPercent the max percent of the bandwidth that can be allocated * @return the remaining amount of bandwidth after these allocations */ private static double processSpecialTargetInstances(HashMap<Long, TargetInstance> aResults, ArrayList<TargetInstance> aBandwidthPercentTIs, long aRemainingBandwidth, int aMaxBandwidthPercent) { if (aBandwidthPercentTIs == null || aBandwidthPercentTIs.isEmpty()) { return aRemainingBandwidth; } double maxbw = aRemainingBandwidth; double remainingbw = aRemainingBandwidth; double maxAllocateableBW = (maxbw * (aMaxBandwidthPercent / 100d)); TargetInstance ti = null; Double allocatedbw = null; if (aBandwidthPercentTIs.size() == 1) { ti = aBandwidthPercentTIs.iterator().next(); allocatedbw = new Double(maxbw * (ti.getBandwidthPercent() / 100d)); remainingbw -= allocatedbw.doubleValue(); ti.setAllocatedBandwidth(new Long(allocatedbw.longValue())); aResults.put(ti.getOid(), ti); } else { Iterator it = null; // Check the target instance for a percentage allocation. double totalBWPercents = 0; if (!aBandwidthPercentTIs.isEmpty()) { it = aBandwidthPercentTIs.iterator(); while (it.hasNext()) { ti = (TargetInstance) it.next(); totalBWPercents += ti.getBandwidthPercent().intValue(); } } it = aBandwidthPercentTIs.iterator(); while (it.hasNext()) { ti = (TargetInstance) it.next(); allocatedbw = new Double(maxAllocateableBW * (ti.getBandwidthPercent() / totalBWPercents)); remainingbw -= allocatedbw.doubleValue(); ti.setAllocatedBandwidth(new Long(allocatedbw.longValue())); aResults.put(ti.getOid(), ti); } } return remainingbw; }
From source file:net.intelliant.util.UtilCommon.java
/** * UtilDateTime.addDaysToTimestamp(Timestamp start, Double days) type-casts input into integer resulting in loss. * @return a <code>Timestamp</code> value *//*from ww w .j av a2 s . c om*/ public static Timestamp addDaysToTimestamp(Timestamp start, Double days) { return new Timestamp(start.getTime() + ((long) (24 * 60 * 60 * 1000 * days.longValue()))); }
From source file:org.apache.pig.impl.util.CastUtils.java
public static Long stringToLong(String str) { if (str == null) { return null; } else {//from ww w . ja v a2 s. c o m try { return Long.parseLong(str); } catch (NumberFormatException e) { // It's possible that this field can be interpreted as a double. // Unfortunately Java doesn't handle this in Long.valueOf. So // we need to try to convert it to a double and if that works // then // go to an long. try { Double d = Double.valueOf(str); // Need to check for an overflow error if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) { LogUtils.warn(CastUtils.class, "Value " + d + " too large for long", PigWarning.TOO_LARGE_FOR_INT, mLog); return null; } return Long.valueOf(d.longValue()); } catch (NumberFormatException nfe2) { LogUtils.warn(CastUtils.class, "Unable to interpret value " + str + " in field being " + "converted to long, caught NumberFormatException <" + nfe2.getMessage() + "> field discarded", PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, mLog); return null; } } } }
From source file:org.opencastproject.comments.CommentParser.java
private static Comment commentFromManifest(Node commentNode, UserDirectoryService userDirectoryService) throws UnsupportedElementException { try {/*ww w . j a va2 s . c o m*/ // id Long id = null; Double idAsDouble = ((Number) xpath.evaluate("@id", commentNode, XPathConstants.NUMBER)).doubleValue(); if (!idAsDouble.isNaN()) id = idAsDouble.longValue(); // text String text = (String) xpath.evaluate("text/text()", commentNode, XPathConstants.STRING); // Author Node authorNode = (Node) xpath.evaluate("author", commentNode, XPathConstants.NODE); User author = userFromManifest(authorNode, userDirectoryService); // ResolvedStatus Boolean resolved = BooleanUtils .toBoolean((Boolean) xpath.evaluate("@resolved", commentNode, XPathConstants.BOOLEAN)); // Reason String reason = (String) xpath.evaluate("reason/text()", commentNode, XPathConstants.STRING); if (StringUtils.isNotBlank(reason)) reason = reason.trim(); // CreationDate String creationDateString = (String) xpath.evaluate("creationDate/text()", commentNode, XPathConstants.STRING); Date creationDate = new Date(DateTimeSupport.fromUTC(creationDateString)); // ModificationDate String modificationDateString = (String) xpath.evaluate("modificationDate/text()", commentNode, XPathConstants.STRING); Date modificationDate = new Date(DateTimeSupport.fromUTC(modificationDateString)); // Create comment Comment comment = Comment.create(Option.option(id), text.trim(), author, reason, resolved, creationDate, modificationDate); // Replies NodeList replyNodes = (NodeList) xpath.evaluate("replies/reply", commentNode, XPathConstants.NODESET); for (int i = 0; i < replyNodes.getLength(); i++) { comment.addReply(replyFromManifest(replyNodes.item(i), userDirectoryService)); } return comment; } catch (XPathExpressionException e) { throw new UnsupportedElementException("Error while reading comment information from manifest", e); } catch (Exception e) { if (e instanceof UnsupportedElementException) throw (UnsupportedElementException) e; throw new UnsupportedElementException( "Error while reading comment creation or modification date information from manifest", e); } }
From source file:org.opencastproject.comments.CommentParser.java
private static CommentReply replyFromManifest(Node commentReplyNode, UserDirectoryService userDirectoryService) throws UnsupportedElementException { try {//from www . j a va2s . c om // id Long id = null; Double idAsDouble = ((Number) xpath.evaluate("@id", commentReplyNode, XPathConstants.NUMBER)) .doubleValue(); if (!idAsDouble.isNaN()) id = idAsDouble.longValue(); // text String text = (String) xpath.evaluate("text/text()", commentReplyNode, XPathConstants.STRING); // Author Node authorNode = (Node) xpath.evaluate("author", commentReplyNode, XPathConstants.NODE); User author = userFromManifest(authorNode, userDirectoryService); // CreationDate String creationDateString = (String) xpath.evaluate("creationDate/text()", commentReplyNode, XPathConstants.STRING); Date creationDate = new Date(DateTimeSupport.fromUTC(creationDateString)); // ModificationDate String modificationDateString = (String) xpath.evaluate("modificationDate/text()", commentReplyNode, XPathConstants.STRING); Date modificationDate = new Date(DateTimeSupport.fromUTC(modificationDateString)); // Create reply return CommentReply.create(Option.option(id), text.trim(), author, creationDate, modificationDate); } catch (XPathExpressionException e) { throw new UnsupportedElementException("Error while reading comment reply information from manifest", e); } catch (Exception e) { if (e instanceof UnsupportedElementException) throw (UnsupportedElementException) e; throw new UnsupportedElementException( "Error while reading comment reply creation or modification date information from manifest", e); } }
From source file:com.github.jessemull.microflex.util.DoubleUtil.java
/** * Converts a list of doubles to a list of longs. * @param List<Double> list of doubles * @return list of longs *//*from w w w . java2s .co m*/ public static List<Long> toLongList(List<Double> list) { List<Long> longList = new ArrayList<Long>(); for (Double val : list) { if (!OverFlowUtil.longOverflow(val)) { OverFlowUtil.overflowError(val); } longList.add(val.longValue()); } return longList; }
From source file:utils.LocoUtils.java
public static Long stringToLong(String str) { if (str == null) { return null; } else {//from w w w.j ava2 s . c o m try { return Long.parseLong(str); } catch (NumberFormatException e) { // It's possible that this field can be interpreted as a double. // Unfortunately Java doesn't handle this in Long.valueOf. So // we need to try to convert it to a double and if that works // then // go to an long. try { Double d = Double.valueOf(str); // Need to check for an overflow error if (d.doubleValue() > mMaxLong.doubleValue() + 1.0) { Logger.warn(TAG + "|Value " + d + " too large for long"); return null; } return Long.valueOf(d.longValue()); } catch (NumberFormatException nfe2) { Logger.warn(TAG + "|Unable to interpret value " + str + " in field being " + "converted to long, caught NumberFormatException <" + nfe2.getMessage() + "> field discarded"); return null; } } } }
From source file:com.meltmedia.cadmium.core.github.ApiClient.java
public static List<Long> getAuthorizationIds(String username, String password) throws Exception { HttpClient client = createStaticHttpClient(); List<Long> authIds = new ArrayList<Long>(); try {/*from ww w .j ava 2 s .co m*/ int limitRemain = getRateLimitRemain(null, client); if (limitRemain > 0) { HttpGet get = new HttpGet("https://api.github.com/authorizations"); setupBasicAuth(username, password, get); HttpResponse response = null; try { response = client.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { List<Map<String, Object>> auths = new Gson().fromJson( EntityUtils.toString(response.getEntity()), new TypeToken<List<Map<String, Object>>>() { }.getType()); if (auths != null && auths.size() > 0) { for (Map<String, Object> auth : auths) { if (auth != null && auth.containsKey("id")) { Double id = (Double) auth.get("id"); authIds.add(id.longValue()); } } } } else { EntityUtils.consume(response.getEntity()); } } finally { get.releaseConnection(); if (response != null) { try { ((CloseableHttpResponse) response).close(); } catch (IOException e) { } } } } else { throw new Exception("Request is rate limited."); } } finally { if (client != null) { try { ((CloseableHttpClient) client).close(); } catch (Throwable t) { } } } return authIds; }