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:com.opengamma.analytics.financial.instrument.index.GeneratorInterestRateFutures.java

/**
 * {@inheritDoc}/*ww w .j  a  v a2 s. c  o  m*/
 * The quantity is modified to be in line with the required notional.
 */
@Override
public InterestRateFutureTransactionDefinition generateInstrument(final ZonedDateTime date,
        final double marketQuote, final double notional, final GeneratorAttribute attribute) {
    final int quantity = (int) Math.ceil(notional / _security.getNotional());
    return new InterestRateFutureTransactionDefinition(_security, date, marketQuote, quantity);
}

From source file:net.dfs.server.token.impl.TokenServiceImpl.java

/**
 * {@inheritDoc}//from   ww w .  j av  a  2s.  com
 */
public void createToken(long FILE_SIZE, String fileName, String ext) {

    String user = userRegistration.invokeUser(fileName);

    NO_OF_CHUNKS = (int) Math.ceil(((double) FILE_SIZE) / Integer.parseInt(CHUNK_SIZE));

    log.debug("TOTAL CHUNKS = " + NO_OF_CHUNKS);

    for (int increment = 1; increment <= NO_OF_CHUNKS; increment++) {

        FileToken token = new FileToken();
        token.fileName = user + "_" + fileName + "_" + increment;
        token.ext = ext;
        token.CHUNK_NO = new Integer(increment);

        writeSpace.writeToSpace(token);
    }

    /*      BufferedInputStream inputStream = new BufferedInputStream(new ByteArrayInputStream(fileStream));
                  
          byte [] buffer = new byte [Integer.parseInt(CHUNK_SIZE)];
          Integer bytesRead = 0, increment = 0;
          FileStorageModel fileModel = new FileStorageModel();
            
          try {
             writeSpace.fileSpace();
                     
             while((bytesRead = inputStream.read(buffer)) != -1){
    increment += 1;
    fileModel.fileName = fileName+"_"+increment+ext;
    fileModel.bytesRead = bytesRead;
    fileModel.bytes = buffer;
            
    writeSpace.writeToSpace(fileModel);
             }
          } catch (IOException e) {
             e.printStackTrace();
          }
    */
}

From source file:de.Keyle.MyPet.util.player.UUIDFetcher.java

public static Map<String, UUID> call(List<String> names) {
    names = new ArrayList<String>(names);
    Iterator<String> iterator = names.iterator();
    while (iterator.hasNext()) {
        String playerName = iterator.next();
        if (fetchedUUIDs.containsKey(playerName)) {
            iterator.remove();//from  ww  w . ja v a  2 s .  c  om
        }
    }
    if (names.size() == 0) {
        return readonlyFetchedUUIDs;
    }

    int count = names.size();

    DebugLogger.info("get UUIDs for " + names.size() + " player(s)");
    int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
    try {
        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);
            JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
            count -= array.size();
            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);
                fetchedUUIDs.put(name, uuid);
            }
            if (rateLimiting && i != requests - 1) {
                Thread.sleep(100L);
            }
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (count > 0) {
        MyPetLogger.write("Can not get UUIDs for " + count + " players. Pets of these player may be lost.");
    }
    return readonlyFetchedUUIDs;
}

From source file:com.smithsmodding.armory.api.crafting.blacksmiths.recipe.VanillaAnvilRecipe.java

public VanillaAnvilRecipe(TileEntityBlackSmithsAnvil pEntity) {
    iEntity = pEntity;/*from  w  ww.j a  v  a  2  s  .co m*/
    iLeftInputStack = iEntity.getStackInSlot(11);
    iRightInputStack = iEntity.getStackInSlot(13);
    iOutputStack = null;
    iMaximumCost = 0;

    calculateValues();

    int tExperience = XPUtil.getExperienceForLevel(iMaximumCost);
    iLevelPerPlayer = XPUtil
            .getLevelForExperience((int) Math.ceil(tExperience / (float) iEntity.getConnectedPlayerCount()));
}

From source file:gr.eap.LSHDB.HammingKey.java

@Override
public int optimizeL() {
    L = (int) Math.ceil(Math.log(delta) / Math.log(1 - Math.pow((1.0 - (t * 1.0 / this.size)), k)));
    return L;//from  www. ja va  2 s .  c  o  m
}

From source file:com.galenframework.specs.RangeValue.java

public int asInt() {
    if (value > 0) {
        return (int) Math.floor(value / Math.pow(10, precision));
    } else {//from   w  w w.  j a v a2s. co m
        return (int) Math.ceil(value / Math.pow(10, precision));
    }
}

From source file:com.opengamma.analytics.financial.instrument.index.GeneratorSwapFuturesDeliverable.java

/**
 * {@inheritDoc}/*from  w ww . j a v a 2 s .c  om*/
 * The quantity is selected to be in line with the required nominal.
 */
@Override
public SwapFuturesPriceDeliverableTransactionDefinition generateInstrument(final ZonedDateTime date,
        final double marketQuote, final double notional, final GeneratorAttribute attribute) {
    final int quantity = (int) Math.ceil(notional / _security.getNotional());
    return new SwapFuturesPriceDeliverableTransactionDefinition(_security, date, marketQuote, quantity);
}

From source file:com.googlecode.jcimd.TextMessageUserDataFactory.java

private static byte[] encodeAs(Charset charset, String textMessage) {
    CharsetEncoder encoder = charset.newEncoder();
    ByteBuffer byteBuffer = ByteBuffer
            .allocate(textMessage.length() * (int) Math.ceil(encoder.maxBytesPerChar()));
    encoder.encode(CharBuffer.wrap(textMessage), byteBuffer, true);
    byte[] bytes = new byte[byteBuffer.position()];
    byteBuffer.flip();/*from w w  w  . j  av a 2 s  .c  om*/
    byteBuffer.get(bytes);
    return bytes;
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.sym_part.Sym_Part_Objective.java

protected int[] findTile(double x1, double x2) {
    int[] t = new int[2];

    double xx1 = (x1 < 0) ? -x1 : x1;
    double xx2 = (x2 < 0) ? -x2 : x2;

    t[0] = (xx1 < c1) ? 0 : ((int) Math.ceil((xx1 - c1) / c2));
    t[1] = (xx2 < b1) ? 0 : ((int) Math.ceil((xx2 - b1) / b));
    if (x1 < 0) {
        t[0] = -(t[0]);/* w ww . j  ava 2  s.c o  m*/
    }
    if (x2 < 0) {
        t[1] = -(t[1]);
    }
    return t;
}

From source file:br.upe.ecomp.doss.algorithm.chargedpso.ChargedPSO.java

@Override
protected void createParticles() {
    ChargedPSOParticle[] particles = new ChargedPSOParticle[getSwarmSize()];
    double chargedParticles = Math.ceil((getSwarmSize() * percentageChargedParticles) / 100);

    double[] position;
    for (int i = 0; i < getSwarmSize(); i++) {
        position = super.getInitialPosition();

        ChargedPSOParticle particle = new ChargedPSOParticle(getDimensions());
        particle.updateCurrentPosition(position, getProblem().getFitness(position));
        particle.updateBestPosition(position.clone(), particle.getCurrentFitness());
        particle.setVelocity(getInitialVelocity());

        if (percentageChargedParticles == 100) {
            particle.setCharge(particleCharge);
        }//w ww  .ja  v a 2 s  .  c  o m

        particles[i] = particle;
    }

    if (percentageChargedParticles < 100) {
        chargeParticles(particles, chargedParticles);
    }

    setParticles(particles);
}