List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:com.linkedin.pinot.core.io.writer.impl.v2.FixedBitMultiValueWriter.java
public FixedBitMultiValueWriter(File file, int numDocs, int totalNumValues, int columnSizeInBits) throws Exception { float averageValuesPerDoc = totalNumValues / numDocs; this.docsPerChunk = (int) (Math.ceil(PREFERRED_NUM_VALUES_PER_CHUNK / averageValuesPerDoc)); this.numChunks = (numDocs + docsPerChunk - 1) / docsPerChunk; chunkOffsetHeaderSize = numChunks * SIZE_OF_INT * NUM_COLS_IN_HEADER; bitsetSize = (totalNumValues + 7) / 8; rawDataSize = SizeUtil.computeBytesRequired(totalNumValues, columnSizeInBits, SizeUtil.BIT_UNPACK_BATCH_SIZE); LOGGER.info("Allocating:{} for rawDataSize to store {} values of bits:{}", rawDataSize, totalNumValues, columnSizeInBits);/*w w w . j a v a 2s . c o m*/ totalSize = chunkOffsetHeaderSize + bitsetSize + rawDataSize; raf = new RandomAccessFile(file, "rw"); chunkOffsetsBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, 0, chunkOffsetHeaderSize, file, this.getClass().getSimpleName() + " chunkOffsetsBuffer"); bitsetBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize, bitsetSize, file, this.getClass().getSimpleName() + " bitsetBuffer"); rawDataBuffer = MmapUtils.mmapFile(raf, FileChannel.MapMode.READ_WRITE, chunkOffsetHeaderSize + bitsetSize, rawDataSize, file, this.getClass().getSimpleName() + " rawDataBuffer"); chunkOffsetsWriter = new FixedByteSingleValueMultiColWriter(chunkOffsetsBuffer, numDocs, NUM_COLS_IN_HEADER, new int[] { SIZE_OF_INT }); customBitSet = CustomBitSet.withByteBuffer(bitsetSize, bitsetBuffer); rawDataWriter = new FixedBitSingleValueWriter(rawDataBuffer, totalNumValues, columnSizeInBits); }
From source file:io.hops.erasure_coding.BaseEncodingManager.java
static long numStripes(long numBlocks, int stripeSize) { return (long) Math.ceil(numBlocks * 1.0 / stripeSize); }
From source file:etomica.potential.EwaldSummation.java
public EwaldSummation(IBox box, AtomLeafAgentManager<MyCharge> atomAgentManager, ISpace _space, double kCut, double rCutRealES) { this.box = box; this.atomAgentManager = atomAgentManager; this.space = _space; this.secondDerivative = space.makeTensor(); this.tempTensorkk = space.makeTensor(); this.kCut = kCut; moleculeList = box.getMoleculeList(); numMolecules = moleculeList.getMoleculeCount(); boxSize = new double[] { box.getBoundary().getBoxSize().getX(0), box.getBoundary().getBoxSize().getX(1), box.getBoundary().getBoxSize().getX(2) }; volume = box.getBoundary().volume(); Lxyz = space.makeVector();/*from w w w.j a v a 2 s . co m*/ this.rCutRealES = rCutRealES; rCutSquared = rCutRealES * rCutRealES; nRealShells = new int[] { (int) Math.ceil(rCutRealES / boxSize[0] - 0.49999), (int) Math.ceil(rCutRealES / boxSize[1] - 0.49999), (int) Math.ceil(rCutRealES / boxSize[2] - 0.49999) }; nKs = new int[] { (int) Math.ceil(boxSize[0] / 2.0 / Math.PI * kCut), (int) Math.ceil(boxSize[1] / 2.0 / Math.PI * kCut), (int) Math.ceil(boxSize[2] / 2.0 / Math.PI * kCut) }; double s = Math.sqrt(rCutRealES * kCut / 2); alpha = s / rCutRealES; //=0.2406189232882774 //nX=1 int nAtoms = box.getLeafList().getAtomCount(); double Q2 = 0; for (int i = 0; i < nAtoms; i++) {//H IAtom atom = box.getLeafList().getAtom(i); double charge = atomAgentManager.getAgent(atom).charge; Q2 += charge * charge; } Q2 /= numMolecules; alpha2 = alpha * alpha; alpha3 = alpha * alpha2; basis = new double[] { 2 * Math.PI / boxSize[0], 2 * Math.PI / boxSize[1], 2 * Math.PI / boxSize[2] }; gradient = new IVectorMutable[0]; sinkrj = new double[0]; coskrj = new double[0]; rAB = space.makeVector(); drTmp = space.makeVector(); kVector = space.makeVector(); }
From source file:statistic.ca.gui.DiagramContainer.java
public void remove(JPanel diagramToRemove) { JPanel toRemove = null;/* www . j a va2 s . c o m*/ DiagramTupel tupelToRemove = null; for (DiagramTupel dt : diagramList) { if (dt.getDiagram().equals(diagramToRemove)) { toRemove = dt.getDiagram(); tupelToRemove = dt; } } if (toRemove == null) { return; } diagramList.remove(tupelToRemove); diagramMapping.clear(); for (DiagramTupel dia : diagramList) { diagramMapping.put(dia.getTitle(), diagramList.indexOf(dia)); } super.removeAll(); setLayout(new GridLayout((int) (Math.ceil((double) diagramList.size() / 2)), 2)); for (DiagramTupel d : diagramList) { add(d.getDiagram()); (d.getDiagram()).addMouseListener(parent.new diagramClick()); } repaint(); validate(); }
From source file:com.cerema.cloud2.lib.resources.files.ChunkedUploadRemoteFileOperation.java
@Override protected int uploadFile(OwnCloudClient client) throws IOException { int status = -1; FileChannel channel = null;// w w w. j a v a2 s. co m RandomAccessFile raf = null; try { File file = new File(mLocalPath); raf = new RandomAccessFile(file, "r"); channel = raf.getChannel(); mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file); synchronized (mDataTransferListeners) { ((ProgressiveDataTransferer) mEntity).addDatatransferProgressListeners(mDataTransferListeners); } long offset = 0; String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-" + Math.abs((new Random()).nextInt(9000) + 1000) + "-"; long totalLength = file.length(); long chunkCount = (long) Math.ceil((double) totalLength / CHUNK_SIZE); String chunkSizeStr = String.valueOf(CHUNK_SIZE); String totalLengthStr = String.valueOf(file.length()); for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) { if (chunkIndex == chunkCount - 1) { chunkSizeStr = String.valueOf(CHUNK_SIZE * chunkCount - totalLength); } if (mPutMethod != null) { mPutMethod.releaseConnection(); // let the connection available // for other methods } mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex); if (mRequiredEtag != null && mRequiredEtag.length() > 0) { mPutMethod.addRequestHeader(IF_MATCH_HEADER, "\"" + mRequiredEtag + "\""); } mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER); mPutMethod.addRequestHeader(OC_CHUNK_SIZE_HEADER, chunkSizeStr); mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, totalLengthStr); ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset); mPutMethod.setRequestEntity(mEntity); if (mCancellationRequested.get()) { mPutMethod.abort(); // next method will throw an exception } status = client.executeMethod(mPutMethod); if (status == 400) { InvalidCharacterExceptionParser xmlParser = new InvalidCharacterExceptionParser(); InputStream is = new ByteArrayInputStream(mPutMethod.getResponseBodyAsString().getBytes()); try { mForbiddenCharsInServer = xmlParser.parseXMLResponse(is); } catch (Exception e) { mForbiddenCharsInServer = false; Log_OC.e(TAG, "Exception reading exception from server", e); } } client.exhaustResponse(mPutMethod.getResponseBodyAsStream()); Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " + chunkIndex + ", count " + chunkCount + ", HTTP result status " + status); if (!isSuccess(status)) break; } } finally { if (channel != null) channel.close(); if (raf != null) raf.close(); if (mPutMethod != null) mPutMethod.releaseConnection(); // let the connection available for other methods } return status; }
From source file:com.sketchy.utils.image.SketchyImage.java
public int getWidthInMillimeters() { return (int) Math.ceil(image.getWidth() / getDotsPerMillimeterWidth()); }
From source file:ch.unifr.pai.twice.widgets.mpProxyScreenShot.server.ReadOnlyPresentation.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter w = resp.getWriter(); for (String uuid : uuidToScreenshot.keySet()) { Screenshot s = uuidToScreenshot.get(uuid); w.print("<div style=\"width:"); w.print((int) Math.ceil((double) s.width * scaleFactor)); w.print("px; height:"); w.print((int) Math.ceil((double) s.height * scaleFactor)); w.print("px; overflow:hidden; display:inline-block;\">"); w.print("<iframe "); w.print("name=\""); w.print(uuid);/*from ww w .ja v a2 s . c o m*/ w.print("\" style=\"width:100%; height:100%;\" src=\""); w.print(SimpleHttpUrlConnectionServletFilter.getServletPath(req)); w.print("/" + s.url + "/"); w.print("miceScreenShot?uuid=" + uuid); w.print("\"></iframe></div>"); } w.flush(); w.close(); return; }
From source file:fr.zcraft.zbanque.structure.items_groups.ItemsGroup.java
public Pair<Long, Map<BlockType, Long>> getAmounts(final Collection<Bank> banks) { Long amount = 0l;//w ww . j a va 2s.c o m Map<BlockType, Long> detail = new HashMap<>(); for (Bank bank : banks) { for (Map.Entry<BlockType, Long> entry : bank.getContent().entrySet()) { final BlockType type = entry.getKey(); if (relativeAmounts.containsKey(type)) { amount += (long) Math.ceil(relativeAmounts.get(type) * entry.getValue()); detail.put(type, entry.getValue() + (detail.containsKey(type) ? detail.get(type) : 0)); } } } return new Pair<>(amount, detail); }
From source file:Main.java
/** * Helper that does the work of the above functions. Gets the rectangular * position of a Bitmap if it were placed inside a View with scale type set * to {@link ImageView#ScaleType #CENTER_INSIDE}. * /* www.j a va 2 s . co m*/ * @param bitmapWidth the Bitmap's width * @param bitmapHeight the Bitmap's height * @param viewWidth the parent View's width * @param viewHeight the parent View's height * @return the rectangular position of the Bitmap */ private static Rect getBitmapRectCenterInsideHelper(int bitmapWidth, int bitmapHeight, int viewWidth, int viewHeight) { double resultWidth; double resultHeight; int resultX; int resultY; double viewToBitmapWidthRatio = Double.POSITIVE_INFINITY; double viewToBitmapHeightRatio = Double.POSITIVE_INFINITY; // Checks if either width or height needs to be fixed if (viewWidth < bitmapWidth) { viewToBitmapWidthRatio = (double) viewWidth / (double) bitmapWidth; } if (viewHeight < bitmapHeight) { viewToBitmapHeightRatio = (double) viewHeight / (double) bitmapHeight; } // If either needs to be fixed, choose smallest ratio and calculate from // there if (viewToBitmapWidthRatio != Double.POSITIVE_INFINITY || viewToBitmapHeightRatio != Double.POSITIVE_INFINITY) { if (viewToBitmapWidthRatio <= viewToBitmapHeightRatio) { resultWidth = viewWidth; resultHeight = (bitmapHeight * resultWidth / bitmapWidth); } else { resultHeight = viewHeight; resultWidth = (bitmapWidth * resultHeight / bitmapHeight); } } // Otherwise, the picture is within frame layout bounds. Desired width // is simply picture size else { resultHeight = bitmapHeight; resultWidth = bitmapWidth; } // Calculate the position of the bitmap inside the ImageView. if (resultWidth == viewWidth) { resultX = 0; resultY = (int) Math.round((viewHeight - resultHeight) / 2); } else if (resultHeight == viewHeight) { resultX = (int) Math.round((viewWidth - resultWidth) / 2); resultY = 0; } else { resultX = (int) Math.round((viewWidth - resultWidth) / 2); resultY = (int) Math.round((viewHeight - resultHeight) / 2); } final Rect result = new Rect(resultX, resultY, resultX + (int) Math.ceil(resultWidth), resultY + (int) Math.ceil(resultHeight)); return result; }
From source file:com.davidsoergel.trees.AbstractRootedPhylogeny.java
/** * {@inheritDoc}// w w w.j a v a 2 s . co m */ @NotNull public T commonAncestor(Collection<T> knownMergeIds, double proportion) throws NoSuchNodeException { Set<List<PhylogenyNode<T>>> theDisposableAncestorLists = new HashSet<List<PhylogenyNode<T>>>(); for (T id : knownMergeIds) { try { PhylogenyNode<T> node = getNode(id); theDisposableAncestorLists.add(new ArrayList<PhylogenyNode<T>>(node.getAncestorPath())); } catch (NoSuchNodeException e) { logger.debug("Node not found with id " + id + " when looking for common ancestor; ignoring"); } } int numberThatMustAgree = (int) Math.ceil(theDisposableAncestorLists.size() * proportion); PhylogenyNode<T> commonAncestor = null; try { while (true) { commonAncestor = DSCollectionUtils.getDominantFirstElement(theDisposableAncestorLists, numberThatMustAgree); // throws NoSuchElementException theDisposableAncestorLists = DSCollectionUtils .filterByAndRemoveFirstElement(theDisposableAncestorLists, commonAncestor); } } catch (NoSuchElementException e) { // good, broke the loop, leaving commonAncestor and theAncestorLists in the most recent valid state } /* while (DSCollectionUtils.allFirstElementsEqual(theAncestorLists)) { commonAncestor = DSCollectionUtils.removeAllFirstElements(theAncestorLists); } */ if (commonAncestor == null) { throw new NoSuchNodeException("Nodes have no common ancestor"); //return null; } return commonAncestor.getPayload(); }