Example usage for java.lang Math ceil

List of usage examples for java.lang Math ceil

Introduction

In this page you can find the example usage for java.lang Math ceil.

Prototype

public static double ceil(double a) 

Source Link

Document

Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:net.amigocraft.mglib.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);//from  w ww  .j a  v a2 s.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);
        }
    }
    uuids.putAll(uuidMap);
    return uuidMap;
}

From source file:com.owncloud.android.operations.ChunkedUploadFileOperation.java

@Override
protected int uploadFile(WebdavClient client) throws HttpException, IOException {
    int status = -1;

    FileChannel channel = null;/*from   w  w w  . j a v  a 2 s .c  om*/
    RandomAccessFile raf = null;
    try {
        File file = new File(getStoragePath());
        raf = new RandomAccessFile(file, "r");
        channel = raf.getChannel();
        mEntity = new ChunkFromFileChannelRequestEntity(channel, getMimeType(), CHUNK_SIZE, file);
        ((ProgressiveDataTransferer) mEntity).addDatatransferProgressListeners(getDataTransferListeners());
        long offset = 0;
        String uriPrefix = client.getBaseUri() + WebdavUtils.encodePath(getRemotePath()) + "-chunking-"
                + Math.abs((new Random()).nextInt(9000) + 1000) + "-";
        long chunkCount = (long) Math.ceil((double) file.length() / CHUNK_SIZE);
        for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
            if (mPutMethod != null) {
                mPutMethod.releaseConnection(); // let the connection available for other methods
            }
            mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
            mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
            ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
            mPutMethod.setRequestEntity(mEntity);
            status = client.executeMethod(mPutMethod);
            client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
            Log_OC.d(TAG, "Upload of " + getStoragePath() + " to " + getRemotePath() + ", 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.baifendian.swordfish.common.utils.DateUtils.java

/**
 * ?/*from  w  w  w .  ja  v  a2 s  .c o m*/
 *
 * @param d1
 * @param d2
 * @return
 */
public static long diffSec(Date d1, Date d2) {
    return (long) Math.ceil(diffMs(d1, d2) / 1000.0);
}

From source file:com.swisscom.safeconnect.model.Subscription.java

public Subscription(SkuDetails sd, PlumberSubscriptionResponse s) {
    this.sku = sd.getSku();
    this.description = sd.getDescription();
    this.title = sd.getTitle();
    this.daysValid = s.getDaysValid();
    this.validTill = s.getValidTill();
    this.id = s.getId();

    try {/*w w  w. j  a  va 2  s  . co m*/
        JSONObject j = new JSONObject(sd.getJson());
        long priceMicros = j.optLong("price_amount_micros");
        float priceNormal = priceMicros / 1000000f;
        if (priceNormal == Math.ceil(priceNormal)) {
            this.price = String.format("%.0f", priceNormal);
        } else {
            this.price = String.format("%.2f", priceNormal);
        }
        this.currency = j.optString("price_currency_code");
    } catch (JSONException e) {
        this.price = String.format("%.2f", s.getPrice());
    }
}

From source file:com.eucalyptus.objectstorage.WalrusAvailabilityEventListener.java

@Override
public void fireEvent(final ClockTick event) {
    if (BootstrapArgs.isCloudController() && Bootstrap.isOperational()) {
        try {// w w  w  . ja va 2 s. c o  m

            WalrusInfo wInfo = WalrusInfo.getWalrusInfo();
            long capacity = 0;
            if (wInfo != null)
                capacity = wInfo.getStorageMaxTotalCapacity();

            ListenerRegistry.getInstance().fireEvent(new ResourceAvailabilityEvent(StorageWalrus,
                    new Availability(capacity, Math.max(0, capacity - (long) Math
                            .ceil((double) WalrusQuotaUtil.countTotalObjectSize() / FileUtils.ONE_GB)))));
        } catch (Exception ex) {
            logger.error(ex, ex);
        }
    }
}

From source file:dk.netarkivet.common.utils.JMXUtils.java

/** The maximum number of times we back off on getting an mbean or a job.
 * The cumulative time trying is 2^(MAX_TRIES) milliseconds,
 * thus the constant is defined as log_2(TIMEOUT), as set in settings.
 * @return The number of tries//from  w w  w .  j av  a2  s  .c o m
 */
public static int getMaxTries() {
    return (int) Math.ceil(Math.log((double) timeoutInseconds * DOUBLE_SECONDS_IN_MILLIS) / Math.log(2.0));
}

From source file:CRM.web.UsersController.java

@RequestMapping("/users/viewusers/{pageid}")
public ModelAndView viewUsers(@PathVariable int pageid, HttpServletRequest request) {
    int total = 25;
    int start = 1;

    if (pageid != 1) {
        start = (pageid - 1) * total + 1;
    }/* w w w. ja va 2s.  c om*/

    List<users> list = dao.getUsersByPage(start, total);

    HashMap<String, Object> context = new HashMap<String, Object>();
    context.put("list", list);

    int count = dao.getUserCount();
    context.put("pages", Math.ceil((float) count / (float) total));

    context.put("page", pageid);

    Message msg = (Message) request.getSession().getAttribute("message");

    if (msg != null) {
        context.put("message", msg);
        request.getSession().removeAttribute("message");
    }

    return new ModelAndView("viewusers", context);
}

From source file:com.adobe.acs.commons.httpcache.store.jcr.impl.writer.BucketNodeFactory.java

private String[] getPathArray() {
    final String hashCodeString = StringUtils.leftPad(String.valueOf(key.hashCode()), (int) HASHCODE_LENGTH,
            "0");

    int increment = (int) Math.ceil(HASHCODE_LENGTH / cacheKeySplitDepth);
    final String[] pathArray = new String[cacheKeySplitDepth];

    for (int position = 0, i = 0; i < (cacheKeySplitDepth); position += increment, i++) {
        int endIndex = (position + increment > hashCodeString.length()) ? hashCodeString.length()
                : position + increment;//from w w w  . j  ava2  s. c o  m
        String nodeName = StringUtils.leftPad(hashCodeString.substring(position, endIndex), 5, "0");
        pathArray[i] = nodeName;
    }
    return pathArray;
}

From source file:de.iew.framework.security.access.RequestMapbuilder.java

/**
 * Builds a request web resource map data structure.
 * <p>//from w ww.ja  v a 2 s  . c o m
 * The data structure maps a {@link RequestMatcher} instance to the {@link WebResource} instance.
 * </p>
 *
 * @param requestMapEntries the request map entries.
 * @return the request web resource map
 */
public static LinkedHashMap<RequestMatcher, WebResource> buildRequestWebResourceMap(
        Collection<RequestMapEntry> requestMapEntries) {
    // Calculate the initial capacity for our LinkedHashMap
    float requestmapEntrySize = (float) requestMapEntries.size();
    int mapInitialCapacity = (int) Math.ceil(requestmapEntrySize / REQUEST_MAP_LOAD_FACTOR);

    if (log.isDebugEnabled()) {
        log.debug("Initialisiere die LinkedHashMap mit einer Kapazitt von " + mapInitialCapacity
                + " Eintrgen.");
    }

    LinkedHashMap<RequestMatcher, WebResource> requestMap = new LinkedHashMap<RequestMatcher, WebResource>();

    for (RequestMapEntry requestMapEntry : requestMapEntries) {
        requestMap.put(requestMapEntry.getRequestMatcher(), requestMapEntry.getWebResource());
    }

    return requestMap;
}

From source file:com.estool.utils.page.PageImpl.java

public int getTotalPages() {

    return getSize() == 0 ? 0 : (int) Math.ceil((double) total / (double) getSize());
}