List of usage examples for java.lang Integer doubleValue
public double doubleValue()
From source file:com.act.analysis.surfactant.SurfactantAnalysis.java
/** * Compute features related to the logP-labeled molecular surface computed by MarvinSpace. * @param jFrame A jFrame to use when running MarvinSpace (seems strange but is requred). * @param hydrogensShareNeighborsLogP Set to true if hydrogen atoms should share their neighbor's logP value. * @return A map of features related to and depending on the computed molecular surface. * @throws Exception/*from ww w.j a va2 s . c om*/ */ public Map<FEATURES, Double> computeSurfaceFeatures(JFrame jFrame, boolean hydrogensShareNeighborsLogP) throws Exception { // TODO: use the proper marvin sketch scene to get better rendering control instead of MSpaceEasy. MSpaceEasy mspace = new MSpaceEasy(1, 2, true); mspace.addCanvas(jFrame.getContentPane()); mspace.setSize(1200, 600); ArrayList<Double> logPVals = new ArrayList<>(); ArrayList<Double> hValues = new ArrayList<>(); // Store a list of ids so we can label the atoms in the surface rendering (otherwise we won't know what's what). ArrayList<Integer> ids = new ArrayList<>(); MolAtom[] atoms = mol.getAtomArray(); for (int i = 0; i < mol.getAtomCount(); i++) { ids.add(i); Double logP = plugin.getAtomlogPIncrement(i); logPVals.add(logP); /* The surface renderer requires that we specify logP values for all hydrogens, which don't appear to have logP * contributions calculated for them, in addition to non-hydrogen atoms. We fake this by either borrowing the * hydrogen's neighbor's logP value, or setting it to 0.0. * TODO: figure out what the command-line marvin sketch logP renderer does and do that instead. * */ MolAtom molAtom = mol.getAtom(i); for (int j = 0; j < molAtom.getImplicitHcount(); j++) { // Note: the logPPlugin's deprecated getAtomlogPHIncrement method just uses the non-H neighbor's logP, as here. // msketch seems to do something different, but it's unclear what that is. hValues.add(hydrogensShareNeighborsLogP ? logP : 0.0); } } /* Tack the hydrogen's logP contributions on to the list of proper logP values. The MSC renderer seems to expect * the hydrogen's values after the non-hydrogen's values, so appending appears to work fine. */ logPVals.addAll(hValues); // Compute the planes before rendering to avoid the addition of implicit hydrogens in the calculation. // TODO: re-strip hydrogens after rendering to avoid these weird issues in general. Map<Integer, Pair<List<Integer>, List<Integer>>> splitPlanes = splitAtomsByNormalPlanes(); MoleculeComponent mc1 = mspace.addMoleculeTo(mol, 0); mspace.getEventHandler().createAtomLabels(mc1, ids); // Don't draw hydrogens; it makes the drawing too noisy. mspace.setProperty("MacroMolecule.Hydrogens", "false"); MoleculeComponent mc2 = mspace.addMoleculeTo(mol, 1); MolecularSurfaceComponent msc = mspace.computeSurface(mc2); SurfaceComponent sc = msc.getSurface(); // Note: if we call mol.getAtomArray() here, it will contain all the implicit hydrogens. Map<Integer, Integer> surfaceComponentCounts = new HashMap<>(); for (int i = 0; i < atoms.length; i++) { surfaceComponentCounts.put(i, 0); } for (int i = 0; i < sc.getVertexCount(); i++) { DPoint3 c = new DPoint3(sc.getVertexX(i), sc.getVertexY(i), sc.getVertexZ(i)); Double closestDist = null; Integer closestAtom = null; for (int j = 0; j < atoms.length; j++) { double dist = c.distance(atoms[j].getLocation()); if (closestDist == null || closestDist > dist) { closestDist = dist; closestAtom = j; } } surfaceComponentCounts.put(closestAtom, surfaceComponentCounts.get(closestAtom) + 1); } // Build a line of (proj(p, lv), logP) pairs. List<Pair<Double, Double>> weightedVals = new ArrayList<>(); for (int i = 0; i < atoms.length; i++) { Integer count = surfaceComponentCounts.get(i); Double logP = plugin.getAtomlogPIncrement(i); Double x = distancesAlongLongestVector.get(i); Double y = count.doubleValue() * logP; // Ditch non-contributing atoms. if (y < -0.001 || y > 0.001) { weightedVals.add(Pair.of(x, y)); } } Collections.sort(weightedVals); Pair<Double, Double> slopeIntercept = performRegressionOverXYPairs(weightedVals); double valAtFarthestPoint = distancesAlongLongestVector.get(lvIndex2) * slopeIntercept.getLeft() + slopeIntercept.getRight(); Map<FEATURES, Double> features = new HashMap<>(); features.put(FEATURES.REG_WEIGHTED_SLOPE, slopeIntercept.getLeft()); features.put(FEATURES.REG_WEIGHTED_INTERCEPT, slopeIntercept.getRight()); features.put(FEATURES.REG_VAL_AT_FARTHEST_POINT, valAtFarthestPoint); /* Multiply the intercept with the value at the largest point to see if there's a sign change. If so, we'll * get a negative number and know the regression line crosses the axis. */ features.put(FEATURES.REG_CROSSES_X_AXIS, valAtFarthestPoint * slopeIntercept.getRight() < 0.000 ? 1.0 : 0.0); // Flatten the list of split planes and find the "best" one (i.e. the one that maximizes the weighted logP delta). List<AtomSplit> allSplitPlanes = new ArrayList<>(); for (int i = 0; i < atoms.length; i++) { if (!splitPlanes.containsKey(i)) { continue; } Pair<List<Integer>, List<Integer>> splitAtoms = splitPlanes.get(i); List<Integer> leftAtoms = splitAtoms.getLeft(); List<Integer> rightAtoms = splitAtoms.getRight(); Pair<AtomSplit, AtomSplit> splitVariants = AtomSplit.computePlaneSplitsForIntersectingAtom(leftAtoms, rightAtoms, i, plugin, surfaceComponentCounts); AtomSplit l = splitVariants.getLeft(); AtomSplit r = splitVariants.getRight(); allSplitPlanes.add(l); allSplitPlanes.add(r); } Pair<AtomSplit, Map<FEATURES, Double>> bestPsRes = findBestPlaneSplitFeatures(allSplitPlanes); features.putAll(bestPsRes.getRight()); msc.setPalette(SurfaceColoring.COLOR_MAPPER_BLUE_TO_RED); msc.showVolume(true); // These parameters were selected via experimentation. msc.setSurfacePrecision("High"); msc.setSurfaceType("van der Waals"); msc.setDrawProperty("Surface.DrawType", "Dot"); msc.setDrawProperty("Surface.Quality", "High"); msc.setAtomPropertyList(logPVals); msc.setDrawProperty("Surface.ColorType", "AtomProperty"); // Don't display here--leave that to the owner of the JFrame. return features; }
From source file:com.ottogroup.bi.streaming.operator.json.statsd.StatsdExtractedMetricsReporter.java
/** * Extracts and reports a gauge value/*from w w w .ja v a2s .c o m*/ * @param metricCfg * The field configuration providing information on how to access and export content from JSON. Value is expected not to be null * @param json * The {@link JSONObject} to extract information from. Value is expected not to be null */ protected void reportGauge(final StatsdMetricConfig metricCfg, final JSONObject json) { String path = null; if (metricCfg.getDynamicPathPrefix() != null) { try { String dynPathPrefix = this.jsonUtils.getTextFieldValue(json, metricCfg.getDynamicPathPrefix().getPath(), false); if (StringUtils.isNotBlank(dynPathPrefix)) path = dynPathPrefix + (!StringUtils.endsWith(dynPathPrefix, ".") ? "." : "") + metricCfg.getPath(); else path = metricCfg.getPath(); } catch (Exception e) { // do nothing path = metricCfg.getPath(); } } else { path = metricCfg.getPath(); } if (metricCfg.getJsonRef().getContentType() == JsonContentType.INTEGER) { try { final Integer value = this.jsonUtils.getIntegerFieldValue(json, metricCfg.getJsonRef().getPath()); if (value != null) this.statsdClient.gauge(path, (metricCfg.getScaleFactor() != 1 ? value.longValue() * metricCfg.getScaleFactor() : value.longValue())); } catch (Exception e) { // do nothing } } else if (metricCfg.getJsonRef().getContentType() == JsonContentType.DOUBLE) { try { final Double value = this.jsonUtils.getDoubleFieldValue(json, metricCfg.getJsonRef().getPath()); if (value != null) this.statsdClient.gauge(path, (metricCfg.getScaleFactor() != 1 ? (long) (value.doubleValue() * metricCfg.getScaleFactor()) : value.longValue())); } catch (Exception e) { // do nothing } } }
From source file:com.ottogroup.bi.streaming.operator.json.statsd.StatsdExtractedMetricsReporter.java
/** * Extracts and reports a counter value/*w ww . j a v a2 s . c om*/ * @param metricCfg * The field configuration providing information on how to access and export content from JSON. Value is expected not to be null * @param json * The {@link JSONObject} to extract information from. Value is expected not to be null */ protected void reportCounter(final StatsdMetricConfig metricCfg, final JSONObject json) { String path = null; if (metricCfg.getDynamicPathPrefix() != null) { try { String dynPathPrefix = this.jsonUtils.getTextFieldValue(json, metricCfg.getDynamicPathPrefix().getPath(), false); if (StringUtils.isNotBlank(dynPathPrefix)) path = dynPathPrefix + (!StringUtils.endsWith(dynPathPrefix, ".") ? "." : "") + metricCfg.getPath(); else path = metricCfg.getPath(); } catch (Exception e) { // do nothing path = metricCfg.getPath(); } } else { path = metricCfg.getPath(); } if (!metricCfg.isReportDelta()) { this.statsdClient.incrementCounter(path); return; } if (metricCfg.getJsonRef().getContentType() == JsonContentType.INTEGER) { try { final Integer value = this.jsonUtils.getIntegerFieldValue(json, metricCfg.getJsonRef().getPath()); if (value != null) this.statsdClient.count(path, (metricCfg.getScaleFactor() != 1 ? value.longValue() * metricCfg.getScaleFactor() : value.longValue())); } catch (Exception e) { // do nothing } } else if (metricCfg.getJsonRef().getContentType() == JsonContentType.DOUBLE) { try { final Double value = this.jsonUtils.getDoubleFieldValue(json, metricCfg.getJsonRef().getPath()); if (value != null) this.statsdClient.count(path, (metricCfg.getScaleFactor() != 1 ? (long) (value.doubleValue() * metricCfg.getScaleFactor()) : value.longValue())); } catch (Exception e) { // do nothing } } }
From source file:org.jgap.gp.function.AddAndStoreTerminal.java
public void execute_void(ProgramChromosome c, int n, Object[] args) { check(c);/* ww w . j av a 2s . c o m*/ if (m_type == CommandGene.IntegerClass) { int value = c.execute_int(n, 0, args); Integer oldValue = (Integer) getGPConfiguration().readFromMemoryIfExists(m_storageName); if (oldValue != null) { value = value + oldValue.intValue(); } // Store in memory. // ---------------- getGPConfiguration().storeInMemory(m_storageName, new Integer(value)); } else if (m_type == CommandGene.LongClass) { long value = c.execute_long(n, 0, args); Long oldValue = (Long) getGPConfiguration().readFromMemoryIfExists(m_storageName); if (oldValue != null) { value = value + oldValue.longValue(); } getGPConfiguration().storeInMemory(m_storageName, new Long(value)); } else if (m_type == CommandGene.DoubleClass) { double value = c.execute_double(n, 0, args); Double oldValue = (Double) getGPConfiguration().readFromMemoryIfExists(m_storageName); if (oldValue != null) { value = value + oldValue.doubleValue(); } getGPConfiguration().storeInMemory(m_storageName, new Double(value)); } else if (m_type == CommandGene.FloatClass) { float value = c.execute_float(n, 0, args); Float oldValue = (Float) getGPConfiguration().readFromMemoryIfExists(m_storageName); if (oldValue != null) { value = value + oldValue.floatValue(); } getGPConfiguration().storeInMemory(m_storageName, new Float(value)); } else { throw new IllegalStateException("Type " + m_type + " unknown"); } }
From source file:org.madsonic.controller.StreamController.java
protected Dimension getSuitableVideoSize(Integer existingWidth, Integer existingHeight, Integer maxBitRate) { if (maxBitRate == null) { return new Dimension(400, 300); }// w ww. ja va 2 s. c o m int w, h; if (maxBitRate < 400) { w = 400; h = 300; } else if (maxBitRate < 600) { w = 480; h = 360; } else if (maxBitRate < 1800) { w = 640; h = 480; } else { w = 960; h = 720; } if (existingWidth == null || existingHeight == null) { return new Dimension(w, h); } if (existingWidth < w || existingHeight < h) { return new Dimension(even(existingWidth), even(existingHeight)); } double aspectRate = existingWidth.doubleValue() / existingHeight.doubleValue(); h = (int) Math.round(w / aspectRate); return new Dimension(even(w), even(h)); }
From source file:com.mbv.web.rest.controller.DeliveryController.java
public Double mul(Integer value1, String value2, Integer scale) { if (scale < 0) { throw new IllegalArgumentException("The scale must be a positive integer or zero"); }/*from ww w . j a va2s . c o m*/ BigDecimal b1 = new BigDecimal(Double.toString(value1.doubleValue())); BigDecimal b2 = new BigDecimal(value2); return DoubleUtil.round(b1.multiply(b2).doubleValue(), scale); }
From source file:com.aba.industry.manufacturing.impl.ManufacturingCalculatorImpl.java
@Override public BuildCalculationResult calculateBuildCost(SystemCostIndexes costIndexes, Double taxMultiplier, BlueprintData bpData, Integer meLevel, Integer teLevel, IndustrySkillConfiguration industrySkills) { BuildCalculationResult result = new BuildCalculationResult(); result.setSkillConfiguration(industrySkills); /*/*w ww .j a va 2s . c o m*/ * for (materialid in blueprintData['activityMaterials'][1]) { * material=blueprintData['activityMaterials'][1][materialid]; * reducedquantity=material.quantity*(1-(me/100))*facilityme[facility]*(1-(teamMe/100)); */ List<ActivityMaterialWithCost> materialsReduced = new ArrayList<>(); Double materialCost = 0d; Double runCost = 0d; for (ActivityMaterialWithCost material : bpData.getActivityMaterials() .get(IndustryActivities.MANUFACTURING.getActivityId())) { ActivityMaterialWithCost materialReduced = new ActivityMaterialWithCost(); materialReduced.setBlueprintTypeId(material.getBlueprintTypeId()); materialReduced.setCost(material.getCost()); materialReduced.setAdjustedCost(material.getAdjustedCost()); materialReduced.setName(material.getName()); materialReduced.setQuantity(Math.round(material.getQuantity() * (1 - (meLevel.doubleValue() / 100)) /* * facility.getFacilityMe()*/ )); materialReduced.setSource(material.getSource()); materialReduced.setTypeId(material.getTypeId()); materialsReduced.add(materialReduced); materialCost += materialReduced.getCost() * materialReduced.getQuantity(); runCost += materialReduced.getAdjustedCost() == null ? 0d : materialReduced.getAdjustedCost() * material.getQuantity(); } result.setMaterialCost(materialCost); result.setMaterialsWithCost(materialsReduced); runCost = (runCost * costIndexes.getCostIndexes().get(IndustryActivities.MANUFACTURING.getActivityId())) * taxMultiplier; //buildTime=blueprintData.blueprintDetails.times[1]*(1-(te/100))*(1-((industry*4)/100))*(1-((aindustry*3) // /100))*facilityte[facility]*runs*dcmultiplier; Long buildTime = Math.round(bpData.getBlueprintDetails().getTimesInSeconds() .get(IndustryActivities.MANUFACTURING.getActivityId()) * (1 - (teLevel.doubleValue() / 100d)) * (1 - ((industrySkills.getIndustrySkillLevel().doubleValue() * 4) / 100d)) * (1 - ((industrySkills.getAdvancedIndustrySkillLevel().doubleValue() * 3d) / 100d))); result.setInstallationFees(runCost); result.setInstallationTax(runCost * .1d); result.setSeconds(buildTime); result.setProductId(bpData.getBlueprintDetails().getProductTypeId()); return result; }
From source file:org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils.java
/** * Update the variant context chromosome counts info fields (AC, AN, AF) * * @param calledAltAlleles number of called alternate alleles for all genotypes * @param calledAlleles number of called alleles for all genotypes * @param builder builder for variant context * @throws IllegalArgumentException if calledAltAlleles or builder are null *///from w ww. jav a 2s. c o m public static void updateChromosomeCountsInfo(final Map<Allele, Integer> calledAltAlleles, final int calledAlleles, final VariantContextBuilder builder) { if (calledAltAlleles == null) throw new IllegalArgumentException("Called alternate alleles can not be null"); if (builder == null) throw new IllegalArgumentException("Variant context builder can not be null"); builder.attribute(VCFConstants.ALLELE_COUNT_KEY, calledAltAlleles.values().toArray()) .attribute(VCFConstants.ALLELE_NUMBER_KEY, calledAlleles); // Add AF is there are called alleles if (calledAlleles != 0) { final Set<Double> alleleFrequency = new LinkedHashSet<Double>(calledAltAlleles.size()); for (final Integer value : calledAltAlleles.values()) { alleleFrequency.add(value.doubleValue() / calledAlleles); } builder.attribute(VCFConstants.ALLELE_FREQUENCY_KEY, alleleFrequency.toArray()); } }
From source file:net.sourceforge.subsonic.service.metadata.FFmpegParser.java
/** * Parses meta data for the given music file. No guessing or reformatting is done. * * * @param file The music file to parse.//w w w . j ava 2 s. c o m * @return Meta data for the file. */ @Override public MetaData getRawMetaData(File file) { MetaData metaData = new MetaData(); try { File ffmpeg = new File(transcodingService.getTranscodeDirectory(), "ffmpeg"); String[] command = new String[] { ffmpeg.getAbsolutePath(), "-i", file.getAbsolutePath() }; Process process = Runtime.getRuntime().exec(command); InputStream stdout = process.getInputStream(); InputStream stderr = process.getErrorStream(); // Consume stdout, we're not interested in that. new InputStreamReaderThread(stdout, "ffmpeg", true).start(); // Read everything from stderr. It will contain text similar to: // Input #0, avi, from 'foo.avi': // Duration: 00:00:33.90, start: 0.000000, bitrate: 2225 kb/s // Stream #0.0: Video: mpeg4, yuv420p, 352x240 [PAR 1:1 DAR 22:15], 29.97 fps, 29.97 tbr, 29.97 tbn, 30k tbc // Stream #0.1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s String[] lines = StringUtil.readLines(stderr); Integer width = null; Integer height = null; Double par = 1.0; for (String line : lines) { Matcher matcher = DURATION_PATTERN.matcher(line); if (matcher.find()) { int hours = Integer.parseInt(matcher.group(1)); int minutes = Integer.parseInt(matcher.group(2)); int seconds = Integer.parseInt(matcher.group(3)); metaData.setDurationSeconds(hours * 3600 + minutes * 60 + seconds); } matcher = BITRATE_PATTERN.matcher(line); if (matcher.find()) { metaData.setBitRate(Integer.valueOf(matcher.group(1))); } matcher = DIMENSION_PATTERN.matcher(line); if (matcher.find()) { width = Integer.valueOf(matcher.group(1)); height = Integer.valueOf(matcher.group(2)); } // PAR = Pixel Aspect Rate matcher = PAR_PATTERN.matcher(line); if (matcher.find()) { int a = Integer.parseInt(matcher.group(1)); int b = Integer.parseInt(matcher.group(2)); if (a > 0 && b > 0) { par = (double) a / (double) b; } } } if (width != null && height != null) { width = (int) Math.round(width.doubleValue() * par); metaData.setWidth(width); metaData.setHeight(height); } } catch (Throwable x) { LOG.warn("Error when parsing metadata in " + file, x); } return metaData; }