List of usage examples for java.lang Double Double
@Deprecated(since = "9") public Double(String s) throws NumberFormatException
From source file:org.jfree.data.DefaultMeterDataset.java
/** * Default constructor. */ public DefaultMeterDataset() { this(new Double(0), new Double(0), null, null); }
From source file:com.jdom.junit.utils.AbstractFixture.java
/** * Get a randomized value.//from www . ja va 2 s. c o m * * @param value * the value to randomize * @param salt * the randomizer to use * @return the randomized value */ public static Double getSaltedValue(Double value, int salt) { Double retValue; if (salt == 0) { retValue = value; } else { retValue = new Double(value.doubleValue() * salt * salt / 2 + DOUBLE_FACTOR); } return retValue; }
From source file:nz.co.senanque.listfunctions.HeapMonitorTest.java
@Test public void test1() throws Exception { ValidationSession validationSession = m_validationEngine.createSession(); Customer customer = m_customerDAO.createCustomer(); validationSession.bind(customer);//from w ww . j a v a 2 s .c o m logger.debug(validationSession.getStats()); customer.setMinInvoiceCount(0); Invoice invoice = new Invoice(); invoice.setAmount(130); customer.getInvoices().add(invoice); logger.debug(validationSession.getStats()); long j = customer.getInvoiceCount(); assertEquals(1, j); invoice = new Invoice(); invoice.setAmount(130); customer.getInvoices().add(invoice); logger.debug(validationSession.getStats()); j = customer.getInvoiceCount(); assertEquals(2, j); invoice = new Invoice(); invoice.setAmount(130); customer.getInvoices().add(invoice); logger.debug(validationSession.getStats()); j = customer.getInvoiceCount(); assertEquals(3, j); invoice = new Invoice(); invoice.setAmount(200); invoice.setTestBoolean(true); customer.getInvoices().add(invoice); logger.debug(validationSession.getStats()); j = customer.getInvoiceCount(); assertEquals(4, j); assertEquals(new Double(590.0), new Double(customer.getAmount())); assertEquals(true, customer.isAnytrue()); assertEquals(false, customer.isAlltrue()); assertEquals(1, customer.getCount()); for (Invoice inv : customer.getInvoices()) { inv.setTestBoolean(true); } assertEquals(true, customer.isAnytrue()); assertEquals(4, customer.getCount()); assertEquals(true, customer.isAlltrue()); for (Invoice inv : customer.getInvoices()) { inv.setTestBoolean(false); } assertEquals(false, customer.isAnytrue()); assertEquals(false, customer.isAlltrue()); assertEquals(0, customer.getCount()); assertEquals(4, customer.getInvoiceCount()); Invoice inv = customer.getInvoices().get(0); customer.getInvoices().remove(inv); j = customer.getInvoiceCount(); logger.debug(validationSession.getStats()); assertEquals(3, j); customer.getInvoices().clear(); j = customer.getInvoiceCount(); logger.debug(validationSession.getStats()); assertEquals(0, j); validationSession.close(); }
From source file:de.unidue.ltl.flextag.core.reports.CvAvgPerWordClassReport.java
public void execute() throws Exception { StorageService storageService = getContext().getStorageService(); for (TaskContextMetadata subcontext : getSubtasks()) { if (TcTaskTypeUtil.isCrossValidationTask(storageService, subcontext.getId())) { File attributes = storageService.locateKey(subcontext.getId(), "ATTRIBUTES.txt"); List<String> foldersOfSingleRuns = getFoldersOfSingleRuns(attributes); List<String> mla = new ArrayList<>(); for (String context : foldersOfSingleRuns) { if (TcTaskTypeUtil.isMachineLearningAdapterTask(storageService, context)) { mla.add(context);/*from www . j a va 2s . c o m*/ } } for (String mlaContext : mla) { File locateKey = storageService.locateKey(mlaContext, Constants.ID_OUTCOME_KEY); Map<String, WordClass> wcPerformances = getWcPerformances(locateKey); for (String key : wcPerformances.keySet()) { WordClass wc = wcPerformances.get(key); List<WordClass> list = map.get(key); if (list == null) { list = new ArrayList<>(); } list.add(wc); map.put(key, list); } } StringBuilder sb = new StringBuilder(); sb.append(String.format("%20s\t%8s\t%5s\n", "PoS", "Occr.", "Acc")); List<String> keySet = new ArrayList<>(map.keySet()); Collections.sort(keySet); for (String k : keySet) { List<WordClass> list = map.get(k); Double N = new Double(0); double acc = 0; for (WordClass wc : list) { N += wc.getN(); acc += (wc.getCorrect() / wc.getN()); } N /= list.size(); acc /= list.size(); sb.append( String.format("%20s\t%8d\t%5s\n", k, N.intValue(), String.format("%3.1f", acc * 100))); } File locateKey = storageService.locateKey(subcontext.getId(), OUTPUT_FILE); FileUtils.writeStringToFile(locateKey, sb.toString(), "utf-8"); } } }
From source file:de.mat.utils.pdftools.PdfSort4Print.java
public static void sortPdfPages(String pdfSourceFile, String pdfDestinationFile, int perPage) throws Exception { PdfImportedPage page = null;//w w w . jav a2s . c o m if (perPage != 2 && perPage != 4) { throw new IllegalArgumentException( "Sorry, perPage must only be " + "2 or 4. All other is not implemented yet :-("); } // ####### // # fill to odd pagecount // ####### // create reader PdfReader readerOrig = new PdfReader(pdfSourceFile); // calc data int countPage = readerOrig.getNumberOfPages(); int blaetter = new Double(Math.ceil((countPage + 0.0) / perPage / 2)).intValue(); int zielPages = (blaetter * perPage * 2) - countPage; if (LOGGER.isInfoEnabled()) LOGGER.info("CurPages: " + countPage + " Blaetter:" + blaetter + " AddPage:" + zielPages); // add sites String oddFile = pdfDestinationFile + ".filled.pdf"; PdfStamper stamper = new PdfStamper(readerOrig, new FileOutputStream(oddFile)); // add empty pages for (int i = 1; i <= zielPages; i++) { if (LOGGER.isDebugEnabled()) LOGGER.debug("addEmptyPage: " + i); stamper.insertPage(readerOrig.getNumberOfPages() + 1, readerOrig.getPageSizeWithRotation(1)); } stamper.close(); readerOrig.close(); // ######## // # read new odd document and sort pages // ######## // step 1: create new reader PdfReader readerOdd = new PdfReader(oddFile); // create writerSorted String sortedFile = pdfDestinationFile; Document documentSorted = new Document(readerOrig.getPageSizeWithRotation(1)); PdfCopy writerSorted = new PdfCopy(documentSorted, new FileOutputStream(sortedFile)); documentSorted.open(); // add pages in calced order List<Integer> lstPageNr = new ArrayList<Integer>(); int pageCount = readerOdd.getNumberOfPages(); int startseite = 1; for (int i = 1; i <= blaetter; i++) { if (perPage == 2) { startseite = ((i - 1) * perPage) + 1; if (LOGGER.isDebugEnabled()) LOGGER.debug("Blatt:" + i + " Startseite: " + startseite); // front top lstPageNr.add(new Integer(pageCount - startseite + 1)); // front bottom lstPageNr.add(new Integer(startseite)); // back top lstPageNr.add(new Integer(startseite + 1)); // back bottom lstPageNr.add(new Integer(pageCount - startseite + 1 - 1)); } else if (perPage == 4) { startseite = ((i - 1) * perPage) + 1; if (LOGGER.isDebugEnabled()) LOGGER.debug("Blatt:" + i + " Startseite: " + startseite); // front top left lstPageNr.add(new Integer(pageCount - startseite + 1)); // front top right lstPageNr.add(new Integer(startseite)); // front bottom lefts lstPageNr.add(new Integer(pageCount - startseite + 1 - 2)); // front bottom right lstPageNr.add(new Integer(startseite + 2)); // back top left lstPageNr.add(new Integer(startseite + 1)); // back top right lstPageNr.add(new Integer(pageCount - startseite + 1 - 1)); // back bottom left lstPageNr.add(new Integer(startseite + 1 + 2)); // back bottom right lstPageNr.add(new Integer(pageCount - startseite + 1 - 1 - 2)); } else { throw new IllegalArgumentException( "Sorry, perPage must " + "only be 2 or 4. All other is not implemented yet :-("); } } if (LOGGER.isInfoEnabled()) LOGGER.info("Seiten:" + lstPageNr.size()); // copy pages for (Iterator iter = lstPageNr.iterator(); iter.hasNext();) { int pageNum = ((Integer) iter.next()).intValue(); if (LOGGER.isDebugEnabled()) LOGGER.debug("addSortPage: " + pageNum); page = writerSorted.getImportedPage(readerOdd, pageNum); writerSorted.addPage(page); } // close everything documentSorted.close(); writerSorted.close(); readerOdd.close(); // delete Tmp-File File file = new File(oddFile); file.delete(); }
From source file:it.cnr.isti.smartfed.test.DatacenterFacilities.java
public static List<FederationDatacenter> getNormalDistribution(int numOfDatacenters, int numHost) { Random r = new Random(13213); int core_variance = maxNumOfCores - minNumOfCores; int delta_cores = core_variance > 0 ? r.nextInt(core_variance) : 0; List<FederationDatacenter> list = new ArrayList<FederationDatacenter>(); NormalDistribution nd = new NormalDistribution(numOfDatacenters / 2d, numOfDatacenters / 4d); // System.out.println("Aa"+numHost); for (int i = 0; i < numOfDatacenters; i++) { // create the virtual processor (PE) List<Pe> peList = new ArrayList<Pe>(); int mips = 25000; for (int j = 0; j < minNumOfCores + delta_cores; j++) { peList.add(new Pe(j, new PeProvisionerSimple(mips))); }/*w ww . j a va 2s . c o m*/ // create the hosts List<Host> hostList = new ArrayList<Host>(); HostProfile prof = HostProfile.getDefault(); prof.set(HostParams.RAM_AMOUNT_MB, 16 * 1024 + ""); int num; if (numOfDatacenters == 1) { num = numHost; } else { Double value = new Double(nd.density(i)) * numHost; num = value.intValue(); } if (num < 1) num = 1; for (int k = 0; k < num; k++) { hostList.add(HostFactory.get(prof, peList)); } // create the storage List<Storage> storageList = new ArrayList<Storage>(); // if empty, no SAN attached // create the datacenters list.add(FederationDatacenterFactory.getDefault(hostList, storageList)); } return list; }
From source file:org.jfree.data.KeyedObjects2DTest.java
/** * Serialize an instance, restore it, and check for equality. *//*ww w. j av a2 s. co m*/ @Test public void testSerialization() { KeyedObjects2D ko2D1 = new KeyedObjects2D(); ko2D1.addObject(new Double(234.2), "Row1", "Col1"); ko2D1.addObject(null, "Row1", "Col2"); ko2D1.addObject(new Double(345.9), "Row2", "Col1"); ko2D1.addObject(new Double(452.7), "Row2", "Col2"); KeyedObjects2D ko2D2 = (KeyedObjects2D) TestUtilities.serialised(ko2D1); assertEquals(ko2D1, ko2D2); }
From source file:net.sf.reportengine.core.calc.TestCalculators.java
@Test public void testUniversalSumCalculator() { SumGroupCalculator calculator = new SumGroupCalculator(); assertTrue(calculator.init() instanceof DefaultCalcIntermResult); assertTrue(calculator.init().getResult() instanceof BigDecimal); assertEquals(calculator.init().getResult(), BigDecimal.ZERO); DefaultCalcIntermResult<BigDecimal> testIntermResult = new DefaultCalcIntermResult<BigDecimal>( BigDecimal.ZERO);/*from ww w. ja v a 2 s.c om*/ DefaultCalcIntermResult<BigDecimal> newResult = calculator.compute(testIntermResult, "1"); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertEquals(newResult.getResult(), new BigDecimal(1)); testIntermResult = newResult; newResult = calculator.compute(testIntermResult, Integer.valueOf(7)); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertEquals(newResult.getResult(), new BigDecimal(8)); testIntermResult = new DefaultCalcIntermResult<BigDecimal>(BigDecimal.ZERO); newResult = calculator.compute(testIntermResult, new BigDecimal(1.18907)); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertTrue(newResult.getResult().doubleValue() == 1.18907D); testIntermResult = new DefaultCalcIntermResult<BigDecimal>(new BigDecimal(1.18907)); newResult = calculator.compute(testIntermResult, new Double(2.3)); assertNotNull(newResult); assertNotNull(newResult.getResult()); assertTrue(newResult.getResult().doubleValue() == 3.48907); }
From source file:com.almende.pi5.lch.DERSimAgent.java
/** * Repeat user events.//from w w w.ja va2s. co m */ @Access(AccessType.PUBLIC) public void repeatUserEvents() { if (doUserEvents) { doUserEvent(); schedule("repeatUserEvents", null, DateTime.now().plusSeconds(new Double(Math.random() * 30).intValue())); } }
From source file:reports.util.BarChartScriptlet.java
public void afterDetailEval() throws JRScriptletException { super.afterDetailEval(); String label = ""; Double values[][] = null;//from w w w .ja v a2s . co m String rows[] = null; String cols[] = null; Iterator list = this.fieldsMap.values().iterator(); Iterator vlist = this.variablesMap.values().iterator(); rows = new String[] { "row1", "row2", "row3", "row4", "row5", "row6", "row7" }; cols = new String[] { "col1", "col2", "col3", "col4", "col5", "col6", "col7" }; values = new Double[][] { { new Double(1), new Double(2), new Double(3), new Double(4), new Double(5), new Double(6), new Double(7) }, { new Double(11), new Double(12), new Double(13), new Double(14), new Double(15), new Double(16), new Double(17) }, { new Double(21), new Double(22), new Double(23), new Double(24), new Double(25), new Double(26), new Double(27) }, { new Double(31), new Double(32), new Double(33), new Double(34), new Double(35), new Double(36), new Double(37) }, { new Double(41), new Double(42), new Double(43), new Double(44), new Double(45), new Double(46), new Double(47) }, { new Double(51), new Double(52), new Double(53), new Double(54), new Double(55), new Double(56), new Double(57) }, { new Double(61), new Double(62), new Double(63), new Double(64), new Double(65), new Double(66), new Double(67) } }; //dataset.addValue(value1, series1, category1); for (int i = 0; i < rows.length; i++) { String series = rows[i]; for (int j = 0; j < cols.length; j++) { String category = cols[j]; Double value = values[i][j]; dataset.addValue(value, series, category); System.out.println(series + " = " + category + " = " + value); } } System.out.println("============="); }