List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:com.websystique.springmvc.dao.LessonDAO.java
@SuppressWarnings("unchecked") public SearchPair<Lesson> getLessonsByQuery(String squery, int maxLessonsInResult, int page) { String sql = "SELECT * FROM lessons WHERE ID IN (SELECT LESSON_ID FROM tags_and_lessons_bounds WHERE TAG_ID IN (SELECT DISTINCT TAG_ID FROM tags_synonyms WHERE TITLE LIKE :squery))"; Query query = getSession().createSQLQuery(sql).addEntity(Lesson.class); query.setParameter("squery", "%" + squery + "%"); query.setMaxResults(maxLessonsInResult); query.setFirstResult(maxLessonsInResult * page); List<Lesson> list = query.list(); int total = 0; sql = "SELECT COUNT (LESSON_ID) FROM tags_and_lessons_bounds WHERE TAG_ID IN (SELECT DISTINCT TAG_ID FROM tags_synonyms WHERE TITLE LIKE :squery)"; query = getSession().createSQLQuery(sql); query.setParameter("squery", "%" + squery + "%"); total = (int) Math.ceil(((Integer) query.uniqueResult()) / Parameters.maxLessonsInSearchResult); return new <Lesson>SearchPair(list, total); }
From source file:com.mycompany.flooringmvc.controllers.FlooringController.java
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseBody/* w ww.j a v a2s . c o m*/ public Order create(@Valid @RequestBody Order order) { List<Product> products = pdao.getProducts(); List<Tax> states = tdao.getTaxes(); String state = order.getState(); state = state.toUpperCase(); double tax = tdao.getTax(state); String type = order.getProduct(); double results[] = getCosts(type); double area = order.getArea(); 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.setLaborCost(lc); order.setLaborCostSqf(lcs); order.setMatCostSqf(mcs); order.setMaterialCost(mc); order.setTax(tax); order.setTaxTotal(taxtotal); order.setTotal(total); for (Product p : products) { if (order.getProduct().equals(type)) { order.setProductId(p.getId()); } } for (Tax t : states) { if (order.getState().equals(state)) { order.setStateId(t.getId()); } } return dao.create(order); }
From source file:edu.umn.cs.spatialHadoop.indexing.ZCurvePartitioner.java
/** * Create a ZCurvePartitioner from a list of points * @param zValues/* ww w .j a v a 2s .c om*/ * @param capacity */ protected void createFromZValues(final long[] zValues, int capacity) { Arrays.sort(zValues); int numSplits = (int) Math.ceil((double) zValues.length / capacity); this.zSplits = new long[numSplits]; long maxZ = computeZ(mbr, mbr.x2, mbr.y2); for (int i = 0; i < numSplits; i++) { int quantile = (int) ((long) (i + 1) * zValues.length / numSplits); this.zSplits[i] = quantile == zValues.length ? maxZ : zValues[quantile]; } }
From source file:com.comphenix.xp.SampleRange.java
public int getMaximum() { return (int) Math.ceil(end); }
From source file:com.publicuhc.pluginframework.util.UUIDFetcher.java
public Map<String, UUID> call() throws IOException, ParseException, InterruptedException { Map<String, UUID> playerMap = new HashMap<String, UUID>(); int requests = (int) Math.ceil(m_names.size() / QUERIES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = getConnection(); String query = JSONArray//from ww w.j a va 2s.c om .toJSONString(m_names.subList(i * 100, Math.min((i + 1) * 100, m_names.size()))); writeQuery(connection, query); JSONArray parsedArray = (JSONArray) m_jsonParser .parse(new InputStreamReader(connection.getInputStream())); for (Object player : parsedArray) { JSONObject jsonPlayer = (JSONObject) player; String id = (String) jsonPlayer.get("id"); String name = (String) jsonPlayer.get("name"); UUID playerID = UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32)); playerMap.put(name, playerID); } if (i != requests - 1) { Thread.sleep(100L); } } return playerMap; }
From source file:edu.umn.cs.spatialHadoop.indexing.BTRPartitioner.java
@Override public void createFromPoints(Rectangle mbr, Point[] points, int capacity) { // Apply the STR algorithm in two rounds // 1- First round, sort points by X and split into the given columns Arrays.sort(points, new Comparator<Point>() { @Override// w w w .ja v a2s . co m public int compare(Point a, Point b) { return a.x < b.x ? -1 : (a.x > b.x ? 1 : 0); } }); // Calculate partitioning numbers based on a grid int numSplits = (int) Math.ceil((double) points.length / capacity); GridInfo gridInfo = new GridInfo(mbr.x1, mbr.y1, mbr.x2, mbr.y2); gridInfo.calculateCellDimensions(numSplits); this.columns = gridInfo.columns; this.rows = gridInfo.rows; this.xSplits = new double[columns]; this.ySplits = new double[rows * columns]; int prev_quantile = 0; this.mbr.set(mbr); for (int column = 0; column < columns; column++) { int col_quantile = (column + 1) * points.length / columns; // Determine the x split for this column. Last column has a special handling this.xSplits[column] = col_quantile == points.length ? mbr.x2 : points[col_quantile - 1].x; // 2- Partition this column vertically in the same way Arrays.sort(points, prev_quantile, col_quantile, new Comparator<Point>() { @Override public int compare(Point a, Point b) { return a.y < b.y ? -1 : (a.y > b.y ? 1 : 0); } }); // Compute y-splits for this column for (int row = 0; row < rows; row++) { int row_quantile = (prev_quantile * (rows - (row + 1)) + col_quantile * (row + 1)) / rows; // Determine y split for this row. Last row has a special handling this.ySplits[column * rows + row] = row_quantile == col_quantile ? mbr.y2 : points[row_quantile].y; } prev_quantile = col_quantile; } }
From source file:com.rogue.regexblock.command.subcommands.HelpCommand.java
private String getPage(int page, Map<String, Object> map) { int factor = 5; int index = (page - 1) * factor; int listSize = map.size(); if (index > listSize) { return ""; }/*from www .j av a2 s .c o m*/ int upper = index + factor; if (upper >= listSize) { upper = listSize; } StringBuilder sb = new StringBuilder(); sb.append("&e").append(this.formatTitle(RegexBlock.getPlugin().getName(), ChatColor.YELLOW, ChatColor.RED)) .append("\n"); sb.append("&ePage &9").append(page).append(" &eof &9") .append((int) Math.ceil((double) listSize / (double) factor)).append("\n").append(ChatColor.RESET); String[] list = map.keySet().toArray(new String[listSize]); Arrays.sort(list); for (int i = index; i < upper; i++) { Object test = map.get(list[i]); if (test != null) { if (test instanceof SubCommand) { SubCommand db = (SubCommand) map.get(list[i]); sb.append("&e").append(db.getHelp()[0]).append(" &9- &f").append(db.getHelp()[1]); } if (i != upper - 1) { sb.append("\n"); } } } sb.append('\n').append("&eUse &9/regexblock <command> help &efor help with a command"); return sb.toString(); }
From source file:MainClass.java
public int getPageCount() { return (int) Math.ceil((double) data.length / pageSize); }
From source file:com.kodyhusky.kodymc.UUIDFetcher.java
@Override @SuppressWarnings("SleepWhileInLoop") 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);/* w w w . ja va 2 s.c o m*/ JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream())); for (Iterator it = array.iterator(); it.hasNext();) { Object profile = it.next(); 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.publicuhc.uhcaddons.teammanager.commands.RandomTeamsCommand.java
/** * Splits the list into even sized lists * * @param list the list to split//from w w w .j av a 2 s . co m * @param count the number of lists to make * @param <T> type * @return a list of the split lists */ public static <T> List<List<T>> split(List<T> list, int count) { Validate.isTrue(list.size() >= count, "List must be >= to the amount of requested lists"); int amountPerList = (int) Math.ceil((double) list.size() / (double) count); return Lists.partition(list, amountPerList); }