/** * Get a path from the local FS. If size is known, we go round-robin over the set of disks (via * the configured dirs) and return the first complete path which has enough space. * * <p>If size is not known, use roulette selection -- pick directories with probability * proportional to their available space. */ public synchronized Path getLocalPathForWrite( String pathStr, long size, Configuration conf, boolean checkWrite) throws IOException { confChanged(conf); int numDirs = localDirsPath.length; int numDirsSearched = 0; // remove the leading slash from the path (to make sure that the uri // resolution results in a valid path on the dir being checked) if (pathStr.startsWith("/")) { pathStr = pathStr.substring(1); } Path returnPath = null; Path path = new Path(pathStr); if (size == SIZE_UNKNOWN) { // do roulette selection: pick dir with probability // proportional to available size long[] availableOnDisk = new long[dirDF.length]; long totalAvailable = 0; // build the "roulette wheel" for (int i = 0; i < dirDF.length; ++i) { availableOnDisk[i] = dirDF[i].getAvailable(); totalAvailable += availableOnDisk[i]; } // Keep rolling the wheel till we get a valid path Random r = new java.util.Random(); while (numDirsSearched < numDirs && returnPath == null) { long randomPosition = Math.abs(r.nextLong()) % totalAvailable; int dir = 0; while (randomPosition > availableOnDisk[dir]) { randomPosition -= availableOnDisk[dir]; dir++; } dirNumLastAccessed = dir; returnPath = createPath(path, checkWrite); if (returnPath == null) { totalAvailable -= availableOnDisk[dir]; availableOnDisk[dir] = 0; // skip this disk numDirsSearched++; } } } else { while (numDirsSearched < numDirs && returnPath == null) { long capacity = dirDF[dirNumLastAccessed].getAvailable(); if (capacity > size) { returnPath = createPath(path, checkWrite); } dirNumLastAccessed++; dirNumLastAccessed = dirNumLastAccessed % numDirs; numDirsSearched++; } } if (returnPath != null) { return returnPath; } // no path found throw new DiskErrorException("Could not find any valid local " + "directory for " + pathStr); }
public void testIdentityCalculator() throws Exception { execute("CRUD.new"); assertNoErrors(); setValue("number", "-1"); // needed in this case because 0 is an existing key setValue("name", "JUNIT COLOR " + (int) (Math.random() * 200)); execute("TypicalNotResetOnSave.save"); assertNoErrors(); String last = getValue("number"); execute("CRUD.new"); assertNoErrors(); setValue("number", "-1"); // needed in this case because 0 is an existing key setValue("name", "JUNIT COLOR " + (int) (Math.random() * 200)); execute("TypicalNotResetOnSave.save"); assertNoErrors(); String next = String.valueOf(Integer.parseInt(last) + 1); assertValue("number", next); }
void numRecStats(byte[] record, int start, int len) throws IOException { numRec_++; if (numRec_ == nextStatusRec_) { String recordStr = new String(record, start, Math.min(len, statusMaxRecordChars_), "UTF-8"); nextStatusRec_ += 100; // *= 10; String status = getStatus(recordStr); LOG.info(status); reporter_.setStatus(status); } }
private int[] getWidths(TableModel tableModel) { int[] widths = new int[tableModel.getColumnCount()]; for (int r = 0; r < Math.min(tableModel.getRowCount(), 500); r++) { // 500 is not for performance, but for using only a sample of data with huge table for (int c = 0; c < tableModel.getColumnCount(); c++) { Object o = tableModel.getValueAt(r, c); if (o instanceof String) { String s = ((String) o).trim(); if (s.length() > widths[c]) widths[c] = s.length(); } } } return widths; }
public void setUp() throws Exception { String time = String.valueOf((new Date()).getTime()).substring(8); String random = String.valueOf(Math.random()).substring(2); unique = (time + random); serviceName = "javaTastyTest-" + unique; JTastyDAO dao = new JTastyMockDAO(); TastyBean tb = new TastyBean(); tb.setDao(dao); tc = new TastyClient(tastyServerUrl, serviceName); tc.setTastyBean(tb); logger.debug(tastyServerUrl + "/service/" + serviceName); // create the service: tc.post(tastyServerUrl + "/service/" + serviceName); // add the user: tc.beanstatus(); }
public GaussianDistribution(double[] values) { // Logger.getAnonymousLogger().info(String.valueOf(values.length)); // 1. mean double sum = 0; for (double v : values) sum += v; this.mean = sum / values.length; // System.out.println(this.mean); // 2. variance double[] deltas = values.clone(); for (int i = 0; i < values.length; i++) { double diff = values[i] - this.mean; deltas[i] = diff * diff; } sum = 0; for (double v : deltas) sum += v; this.variance = sum / (values.length - 1); // 3. standard deviation this.standardDeviation = Math.sqrt(this.variance); }
public double probability(Double value) { double expArg = -.5 * (value - mean) * (value - mean) / variance; return Math.pow(2. * Math.PI * variance, -.5) * Math.exp(expArg); }
public GaussianDistribution(double mean, double deviance) { this.mean = mean; this.variance = deviance; this.standardDeviation = Math.sqrt(deviance); }