List of usage examples for org.apache.commons.lang3.mutable MutableDouble MutableDouble
public MutableDouble(final String value) throws NumberFormatException
From source file:com.quinsoft.epamms.mSPLDef_Object.java
public int omSPLDef_ComputeTopPositions(View mSPLDef) { double LastBlockTopPosition = 0.0; //:DECIMAL LastSubBlockTopPosition double LastSubBlockTopPosition = 0.0; int RESULT = 0; double dTempDecimal_0 = 0.0; double dTempDecimal_1 = 0.0; double dTempDecimal_2 = 0.0; double dTempDecimal_3 = 0.0; double dTempDecimal_4 = 0.0; double dTempDecimal_5 = 0.0; //:// Calculate the Top position for each Block and SubBlock. SubBlock positions are relative //:// to the parent Block //:// If the Top Position is specified, we'll use it. Otherwise, we'll use the last position of the //:// previous Block or SubBlock entry plust its Height. //:FOR EACH mSPLDef.LLD_Panel WITHIN mSPLDef.SubregPhysicalLabelDef RESULT = SetCursorFirstEntity(mSPLDef, "LLD_Panel", "SubregPhysicalLabelDef"); while (RESULT > zCURSOR_UNCHANGED) { //:LastBlockTopPosition = 0 LastBlockTopPosition = 0;/*from w w w . j av a2 s . c om*/ //:FOR EACH mSPLDef.LLD_Block RESULT = SetCursorFirstEntity(mSPLDef, "LLD_Block", ""); while (RESULT > zCURSOR_UNCHANGED) { //:IF mSPLDef.LLD_Block.Top != "" if (CompareAttributeToString(mSPLDef, "LLD_Block", "Top", "") != 0) { //:mSPLDef.LLD_Block.wComputedTopPosition = mSPLDef.LLD_Block.Top SetAttributeFromAttribute(mSPLDef, "LLD_Block", "wComputedTopPosition", mSPLDef, "LLD_Block", "Top"); //:LastBlockTopPosition = mSPLDef.LLD_Block.Top + mSPLDef.LLD_Block.Height { MutableDouble md_dTempDecimal_0 = new MutableDouble(dTempDecimal_0); GetDecimalFromAttribute(md_dTempDecimal_0, mSPLDef, "LLD_Block", "Top"); dTempDecimal_0 = md_dTempDecimal_0.doubleValue(); } { MutableDouble md_dTempDecimal_1 = new MutableDouble(dTempDecimal_1); GetDecimalFromAttribute(md_dTempDecimal_1, mSPLDef, "LLD_Block", "Height"); dTempDecimal_1 = md_dTempDecimal_1.doubleValue(); } LastBlockTopPosition = dTempDecimal_0 + dTempDecimal_1; //:ELSE } else { //:mSPLDef.LLD_Block.wComputedTopPosition = LastBlockTopPosition SetAttributeFromDecimal(mSPLDef, "LLD_Block", "wComputedTopPosition", LastBlockTopPosition); //:LastBlockTopPosition = LastBlockTopPosition + mSPLDef.LLD_Block.Height { MutableDouble md_dTempDecimal_2 = new MutableDouble(dTempDecimal_2); GetDecimalFromAttribute(md_dTempDecimal_2, mSPLDef, "LLD_Block", "Height"); dTempDecimal_2 = md_dTempDecimal_2.doubleValue(); } LastBlockTopPosition = LastBlockTopPosition + dTempDecimal_2; } //:END //:LastSubBlockTopPosition = 0 LastSubBlockTopPosition = 0; //:FOR EACH mSPLDef.LLD_SubBlock RESULT = SetCursorFirstEntity(mSPLDef, "LLD_SubBlock", ""); while (RESULT > zCURSOR_UNCHANGED) { //:IF mSPLDef.LLD_SubBlock.Top != "" if (CompareAttributeToString(mSPLDef, "LLD_SubBlock", "Top", "") != 0) { //:mSPLDef.LLD_SubBlock.wComputedTopPosition = mSPLDef.LLD_SubBlock.Top SetAttributeFromAttribute(mSPLDef, "LLD_SubBlock", "wComputedTopPosition", mSPLDef, "LLD_SubBlock", "Top"); //:LastSubBlockTopPosition = mSPLDef.LLD_SubBlock.Top + mSPLDef.LLD_SubBlock.Height { MutableDouble md_dTempDecimal_3 = new MutableDouble(dTempDecimal_3); GetDecimalFromAttribute(md_dTempDecimal_3, mSPLDef, "LLD_SubBlock", "Top"); dTempDecimal_3 = md_dTempDecimal_3.doubleValue(); } { MutableDouble md_dTempDecimal_4 = new MutableDouble(dTempDecimal_4); GetDecimalFromAttribute(md_dTempDecimal_4, mSPLDef, "LLD_SubBlock", "Height"); dTempDecimal_4 = md_dTempDecimal_4.doubleValue(); } LastSubBlockTopPosition = dTempDecimal_3 + dTempDecimal_4; //:ELSE } else { //:mSPLDef.LLD_SubBlock.wComputedTopPosition = LastSubBlockTopPosition SetAttributeFromDecimal(mSPLDef, "LLD_SubBlock", "wComputedTopPosition", LastSubBlockTopPosition); //:LastSubBlockTopPosition = LastSubBlockTopPosition + mSPLDef.LLD_SubBlock.Height { MutableDouble md_dTempDecimal_5 = new MutableDouble(dTempDecimal_5); GetDecimalFromAttribute(md_dTempDecimal_5, mSPLDef, "LLD_SubBlock", "Height"); dTempDecimal_5 = md_dTempDecimal_5.doubleValue(); } LastSubBlockTopPosition = LastSubBlockTopPosition + dTempDecimal_5; } RESULT = SetCursorNextEntity(mSPLDef, "LLD_SubBlock", ""); //:END } RESULT = SetCursorNextEntity(mSPLDef, "LLD_Block", ""); //:END } RESULT = SetCursorNextEntity(mSPLDef, "LLD_Panel", "SubregPhysicalLabelDef"); //:END } //:END return (0); // END }
From source file:org.apache.apex.malhar.lib.window.accumulation.SumDouble.java
@Override public MutableDouble defaultAccumulatedValue() { return new MutableDouble(0.0); }
From source file:org.apache.apex.malhar.lib.window.accumulation.SumTest.java
@Test public void SumTest() { SumInt si = new SumInt(); SumLong sl = new SumLong(); SumFloat sf = new SumFloat(); SumDouble sd = new SumDouble(); Assert.assertEquals(new MutableInt(10), si.accumulate(si.defaultAccumulatedValue(), 10)); Assert.assertEquals(new MutableInt(11), si.accumulate(new MutableInt(1), 10)); Assert.assertEquals(new MutableInt(22), si.merge(new MutableInt(1), new MutableInt(21))); Assert.assertEquals(new MutableLong(10L), sl.accumulate(sl.defaultAccumulatedValue(), 10L)); Assert.assertEquals(new MutableLong(22L), sl.accumulate(new MutableLong(2L), 20L)); Assert.assertEquals(new MutableLong(41L), sl.merge(new MutableLong(32L), new MutableLong(9L))); Assert.assertEquals(new MutableFloat(9.0F), sf.accumulate(sf.defaultAccumulatedValue(), 9.0F)); Assert.assertEquals(new MutableFloat(22.5F), sf.accumulate(new MutableFloat(2.5F), 20F)); Assert.assertEquals(new MutableFloat(41.0F), sf.merge(new MutableFloat(33.1F), new MutableFloat(7.9F))); Assert.assertEquals(new MutableDouble(9.0), sd.accumulate(sd.defaultAccumulatedValue(), 9.0)); Assert.assertEquals(new MutableDouble(22.5), sd.accumulate(new MutableDouble(2.5), 20.0)); Assert.assertEquals(new MutableDouble(41.0), sd.merge(new MutableDouble(33.1), new MutableDouble(7.9))); }
From source file:org.apache.pulsar.broker.loadbalance.impl.OverloadShedder.java
/** * Attempt to shed some bundles off every broker which is overloaded. * * @param loadData//from w w w. j ava 2 s. c o m * The load data to used to make the unloading decision. * @param conf * The service configuration. * @return A map from bundles to unload to the brokers on which they are loaded. */ public Multimap<String, String> findBundlesForUnloading(final LoadData loadData, final ServiceConfiguration conf) { selectedBundlesCache.clear(); final double overloadThreshold = conf.getLoadBalancerBrokerOverloadedThresholdPercentage() / 100.0; final Map<String, Long> recentlyUnloadedBundles = loadData.getRecentlyUnloadedBundles(); // Check every broker and select loadData.getBrokerData().forEach((broker, brokerData) -> { final LocalBrokerData localData = brokerData.getLocalData(); final double currentUsage = localData.getMaxResourceUsage(); if (currentUsage < overloadThreshold) { if (log.isDebugEnabled()) { log.debug("[{}] Broker is not overloaded, ignoring at this point", broker); } return; } // We want to offload enough traffic such that this broker will go below the overload threshold // Also, add a small margin so that this broker won't be very close to the threshold edge. double percentOfTrafficToOffload = currentUsage - overloadThreshold + ADDITIONAL_THRESHOLD_PERCENT_MARGIN; double brokerCurrentThroughput = localData.getMsgThroughputIn() + localData.getMsgThroughputOut(); double minimumThroughputToOffload = brokerCurrentThroughput * percentOfTrafficToOffload; log.info( "Attempting to shed load on {}, which has max resource usage above threshold {}% > {}% -- Offloading at least {} MByte/s of traffic", broker, currentUsage, overloadThreshold, minimumThroughputToOffload / 1024 / 1024); MutableDouble trafficMarkedToOffload = new MutableDouble(0); MutableBoolean atLeastOneBundleSelected = new MutableBoolean(false); if (localData.getBundles().size() > 1) { // Sort bundles by throughput, then pick the biggest N which combined make up for at least the minimum throughput to offload loadData.getBundleData().entrySet().stream().map((e) -> { // Map to throughput value // Consider short-term byte rate to address system resource burden String bundle = e.getKey(); BundleData bundleData = e.getValue(); TimeAverageMessageData shortTermData = bundleData.getShortTermData(); double throughput = shortTermData.getMsgThroughputIn() + shortTermData.getMsgThroughputOut(); return Pair.of(bundle, throughput); }).filter(e -> { // Only consider bundles that were not already unloaded recently return !recentlyUnloadedBundles.containsKey(e.getLeft()); }).sorted((e1, e2) -> { // Sort by throughput in reverse order return Double.compare(e2.getRight(), e1.getRight()); }).forEach(e -> { if (trafficMarkedToOffload.doubleValue() < minimumThroughputToOffload || atLeastOneBundleSelected.isFalse()) { selectedBundlesCache.put(broker, e.getLeft()); trafficMarkedToOffload.add(e.getRight()); atLeastOneBundleSelected.setTrue(); } }); } else if (localData.getBundles().size() == 1) { log.warn( "HIGH USAGE WARNING : Sole namespace bundle {} is overloading broker {}. " + "No Load Shedding will be done on this broker", localData.getBundles().iterator().next(), broker); } else { log.warn("Broker {} is overloaded despite having no bundles", broker); } }); return selectedBundlesCache; }
From source file:org.matsim.contrib.parking.parkingsearch.evaluation.ParkedVehiclesVisualiser.java
@Override public void handleEvent(PersonLeavesVehicleEvent event) { vehicleParkingPosition.put(event.getVehicleId(), new Tuple<Id<Link>, MutableDouble>( lastLink.get(event.getVehicleId()), new MutableDouble(event.getTime()))); }
From source file:org.matsim.contrib.parking.parkingsearch.evaluation.ParkingSlotVisualiser.java
private void initialize(Map<Id<ActivityFacility>, ActivityFacility> parkingFacilities) { Map<Id<Link>, MutableDouble> nrOfSlotsPerLink = new HashMap<Id<Link>, MutableDouble>(); for (ActivityFacility fac : parkingFacilities.values()) { Id<Link> linkId = fac.getLinkId(); if (nrOfSlotsPerLink.containsKey(linkId)) { nrOfSlotsPerLink.get(linkId) .add(fac.getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity()); } else {// ww w .j a v a 2 s . com nrOfSlotsPerLink.put(linkId, new MutableDouble( fac.getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity())); } } for (Id<Link> linkID : nrOfSlotsPerLink.keySet()) { // Logger.getLogger(getClass()).info("initialize parking visualisation for link " + linkID); this.slotsOnLink.put(linkID, new ParkingSlotManager(network.getLinks().get(linkID), nrOfSlotsPerLink.get(linkID).intValue())); } }
From source file:ru.org.linux.tag.TagCloudDao.java
public List<TagDTO> getTags(int tagcount) { String sql = "select value,counter from tags_values where counter>=10 order by counter desc limit ?"; final MutableDouble maxc = new MutableDouble(1); final MutableDouble minc = new MutableDouble(-1); List<TagDTO> result = jdbcTemplate.query(sql, (rs, rowNum) -> { TagDTO result1 = new TagDTO(); result1.setValue(rs.getString("value")); double counter = Math.log(rs.getInt("counter")); result1.setCounter(counter);//w ww . jav a2s.c o m if (maxc.doubleValue() < counter) { maxc.setValue(counter); } if (minc.doubleValue() < 0 || counter < minc.doubleValue()) { minc.setValue(counter); } return result1; }, tagcount); if (minc.doubleValue() < 0) { minc.setValue(0); } result.forEach(tag -> tag.setWeight((int) Math .round(10 * (tag.getCounter() - minc.doubleValue()) / (maxc.doubleValue() - minc.doubleValue())))); Collections.sort(result); return result; }