List of usage examples for java.lang Double intValue
public int intValue()
From source file:net.sbbi.upnp.devices.UPNPRootDevice.java
/** * Parsing an UPNPdevice services list element (<device/serviceList>) in the description XML file * @param device the device object that will store the services list (UPNPService) objects * @param deviceCtx an XPath context for object population * @throws MalformedURLException if some URL provided in the description * file for a service entry is invalid *///from www. j av a 2 s . c o m private void fillUPNPServicesList(UPNPDevice device, JXPathContext deviceCtx) throws MalformedURLException { Pointer serviceListPtr = deviceCtx.getPointer("serviceList"); JXPathContext serviceListCtx = deviceCtx.getRelativeContext(serviceListPtr); Double arraySize = (Double) serviceListCtx.getValue("count( service )"); if (log.isDebugEnabled()) log.debug("device services count is " + arraySize); device.services = new ArrayList(); for (int i = 1; i <= arraySize.intValue(); i++) { Pointer servicePtr = serviceListCtx.getPointer("service[" + i + "]"); JXPathContext serviceCtx = serviceListCtx.getRelativeContext(servicePtr); // TODO possibility of bugs if deviceDefLoc contains a file name URL base = URLBase != null ? URLBase : deviceDefLoc; UPNPService service = new UPNPService(serviceCtx, base, this); device.services.add(service); } }
From source file:net.sbbi.upnp.devices.UPNPRootDevice.java
/** * Parsing an UPNPdevice icons list element (<device/iconList>) in the description XML file * This list can be null//w ww.ja va 2s . c o m * @param device the device object that will store the icons list (DeviceIcon) objects * @param deviceCtx an XPath context for object population * @throws MalformedURLException if some URL provided in the description * file for an icon URL */ private void fillUPNPDeviceIconsList(UPNPDevice device, JXPathContext deviceCtx, URL baseURL) throws MalformedURLException { Pointer iconListPtr; try { iconListPtr = deviceCtx.getPointer("iconList"); } catch (JXPathException ex) { // no pointers for icons list, this can happen // simply returning return; } JXPathContext iconListCtx = deviceCtx.getRelativeContext(iconListPtr); Double arraySize = (Double) iconListCtx.getValue("count( icon )"); if (log.isDebugEnabled()) log.debug("device icons count is " + arraySize); device.deviceIcons = new ArrayList(); for (int i = 1; i <= arraySize.intValue(); i++) { DeviceIcon ico = new DeviceIcon(); ico.mimeType = (String) iconListCtx.getValue("icon[" + i + "]/mimetype"); ico.width = Integer.parseInt((String) iconListCtx.getValue("icon[" + i + "]/width")); ico.height = Integer.parseInt((String) iconListCtx.getValue("icon[" + i + "]/height")); ico.depth = Integer.parseInt((String) iconListCtx.getValue("icon[" + i + "]/depth")); ico.url = getURL((String) iconListCtx.getValue("icon[" + i + "]/url"), baseURL); if (log.isDebugEnabled()) log.debug("icon URL is " + ico.url); device.deviceIcons.add(ico); } }
From source file:org.richfaces.tests.metamer.ftest.AbstractWebDriverTest.java
public static <T extends Number & Comparable<T>> Number countMedian(List<T> values) { assertTrue(values.size() > 0);//from w ww.ja v a2 s . co m if (values.size() == 1) { return values.get(0); } final List<T> copy = Lists.newArrayList(values); Collections.sort(copy); int middleIndex = (copy.size() - 1) / 2; double result = copy.get(middleIndex).doubleValue(); if (copy.size() % 2 == 0) { result = (result + copy.get(middleIndex + 1).doubleValue()) / 2.0; } final Double median = Double.valueOf(result); return new Number() { private static final long serialVersionUID = 1L; @Override public int intValue() { return median.intValue(); } @Override public long longValue() { return median.longValue(); } @Override public float floatValue() { return median.floatValue(); } @Override public double doubleValue() { return median.doubleValue(); } @Override public String toString() { return median.doubleValue() + " from values(sorted) " + copy.toString() + '.'; } }; }
From source file:org.apache.nifi.processors.hadoop.GetHDFS.java
protected void processBatchOfFiles(final List<Path> files, final ProcessContext context, final ProcessSession session) { // process the batch of files InputStream stream = null;/*w w w. java 2 s .com*/ CompressionCodec codec = null; Configuration conf = getConfiguration(); FileSystem hdfs = getFileSystem(); final boolean keepSourceFiles = context.getProperty(KEEP_SOURCE_FILE).asBoolean(); final Double bufferSizeProp = context.getProperty(BUFFER_SIZE).asDataSize(DataUnit.B); int bufferSize = bufferSizeProp != null ? bufferSizeProp.intValue() : conf.getInt(BUFFER_SIZE_KEY, BUFFER_SIZE_DEFAULT); final Path rootDir = new Path(context.getProperty(DIRECTORY).evaluateAttributeExpressions().getValue()); final CompressionType compressionType = CompressionType .valueOf(context.getProperty(COMPRESSION_CODEC).toString()); final boolean inferCompressionCodec = compressionType == CompressionType.AUTOMATIC; if (inferCompressionCodec || compressionType != CompressionType.NONE) { codec = getCompressionCodec(context, getConfiguration()); } final CompressionCodecFactory compressionCodecFactory = new CompressionCodecFactory(conf); for (final Path file : files) { try { if (!hdfs.exists(file)) { continue; // if file is no longer there then move on } final String originalFilename = file.getName(); final String relativePath = getPathDifference(rootDir, file); stream = hdfs.open(file, bufferSize); final String outputFilename; // Check if we should infer compression codec if (inferCompressionCodec) { codec = compressionCodecFactory.getCodec(file); } // Check if compression codec is defined (inferred or otherwise) if (codec != null) { stream = codec.createInputStream(stream); outputFilename = StringUtils.removeEnd(originalFilename, codec.getDefaultExtension()); } else { outputFilename = originalFilename; } FlowFile flowFile = session.create(); final StopWatch stopWatch = new StopWatch(true); flowFile = session.importFrom(stream, flowFile); stopWatch.stop(); final String dataRate = stopWatch.calculateDataRate(flowFile.getSize()); final long millis = stopWatch.getDuration(TimeUnit.MILLISECONDS); flowFile = session.putAttribute(flowFile, CoreAttributes.PATH.key(), relativePath); flowFile = session.putAttribute(flowFile, CoreAttributes.FILENAME.key(), outputFilename); if (!keepSourceFiles && !hdfs.delete(file, false)) { getLogger().warn("Could not remove {} from HDFS. Not ingesting this file ...", new Object[] { file }); session.remove(flowFile); continue; } final String transitUri = (originalFilename.startsWith("/")) ? "hdfs:/" + originalFilename : "hdfs://" + originalFilename; session.getProvenanceReporter().receive(flowFile, transitUri); session.transfer(flowFile, REL_SUCCESS); getLogger().info("retrieved {} from HDFS {} in {} milliseconds at a rate of {}", new Object[] { flowFile, file, millis, dataRate }); session.commit(); } catch (final Throwable t) { getLogger().error("Error retrieving file {} from HDFS due to {}", new Object[] { file, t }); session.rollback(); context.yield(); } finally { IOUtils.closeQuietly(stream); stream = null; } } }
From source file:servlet.F_Function.java
public String SetTableDataReview(String Query1, String Query2) { String data = ""; int k = 0;/*from w w w . j a v a 2 s .co m*/ Double[][] rs1 = SelectD(Query1, 10); Double[][] rs2 = SelectD(Query2, 10); try { for (int i = 0; i < 10; i++) { List<Integer> dataList = new ArrayList<>(); Double target = rs1[0][i]; Double actual = rs2[0][i]; dataList.add(round(target.intValue())); dataList.add(round(actual.intValue())); Double fs; fs = (actual / target) * 100d; if (fs.isNaN()) { fs = 0d; } if (fs.isInfinite()) { fs = -1d; } int persen = round(fs.intValue()); dataList.add(persen); int hasil[] = toPrimitive(dataList.toArray(new Integer[dataList.size()])); String[] a = Arrays.toString(hasil).split("[\\[\\]]")[1].split(", "); DecimalFormat DFor = new java.text.DecimalFormat("#,###;(#,###)"); for (int index = 0; index < a.length; index++) { if (index == a.length - 1) { a[index] = Integer.toString(persen); if (a[index].equals("-1")) { a[index] = a[index].replace("-1", "-"); } else { a[index] += " %"; } } else { a[index] = DFor.format(parseDouble(a[index])); } } data += "<tr>"; data += "<td>" + Desk[k] + "</td>"; data += "<td>Rp. " + a[0] + " </td>"; data += "<td>Rp. " + a[1] + " </td>"; data += "<td> " + a[2] + " </td>"; data += "</tr>"; k++; } } catch (NullPointerException e) { data += "<tr><td>" + null + "</td></tr>"; } return data; }
From source file:net.sbbi.upnp.devices.UPNPRootDevice.java
/** * Parsing an UPNPdevice description element (<device>) in the description XML file * @param device the device object that will be populated * @param parent the device parent object * @param deviceCtx an XPath context for object population * @param baseURL the base URL of the UPNP device * @throws MalformedURLException if some URL provided in the description file is invalid *//*from w w w . j ava 2 s . c o m*/ private void fillUPNPDevice(UPNPDevice device, UPNPDevice parent, JXPathContext deviceCtx, URL baseURL) throws MalformedURLException { device.deviceType = getMandatoryData(deviceCtx, "deviceType"); if (log.isDebugEnabled()) log.debug("parsing device " + device.deviceType); device.friendlyName = getMandatoryData(deviceCtx, "friendlyName"); device.manufacturer = getNonMandatoryData(deviceCtx, "manufacturer"); String base = getNonMandatoryData(deviceCtx, "manufacturerURL"); try { if (base != null) device.manufacturerURL = new URL(base); } catch (java.net.MalformedURLException ex) { // crappy data provided, keep the field null } try { device.presentationURL = getURL(getNonMandatoryData(deviceCtx, "presentationURL"), URLBase); } catch (java.net.MalformedURLException ex) { // crappy data provided, keep the field null } device.modelDescription = getNonMandatoryData(deviceCtx, "modelDescription"); device.modelName = getMandatoryData(deviceCtx, "modelName"); device.modelNumber = getNonMandatoryData(deviceCtx, "modelNumber"); device.modelURL = getNonMandatoryData(deviceCtx, "modelURL"); device.serialNumber = getNonMandatoryData(deviceCtx, "serialNumber"); device.UDN = getMandatoryData(deviceCtx, "UDN"); device.USN = UDN.concat("::").concat(deviceType); String tmp = getNonMandatoryData(deviceCtx, "UPC"); if (tmp != null) { try { device.UPC = Long.parseLong(tmp); } catch (Exception ex) { // non all numeric field provided, non upnp compliant device } } device.parent = parent; fillUPNPServicesList(device, deviceCtx); fillUPNPDeviceIconsList(device, deviceCtx, URLBase); Pointer deviceListPtr; try { deviceListPtr = deviceCtx.getPointer("deviceList"); } catch (JXPathException ex) { // no pointers for this device list, this can happen // if the device has no child devices, simply returning return; } JXPathContext deviceListCtx = deviceCtx.getRelativeContext(deviceListPtr); Double arraySize = (Double) deviceListCtx.getValue("count( device )"); device.childDevices = new ArrayList(); if (log.isDebugEnabled()) log.debug("child devices count is " + arraySize); for (int i = 1; i <= arraySize.intValue(); i++) { Pointer devicePtr = deviceListCtx.getPointer("device[" + i + "]"); JXPathContext childDeviceCtx = deviceListCtx.getRelativeContext(devicePtr); UPNPDevice childDevice = new UPNPDevice(); fillUPNPDevice(childDevice, device, childDeviceCtx, baseURL); if (log.isDebugEnabled()) log.debug("adding child device " + childDevice.getDeviceType()); device.childDevices.add(childDevice); } }
From source file:org.spantus.exp.segment.draw.AbstractGraphGenerator.java
protected void draw(JFreeChart chart, String name, Double widthCoef, Double heightCoef) { Double width = 800 * widthCoef; Double height = 270 * heightCoef; try {/* w ww. ja v a 2 s .c om*/ new File(getGeneratePath()).mkdirs(); String _name = name.replaceAll(":", "_"); _name = _name.replaceAll("^\\s+", "").replaceAll("\\s+$", "").replaceAll("\\s+", "-"); ChartUtilities.saveChartAsPNG(new File(getGeneratePath() + _name + ".png"), chart, width.intValue(), height.intValue()); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.htm.taskinstance.jpa.TaskInstanceFactoryJPA.java
protected int evaluatePriorityQuery(IQuery query, Object context) throws com.htm.exceptions.IllegalArgumentException { /* Query can be null since the priority query is optional */ if (query != null) { // List<?> priority = evaluateXPath(query, context); ///*from w ww. j av a 2 s . c o m*/ // /* // * Obviously exactly one value is expected for priority and it // must // * be a number represented as string. // */ // if (priority.size() == 1 && priority.get(0) instanceof String) { // String priorityAsString = (String) priority.get(0); // log.debug("Evaluating priority query - Determined value is '" // + priorityAsString + "'. " // + "Try to create integer from this value."); // return Integer.valueOf(priorityAsString); // } else { // log.debug("Evaluating priority query - No value could be determined during evaluation."); // } // XPATH Number by default is mapped to Double int priority; Double tmpPriority; try { tmpPriority = evaluateXPath(Double.class, query, context); if (tmpPriority != null) { priority = tmpPriority.intValue(); } else { log.debug("priority is null - Default priority value '" + PRIORITY_DEFAULT + "' is used."); priority = PRIORITY_DEFAULT; } log.debug("Evaluating priority query - Determined value is '" + priority + "'."); } catch (com.htm.exceptions.IllegalArgumentException e) { log.error("Cannot evaluate priority query - Default priority value '" + PRIORITY_DEFAULT + "' is used.", e); priority = PRIORITY_DEFAULT; } return priority; } else { log.debug("Evaluating priority query - No priority query was specified"); } log.debug("Evaluating priority query - Default priority value '" + PRIORITY_DEFAULT + "' is used."); /* * If the query has failed for some reason return the default value for * priority */ return PRIORITY_DEFAULT; }
From source file:de.innovationgate.utils.URLBuilder.java
private String rebuildQuery() { Map<String, Object> rebuildParameters = getRebuildParameters(); Iterator<String> paramKeys = rebuildParameters.keySet().iterator(); String paramSeparator = "&"; StringBuffer paramString = new StringBuffer(); String key;//from w ww . j av a 2s . co m Object value; // may be a List while (paramKeys.hasNext()) { key = paramKeys.next().toString(); value = rebuildParameters.get(key); List<Object> values = new ArrayList<Object>(); if (value instanceof List) values.addAll((List) value); // add all values else values.add(value); // add single value try { if (_encoding != null) key = URIUtil.encodeWithinQuery(key, _encoding); for (Object o : values) { if (paramString.length() > 0) { paramString.append(paramSeparator); } paramString.append(key); if (o == null) continue; // special handling of INT values: if (o instanceof Double) { Double _o = (Double) o; if (_o == _o.intValue()) { // is Integer? o = _o.intValue(); } } String v = o.toString(); if (_encoding != null) v = URIUtil.encodeWithinQuery(v, _encoding); if (v != null && !v.trim().equals("")) { paramString.append("="); paramString.append(v); } } } catch (Exception e) { throw new RuntimeException(e); } } if (paramString.length() > 0) { return "?" + paramString.toString(); } else { return ""; } }
From source file:org.jahia.utils.maven.plugin.contentgenerator.wise.FileAndFolderService.java
public void generateFolders(String docspaceName, ExportBO wiseExport) { docspaceName = StringUtils.lowerCase(docspaceName); // (N^L-1) / (N-1) * N double nbNodes = wiseExport.getNbFoldersPerLevel().doubleValue(); double depth = wiseExport.getFoldersDepth().doubleValue(); Double totalFolders = Math.pow(nbNodes, depth) - 1; totalFolders = totalFolders / (nbNodes - 1); totalFolders = totalFolders * nbNodes; Double totalFiles = totalFolders * wiseExport.getNbFilesPerFolder(); logger.info("Folders generation is starting, " + totalFolders.intValue() + " folders to create, containing a total of " + totalFiles.intValue() + " files."); String currentPath = initializeContentFolder(wiseExport.getOutputDir() + sep + "wise", wiseExport.getSiteKey(), docspaceName); String currentNodePath = "/" + "sites" + "/" + wiseExport.getSiteKey() + "/" + "files" + "/" + "docspaces" + "/" + docspaceName; // if there is not enough physical files available // we'll take them all and stop Integer nbFilesAvailable = wiseExport.getFileNames().size(); if (wiseExport.getNbFilesPerFolder().compareTo(nbFilesAvailable) > 0) { logger.warn(/*from w w w . j a v a 2 s .c o m*/ "You asked for " + wiseExport.getNbFilesPerFolder() + " files per folder, but there are only " + nbFilesAvailable + " files in the pool, and we can't use them twice."); wiseExport.setNbFilesPerFolder(nbFilesAvailable); } // create temporary folders to serialize files and folders objects created File tmpTopFoldersDir = new File(ExportBO.tmp + sep + ContentGeneratorCst.TMP_DIR_TOP_FOLDERS); tmpTopFoldersDir.mkdir(); File tmpFilesDir = new File(ExportBO.tmp + sep + ContentGeneratorCst.TMP_DIR_WISE_FILES); tmpFilesDir.mkdir(); // initialize date range difference for random creation date startTimestamp = wiseExport.getStartCreationDateRange().getTime(); long endTimestamp = wiseExport.getEndCreationDateRange().getTime(); timestampDifference = endTimestamp - startTimestamp; generateFolders(1, currentPath, currentNodePath, wiseExport); }