List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:cn.edu.suda.core.AnalysisTask.java
@Override protected Integer call() throws Exception { Manager ma = Manager.getInstance();//ww w . j ava 2s. co m updateMessage("Building Network..."); Network net = Network.build((List<Pair>) ma.getResult(Manager.Result.Overlap)); ma.putResult(Manager.Result.Network, net); updateMessage("Calculating NOD..."); if (!ma.containResult(Manager.Result.Overlap)) { return 2; } List<Pair> overlap = (List<Pair>) ma.getResult(Manager.Result.Overlap); List<Triplet> nods = PairUtils.countNOD(overlap, PairUtils.count(overlap, false), false); ma.putResult(Manager.Result.NOD, nods); updateMessage("Wilcox Test..."); double[] data1 = new double[nods.size()]; int i = 0; for (Triplet p : nods) { data1[i++] = Double.parseDouble(p.getT2()); } double max = StatUtils.max(data1); double[] wilcox = new double[(int) Math.ceil(max) + 1]; for (int j = 0; j < max + 1; j++) { wilcox[j] = StatsUtils.wilcoxTest(data1, j); } ma.putResult(Manager.Result.WilcoxTest, wilcox); return 0; }
From source file:net.agentlv.namemanager.util.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body);/*from w w w .j ava 2s .c om*/ JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.mstiles92.plugins.stileslib.player.UUIDFetcher.java
public Map<String, UUID> execute() { Map<String, UUID> results = new HashMap<>(); try {/*from w ww. ja v a 2 s .c o m*/ BasicHttpClient client = new BasicHttpClient(new URL("https://api.mojang.com/profiles/minecraft")); client.addHeader("Content-Type", "application/json"); int requests = (int) Math.ceil((double) usernames.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { int start = i * PROFILES_PER_REQUEST; int end = Math.min((i + 1) * PROFILES_PER_REQUEST, usernames.size()); client.setBody(JSONArray.toJSONString(usernames.subList(start, end))); String response = client.post(); JSONArray responseJson = (JSONArray) new JSONParser().parse(response); for (Object o : responseJson) { JSONObject profile = (JSONObject) o; String id = (String) profile.get("id"); String name = (String) profile.get("name"); results.put(name, getUUID(id)); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return results; }
From source file:com.sangupta.passcode.HashStream.java
public int generate(int n, int base, boolean inner) { int value = n; int k = (int) Math.ceil(Math.log(n) / Math.log(base)); int r = (int) Math.pow(base, k) - n; while (value >= n) { List<Integer> chunk = this.shift(base, k); if (chunk == null) { return inner ? n : 0; }/*from www .java 2s .c om*/ value = this.evaluate(chunk, base); if (value >= n) { if (r == 1d) { continue; } this.push(r, value - n); value = this.generate(n, r, true); } } return value; }
From source file:com.expressui.core.util.StringUtil.java
/** * Gets the approximate width in EM units of the given string. * * @param s string to measure//from w w w. j a v a2s. co m * @return width in EM units */ public static int approximateEmWidth(String s) { return (int) Math.ceil(FONT_METRICS.stringWidth(s) * 0.08) + 2; }
From source file:com.norconex.commons.wicket.markup.html.chart.jqplot.PlotPanel.java
public PlotPanel(String id, PlotData plotData, boolean minified) { super(id);/*from w w w.j ava2 s .c o m*/ setOutputMarkupId(true); WebMarkupContainer plotDiv = new WebMarkupContainer("plot"); plotDiv.setOutputMarkupId(true); add(plotDiv); String plotId = plotDiv.getMarkupId(); //XXX hack to get minified version should be done better if (minified) { AxisOptions xaxis = plotData.getOptions().getAxes().getXaxis(); Integer val = xaxis.getNumberTicks(); int numberTicks = 0; if (val != null) { numberTicks = val; } if (numberTicks > 0) { numberTicks = (int) Math.ceil((float) numberTicks / 2f); } xaxis.setNumberTicks(numberTicks); } String code = ""; if (plotData != null) { //--- Options --- String options = "{}"; if (plotData.getOptions() != null) { options = plotData.getOptions().toString(); } //--- Series --- String series = "[]"; if (plotData.getSeries() != null) { series = "[" + StringUtils.join(plotData.getSeries(), ", ") + "]"; } //--- pre/post JS --- String preJs = plotData.getPreJavascript(); if (preJs == null) { preJs = StringUtils.EMPTY; } String postJs = plotData.getPostJavascript(); if (postJs == null) { postJs = StringUtils.EMPTY; } //--- Plot Code --- code = "$(document).ready(function(){" + preJs + " $.jqplot.config.enablePlugins = true;" + " var plot = $.jqplot('" + plotId + "', " + series + ", " + options + ");" + " $(window).resize(function() {" + " if (plot) { " + " $.each(plot.series, function(index, series) {" + " series.barWidth = undefined;" + " });" + " plot.replot();" + " }" + " });" + postJs + "});"; } Label script = new Label("script", code); script.setEscapeModelStrings(false); addOrReplace(script); }
From source file:com.codelanx.playtime.callable.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<String, UUID>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body);// ww w. ja v a2s. c om JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:com.mycompany.flooringmvc.OrderSQLTest.java
@Before public void setUp() throws ParseException { order.setName("Brennan"); SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); Date date = fmt.parse("2013-05-06"); order.setDate(date);/*from ww w. j a v a 2 s . c o m*/ // order.setProduct(1); // order.setState(3); // String state = order.getState(); // state = state.toUpperCase(); double tax = tdao.getTax("OH"); String type = order.getProduct(); double results[] = getCosts(1); double area = 100; double mcs = results[0]; double lcs = results[1]; double lc = Math.ceil(lcs * area); double mc = Math.ceil(mcs * area); double pretotal = Math.ceil(lc + mc); double ttax = tax / 100; double taxtotal = pretotal * ttax; double total = pretotal + taxtotal; order.setArea(area); order.setTotal(total); order.setStateId(3); order.setProductId(1); dao.create(order); }
From source file:com.turt2live.hurtle.uuid.UUIDFetcher.java
public Map<String, UUID> call() throws Exception { Map<String, UUID> uuidMap = new HashMap<>(); int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = createConnection(); String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size()))); writeBody(connection, body);//from w ww . j a va 2s . c o m JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Object profile : array) { JSONObject jsonProfile = (JSONObject) profile; String id = (String) jsonProfile.get("id"); String name = (String) jsonProfile.get("name"); UUID uuid = UUIDFetcher.getUUID(id); uuidMap.put(name, uuid); } if (rateLimiting && i != requests - 1) { Thread.sleep(100L); } } return uuidMap; }
From source file:net.shopxx.service.impl.ShippingMethodServiceImpl.java
@Transactional(readOnly = true) public BigDecimal calculateFreight(ShippingMethod shippingMethod, Area area, Integer weight) { Assert.notNull(shippingMethod);/*from w w w.j a v a2 s. c o m*/ Setting setting = SystemUtils.getSetting(); BigDecimal firstPrice = shippingMethod.getDefaultFirstPrice(); BigDecimal continuePrice = shippingMethod.getDefaultContinuePrice(); if (area != null && CollectionUtils.isNotEmpty(shippingMethod.getFreightConfigs())) { List<Area> areas = new ArrayList<Area>(); areas.addAll(area.getParents()); areas.add(area); for (int i = areas.size() - 1; i >= 0; i--) { FreightConfig freightConfig = shippingMethod.getFreightConfig(areas.get(i)); if (freightConfig != null) { firstPrice = freightConfig.getFirstPrice(); continuePrice = freightConfig.getContinuePrice(); break; } } } if (weight == null || weight <= shippingMethod.getFirstWeight() || continuePrice.compareTo(BigDecimal.ZERO) == 0) { return setting.setScale(firstPrice); } else { double contiuneWeightCount = Math .ceil((weight - shippingMethod.getFirstWeight()) / (double) shippingMethod.getContinueWeight()); return setting.setScale( firstPrice.add(continuePrice.multiply(new BigDecimal(String.valueOf(contiuneWeightCount))))); } }