List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:Main.java
public static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) { double w = options.outWidth; double h = options.outHeight; int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels)); int upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength)); if (upperBound < lowerBound) { // return the larger one when there is no overlapping zone. return lowerBound; }/*from w w w . j a v a 2 s . c o m*/ if ((maxNumOfPixels == -1) && (minSideLength == -1)) { return 1; } else if (minSideLength == -1) { return lowerBound; } else { return upperBound; } }
From source file:com.ms.commons.file.impl.FileServiceImpl.java
/** * API??/*from w w w. j a v a 2s . co m*/ * * @param url ?url * @param widths ??savePaths????? * @param savePaths ??widths */ public boolean reduceAllPicture(String url, Double quality, Integer[] widths, String[] savePaths) { if (url == null || url.trim().length() == 0 || widths == null || savePaths == null || widths.length == 0 || widths.length != savePaths.length) { return false; } try { Map<String, Integer> imageBasicInfo = ImageUtil.getImageWH(url); int originalImageWidth = imageBasicInfo.get(ImageUtil.IMAGE_WIDTH); int originalImageHeight = imageBasicInfo.get(ImageUtil.IMAGE_HEIGHT); for (int i = 0, len = widths.length; i < len; i++) { double widthBo = (double) widths[i] / originalImageWidth; int height = (int) Math.ceil(widthBo * originalImageHeight); ImageUtil.scaleImage(url, widths[i], height, savePaths[i], quality); } return true; } catch (Exception e) { logger.error("", e); return false; } }
From source file:gate.corpora.twitter.Population.java
/** * /*from ww w. j a v a2 s .c o m*/ * @param corpus * @param inputUrl * @param encoding * @param contentKeys * @param featureKeys * @param tweetsPerDoc 0 = put them all in one document; otherwise the number per document * @throws ResourceInstantiationException */ public static void populateCorpus(final Corpus corpus, URL inputUrl, String encoding, List<String> contentKeys, List<String> featureKeys, int tweetsPerDoc) throws ResourceInstantiationException { try { InputStream input = inputUrl.openStream(); List<String> lines = IOUtils.readLines(input, encoding); IOUtils.closeQuietly(input); // TODO: sort this out so it processes one at a time instead of reading the // whole hog into memory // For now, we assume the streaming API format (concatenated maps, not in a list) List<Tweet> tweets = TweetUtils.readTweetStrings(lines, contentKeys, featureKeys); int digits = (int) Math.ceil(Math.log10(tweets.size())); int tweetCounter = 0; Document document = newDocument(inputUrl, tweetCounter, digits); StringBuilder content = new StringBuilder(); Map<PreAnnotation, Integer> annotandaOffsets = new HashMap<PreAnnotation, Integer>(); for (Tweet tweet : tweets) { if ((tweetsPerDoc > 0) && (tweetCounter > 0) && ((tweetCounter % tweetsPerDoc) == 0)) { closeDocument(document, content, annotandaOffsets, corpus); document = newDocument(inputUrl, tweetCounter, digits); content = new StringBuilder(); annotandaOffsets = new HashMap<PreAnnotation, Integer>(); } int startOffset = content.length(); content.append(tweet.getString()); for (PreAnnotation preAnn : tweet.getAnnotations()) { annotandaOffsets.put(preAnn, startOffset); } content.append('\n'); tweetCounter++; } // end of Tweet loop if (content.length() > 0) { closeDocument(document, content, annotandaOffsets, corpus); } else { Factory.deleteResource(document); } if (corpus.getDataStore() != null) { corpus.getDataStore().sync(corpus); } } catch (Exception e) { throw new ResourceInstantiationException(e); } }
From source file:com.amazonaws.mturk.cmd.ResetAccount.java
private String[] getHits() { HIT[] hits = null;// w w w.j a v a 2 s . c o m List<String> ret = new ArrayList<String>(); SearchHITsResult result = null; String[] responseGroup = new String[] { "Minimal", "HITDetail" }; int pageSize = 50; totalNumberOfHits = service.getTotalNumHITsInAccount(); double numPagesDouble = Math.ceil(new Double(totalNumberOfHits) / new Double(pageSize)); int numPages = (new Double(numPagesDouble)).intValue(); for (int i = 1; i <= numPages; i = i + 1) { result = service.searchHITs(SortDirection.Ascending, SearchHITsSortProperty.Enumeration, i, pageSize, responseGroup); hits = result.getHIT(); if (hits != null) { for (HIT h : hits) { if (!h.getHITStatus().equals(HITStatus.Unassignable)) { ret.add(h.getHITId()); } else { unassignableCount++; } } } } return (String[]) ret.toArray(new String[] {}); }
From source file:com.groupon.odo.proxylib.Utils.java
public static HashMap<String, Object> getJQGridJSON(Object[] rows, String rowName, int offset, int totalRows, int requestedRows) { HashMap<String, Object> returnVal = new HashMap<String, Object>(); double totalPages = Math.ceil((double) totalRows / (double) requestedRows); returnVal.put("records", totalRows); returnVal.put("total", totalPages); returnVal.put("page", offset / requestedRows + 1); returnVal.put(rowName, rows);//from w w w . j a va 2 s. c o m return returnVal; }
From source file:com.wipro.ats.bdre.datagen.mr.RangeInputFormat.java
/** * Create the desired number of splits, dividing the number of rows * between the mappers.// w ww. ja v a 2s.com */ @Override public List<InputSplit> getSplits(JobContext job) { long totalRows = getNumberOfRows(job); int numSplits = job.getConfiguration().getInt(Config.NUM_SPLITS_KEY, 1); LOG.info("Generating " + totalRows + " using " + numSplits); List<InputSplit> splits = new ArrayList<InputSplit>(); long currentRow = 0; for (int split = 0; split < numSplits; ++split) { long goal = (long) Math.ceil(totalRows * (double) (split + 1) / numSplits); splits.add(new RangeInputSplit(currentRow, goal - currentRow)); currentRow = goal; } return splits; }
From source file:com.bellman.bible.android.view.util.buttongrid.LayoutDesigner.java
RowColLayout calculateLayout(List<ButtonInfo> buttonInfoList) { RowColLayout rowColLayout = new RowColLayout(); int numButtons = buttonInfoList.size(); // is it the list of bible books if (buttonInfoList.size() == 66 && !StringUtils.isNumeric(buttonInfoList.get(0).name)) { // bible books if (isPortrait()) { rowColLayout = BIBLE_BOOK_LAYOUT; } else {// w ww. j a v a 2 s .c o m rowColLayout = BIBLE_BOOK_LAYOUT_LAND; } } else { // a list of chapters or verses if (numButtons <= 50) { if (isPortrait()) { rowColLayout.rows = 10; } else { rowColLayout.rows = 5; } } else if (numButtons <= 100) { rowColLayout.rows = 10; } else { if (isPortrait()) { rowColLayout.rows = 15; } else { rowColLayout.rows = 10; } } rowColLayout.cols = (int) Math.ceil(((float) numButtons) / rowColLayout.rows); // if there are too few buttons/rows you just see a couple of large buttons on the screen so ensure there are enough rows to look nice int minCols = isPortrait() ? MIN_COLS : MIN_COLS_LAND; rowColLayout.cols = Math.max(minCols, rowColLayout.cols); } rowColLayout.columnOrder = isPortrait(); Log.d(TAG, "Rows:" + rowColLayout.rows + " Cols:" + rowColLayout.cols); return rowColLayout; }
From source file:com.trenako.web.infrastructure.PageLinksBuilder.java
private int calculateNumberOfPages(long nrOfElements, int pageSize) { double d = Math.ceil((double) nrOfElements / pageSize); return (int) d; }
From source file:com.joliciel.lefff.LefffMemoryBaseImpl.java
public LefffMemoryBaseImpl(Map<String, List<LexicalEntry>> entryMap, Map<PosTagSet, LefffPosTagMapper> posTagMappers) { this.entryMap = entryMap; this.posTagMappers = posTagMappers; double requiredCapacity = 300000; this.lemmaEntryMap = new HashMap<String, List<LexicalEntry>>(((int) Math.ceil(requiredCapacity / 0.75))); LOG.debug("Constructing lemma entry map"); for (List<LexicalEntry> entries : entryMap.values()) { for (LexicalEntry entry : entries) { LefffEntry lefffEntry = (LefffEntry) entry; String lemma = lefffEntry.getLefffLemma().getText(); String complement = lefffEntry.getLefffLemma().getComplement(); String key = lemma;/*from ww w .ja v a 2s . com*/ if (complement.length() > 0) key += "|" + complement; List<LexicalEntry> entriesPerLemma = lemmaEntryMap.get(key); if (entriesPerLemma == null) { entriesPerLemma = new ArrayList<LexicalEntry>(); lemmaEntryMap.put(key, entriesPerLemma); } entriesPerLemma.add(entry); } } }
From source file:com.baifendian.swordfish.common.utils.DateUtils.java
/** * ??//from w w w . jav a2 s. c om * * @param d1 * @param d2 * @return */ public static long diffHours(Date d1, Date d2) { return (long) Math.ceil(diffMin(d1, d2) / 60.0); }