List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:dbseer.gui.frame.DBSeerPlotPresetFrame.java
public DBSeerPlotPresetFrame(String[] chartNames, DBSeerDataSet dataset) { this.setTitle("DBSeer Visualization"); this.chartNames = chartNames; this.dataset = dataset; this.isInitSuccess = true; numCharts = chartNames.length;/* w w w. j a v a 2 s .c o m*/ numChartInRow = (int) Math.ceil(Math.sqrt(numCharts)); try { initializeGUI(); } catch (Exception e) { e.printStackTrace(); this.isInitSuccess = false; } }
From source file:de.upb.wdqa.wdvd.revisiontags.SHA1Converter.java
private static String getBase(int base, byte[] bytes) { String result;//from w w w . j a v a 2s . c om if (bytes != null) { if (bytes.length != 0) { BigInteger bi = new BigInteger(1, bytes); String tmp = bi.toString(base); int numberOfDigits = (int) Math.ceil(160.0 / (Math.log(base) / Math.log(2.0))); result = StringUtils.leftPad(tmp, numberOfDigits, '0'); } else { result = ""; } } else { result = null; } return result; }
From source file:bb.mcmc.analysis.ConvergeStatUtils.java
protected static <T> T[] thinWindow(T[] array, int kthin) { if (kthin == 1) { return array; } else {//from ww w . jav a 2 s . c om final int count = (int) Math.ceil(array.length / (double) kthin); final Class<?> type = array.getClass().getComponentType(); @SuppressWarnings("unchecked") // OK, because array is of type T final T[] newArray = (T[]) Array.newInstance(type, count); for (int i = 0; i < newArray.length; i++) { newArray[i] = array[kthin * i]; } return newArray; } }
From source file:ldbc.snb.datagen.generator.distribution.utils.Bucket.java
public static ArrayList<Bucket> bucketizeHistogram(ArrayList<Pair<Integer, Integer>> histogram, int num_buckets) { ArrayList<Bucket> buckets = new ArrayList<Bucket>(); int population = 0; int num_edges = 0; for (Pair<Integer, Integer> i : histogram) { population += i.getValue();/*from w w w . jav a2 s. c o m*/ num_edges += i.getValue() * i.getKey(); } num_edges /= 2; int avgDegreeAt1B = 200; int avgDegree = num_edges / population; double aCoeff = Math.log(avgDegreeAt1B) / Math.log(1000000000); double bCoeff = (aCoeff - (Math.log(avgDegree) / Math.log(population))) / Math.log10(population); int target_mean = (int) Math.round( Math.pow(DatagenParams.numPersons, (aCoeff - bCoeff * Math.log10(DatagenParams.numPersons)))); System.out.println("Distribution mean degree: " + avgDegree + " Distribution target mean " + target_mean); int bucket_size = (int) (Math.ceil(population / (double) (num_buckets))); int current_histogram_index = 0; int current_histogram_left = histogram.get(current_histogram_index).getValue(); for (int i = 0; i < num_buckets && (current_histogram_index < histogram.size()); ++i) { int current_bucket_count = 0; int min = population; int max = 0; while (current_bucket_count < bucket_size && current_histogram_index < histogram.size()) { int degree = histogram.get(current_histogram_index).getKey(); min = degree < min ? degree : min; max = degree > max ? degree : max; if ((bucket_size - current_bucket_count) > current_histogram_left) { current_bucket_count += current_histogram_left; current_histogram_index++; if (current_histogram_index < histogram.size()) { current_histogram_left = histogram.get(current_histogram_index).getValue(); } } else { current_histogram_left -= (bucket_size - current_bucket_count); current_bucket_count = bucket_size; } } min = (int) (min * target_mean / (double) avgDegree); max = (int) (max * target_mean / (double) avgDegree); buckets.add(new Bucket(min, max)); } return buckets; }
From source file:IK.G.java
public static double ceil(double in) { return Math.ceil(in); }
From source file:ml.shifu.shifu.core.binning.NativeBinning.java
@Override public List<Double> getDataBin() { QuickSort.sort(array);/*from w w w . ja va 2 s. c o m*/ int actualBinSize = (int) Math.ceil((double) array.size() / (double) expectedBinningNum); int actualBiningNum = this.expectedBinningNum; List<Double> binBoundary = new ArrayList<Double>(); binBoundary.add(Double.NEGATIVE_INFINITY); double prevData = array.get(0); int currBinSize = 0; int currBinIndex = 0; for (int i = 0; i < array.size(); i++) { double currData = array.get(i); currBinSize++; if (currBinSize >= actualBinSize) { if (currBinIndex == actualBiningNum - 1 && i != array.size() - 1) { continue; } if (i == 0 || (mergeEnabled == true && Math.abs(currData - prevData) > EPS) || mergeEnabled == false) { if (i == array.size() - 1) { break; } currBinIndex++; currBinSize = 0; binBoundary.add(currData); } } prevData = currData; } // binBoundary.set(binBoundary.size() - 1, Double.POSITIVE_INFINITY); return binBoundary; }
From source file:net.meltdowntech.steamstats.SteamUser.java
public static List<SteamUser> fetchUsers(List<Long> ids) { List<SteamUser> users = new ArrayList<>(); int queries = (int) Math.ceil(ids.size() / 100.0); //Query every hundred users Util.printDebug("Fetching users"); Util.printInfo(String.format("%d user%s allotted", ids.size(), ids.size() == 1 ? "" : "s")); Util.printDebug(String.format("%d quer%s allotted", queries, queries == 1 ? "y" : "ies")); for (int x = 0; x < queries; x++) { //Create steam ids query string String steamIds = "&steamids="; for (int y = x * 100; y < (x + 1) * 100 && y < ids.size(); y++) { steamIds += ids.get(y) + ","; }//from w w w .ja v a2 s .c o m //Create query url String url = Steam.URL + Steam.PLAYER_DATA + "?key=" + Steam.KEY + steamIds; try { //Attempt connection and parse URL steam = new URL(url); URLConnection steamConn = steam.openConnection(); Reader steamReader = new InputStreamReader(steamConn.getInputStream()); JSONTokener steamTokener = new JSONTokener(steamReader); JSONObject data = (JSONObject) steamTokener.nextValue(); JSONObject response = data.getJSONObject("response"); JSONArray players = response.getJSONArray("players"); //Parse each player for (int y = 0; y < players.length(); y++) { JSONObject player = players.getJSONObject(y); SteamUser user = new SteamUser(); //Parse each field Iterator keys = player.keys(); while (keys.hasNext()) { String key = (String) keys.next(); user.values.put(key, player.get(key)); } users.add(user); } } catch (MalformedURLException ex) { Util.printError("Invalid URL"); } catch (IOException | JSONException ex) { Util.printError("Invalid data"); } catch (Exception ex) { Util.printError("Generic error"); } } Util.printDebug("Done fetching users"); return users; }
From source file:com.baifendian.swordfish.common.utils.DateUtils.java
/** * ?//from ww w .j a v a2 s . com * * @param d1 * @param d2 * @return */ public static long diffDays(Date d1, Date d2) { return (long) Math.ceil(diffHours(d1, d2) / 24.0); }
From source file:com.l2jfree.L2Config.java
/** * Returns application lifetime in an user-friendly string. * /*ww w.java 2 s . co m*/ * @return time since launch */ public static String getUptime() { final long uptimeInSec = (long) Math.ceil(ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0); final long s = uptimeInSec / 1 % 60; final long m = uptimeInSec / 60 % 60; final long h = uptimeInSec / 3600 % 24; final long d = uptimeInSec / 86400; final L2TextBuilder tb = new L2TextBuilder(); if (d > 0) tb.append(d + " day(s), "); if (h > 0 || tb.length() != 0) tb.append(h + " hour(s), "); if (m > 0 || tb.length() != 0) tb.append(m + " minute(s), "); if (s > 0 || tb.length() != 0) tb.append(s + " second(s)"); return tb.moveToString(); }
From source file:sk.lazyman.gizmo.data.provider.BasicDataProvider.java
@Override public Iterator<? extends T> iterator(long first, long count) { int pageIndex = (int) Math.ceil((double) first / (double) itemsPerPage); LOG.debug("Setting page request: page {}, size {}", pageIndex, itemsPerPage); Predicate predicate = getPredicate(); PageRequest page = new PageRequest(pageIndex, itemsPerPage, sort); Page<T> found;//from w w w . ja v a 2 s .co m if (predicate == null) { found = repository.findAll(page); } else { QueryDslPredicateExecutor executor = (QueryDslPredicateExecutor) repository; found = executor.findAll(predicate, page); } if (found != null) { return found.iterator(); } return new ArrayList<T>().iterator(); }