Example usage for java.lang Math floor

List of usage examples for java.lang Math floor

Introduction

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

Prototype

public static double floor(double a) 

Source Link

Document

Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.

Usage

From source file:fi.ilmoeuro.membertrack.holvi.HolviPopulator.java

private void createSubscriptionPeriod(ProductMapping mapping, int i, Person person, Order order) {
    sessionRunner.exec(token -> {//from   w ww. ja  v a2  s .c om
        Services services = servicesFactory.create(token);
        Service service = services.findById(mapping.getServiceUUID());
        if (service == null) {
            throw new ServiceNotFoundException(mapping.getServiceUUID());
        }

        double payment = mapping.getPayment();
        int euros = (int) (Math.floor(payment));
        int cents = (int) ((payment - euros) * 100);
        LocalDate orderDate = order.getPaid_time().withZoneSameInstant(ZoneId.systemDefault()).toLocalDate();
        SubscriptionPeriod sp = new SubscriptionPeriod(service, person, orderDate, mapping.getTimeUnit(),
                mapping.getLength(), euros * 100 + cents, false);
        SubscriptionPeriodHolviHandle hh = new SubscriptionPeriodHolviHandle(sp, config.getPoolHandle(),
                order.getCode(), i, orderDate);

        UnitOfWork uow = uowFactory.create(token);
        uow.addEntity(sp);
        uow.addEntity(hh);
        uow.execute();
    });
}

From source file:io.indy.seni.ui.EvolveGridFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.fragment_evolve, container, false);

    mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);/*  w  w  w .  ja v  a 2 s  . com*/
    mGridView.setOnItemClickListener(this);
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {

            } else {
                mImageGenerator.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                int totalItemCount) {
        }
    });

    mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
    mGridView.setMultiChoiceModeListener(mMultiChoiceModeListener);

    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                    if (AppConfig.hasJellyBean()) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });

    return v;
}

From source file:com.metova.vtube.service.video.Videos.java

public static final String getLengthText(long length, boolean forceHours) {

    StringBuffer stringBuffer = new StringBuffer();

    if (length >= Dates.HOUR) {

        int time = (int) Math.floor(MathUtils.doubleDivision(length, Dates.HOUR));
        length = length - (int) (Dates.HOUR * time);

        if (time < 10) {

            stringBuffer.append("0");
        }//  ww w . ja va 2s. com

        stringBuffer.append(time);
        stringBuffer.append(":");
    } else if (forceHours) {

        stringBuffer.append("00:");
    }

    if (length >= Dates.MINUTE) {

        int time = (int) Math.floor(MathUtils.doubleDivision(length, Dates.MINUTE));
        length = length - (int) (Dates.MINUTE * time);

        stringBuffer.append((time < 10) ? "0" : "");
        stringBuffer.append(time);
    } else {

        stringBuffer.append("00");
    }

    if (length >= Dates.SECOND) {

        int time = (int) Math.floor(MathUtils.doubleDivision(length, Dates.SECOND));
        length = length - (int) (Dates.SECOND * time);

        stringBuffer.append((time < 10) ? ":0" : ":");
        stringBuffer.append(time);
    } else {

        stringBuffer.append(":00");
    }

    return stringBuffer.toString();
}

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "Return the largest integer smaller than or equal to argument")
public int Floor(double d) {
    return (int) Math.floor(d);
}

From source file:energy.usef.pbcfeeder.PbcFeeder.java

/**
 * @param date/*from  www. ja  va2 s . c om*/
 * @param startPtuIndex of the list starting from 1 till 96 (PTU_PER_DAY).
 * @param amount
 * @return
 */
public List<PbcStubDataDto> getStubRowInputList(LocalDate date, int startPtuIndex, int amount) {
    if (startPtuIndex > PTU_PER_DAY) {
        date = date.plusDays((int) Math.floor(startPtuIndex / PTU_PER_DAY));
        startPtuIndex = startPtuIndex % PTU_PER_DAY;
    }

    // Match PTU-index with requested startIndex and date from ExcelSheet.
    LocalDate epochDate = new LocalDate("1970-01-01");
    int daysDif = Days.daysBetween(epochDate, date).getDays();
    int ptuOffset = (daysDif % DAYS_IN_SPREADSHEET) * PTU_PER_DAY + startPtuIndex - 1;
    List<PbcStubDataDto> pbcStubDataDtoList = new ArrayList<>();

    // Loop over stubRowInputList, if necessary, to get requested amount of ptus.
    do {
        int toIndex = 0;
        if (ptuOffset + amount > stubRowInputList.size()) {
            toIndex = stubRowInputList.size();
        } else {
            toIndex = ptuOffset + amount;
        }
        amount -= (toIndex - ptuOffset);

        pbcStubDataDtoList.addAll(stubRowInputList.subList(ptuOffset, toIndex));
        ptuOffset = 0;
    } while (amount > 0);

    // Create and set PtuContainer for pbcStubDataDto.

    int lastPtuIndex = 0;
    for (PbcStubDataDto pbcStubDataDto : pbcStubDataDtoList) {
        int ptuIndex = pbcStubDataDto.getIndex() % PTU_PER_DAY;
        if (ptuIndex == 0) {
            ptuIndex = PTU_PER_DAY;
        }
        if (ptuIndex < lastPtuIndex) {
            date = date.plusDays(1);
        }
        PbcPtuContainerDto ptuContainerDto = new PbcPtuContainerDto(date.toDateMidnight().toDate(), ptuIndex);
        pbcStubDataDto.setPtuContainer(ptuContainerDto);
        lastPtuIndex = ptuIndex;
    }
    return pbcStubDataDtoList;
}

From source file:com.garyclayburg.UserRestSmokeTest.java

@Test
public void testHalJsonutf8Apache() throws Exception {
    RestTemplate rest = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
    SimpleUser user1 = new SimpleUser();
    user1.setFirstname("Tommy");
    user1.setLastname("Deleteme");
    user1.setId("112" + (int) (Math.floor(Math.random() * 10000)));

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Content-Type", "application/hal+json;charset=UTF-8");
    //        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
    HttpEntity<?> requestEntity = new HttpEntity(user1, requestHeaders);

    ResponseEntity<SimpleUser> simpleUserResponseEntity = rest.exchange(
            "http://" + endpoint + "/audited-users/auditedsave", HttpMethod.POST, requestEntity,
            SimpleUser.class);

    //        ResponseEntity<SimpleUser> userResponseEntity =
    //            rest.postForEntity("http://" + endpoint + "/audited-users/auditedsave",user1,SimpleUser.class);
    log.info("got a response");
    MatcherAssertionErrors.assertThat(simpleUserResponseEntity.getStatusCode(),
            Matchers.equalTo(HttpStatus.OK));

}

From source file:com.intellectualcrafters.plot.generator.HybridPlotWorld.java

public void setupSchematics() {
    this.G_SCH_DATA = new HashMap<>();
    this.G_SCH = new HashMap<>();
    final String schem1Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/sideroad";
    final String schem2Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/intersection";
    final String schem3Str = "GEN_ROAD_SCHEMATIC/" + this.worldname + "/plot";
    final Schematic schem1 = SchematicHandler.manager.getSchematic(schem1Str);
    final Schematic schem2 = SchematicHandler.manager.getSchematic(schem2Str);
    final Schematic schem3 = SchematicHandler.manager.getSchematic(schem3Str);
    final int shift = (int) Math.floor(this.ROAD_WIDTH / 2);
    int oddshift = 0;
    if ((this.ROAD_WIDTH % 2) != 0) {
        oddshift = 1;/*from   w  w  w.j  av  a 2 s.c o m*/
    }
    if (schem3 != null) {
        this.PLOT_SCHEMATIC = true;
        final DataCollection[] blocks3 = schem3.getBlockCollection();
        final Dimension d3 = schem3.getSchematicDimension();
        final short w3 = (short) d3.getX();
        final short l3 = (short) d3.getZ();
        final short h3 = (short) d3.getY();
        int center_shift_x = 0;
        int center_shift_z = 0;
        if (l3 < this.PLOT_WIDTH) {
            center_shift_z = (this.PLOT_WIDTH - l3) / 2;
        }
        if (w3 < this.PLOT_WIDTH) {
            center_shift_x = (this.PLOT_WIDTH - w3) / 2;
        }
        for (short x = 0; x < w3; x++) {
            for (short z = 0; z < l3; z++) {
                for (short y = 0; y < h3; y++) {
                    final int index = (y * w3 * l3) + (z * w3) + x;
                    final short id = blocks3[index].getBlock();
                    final byte data = blocks3[index].getData();
                    if (id != 0) {
                        addOverlayBlock((short) (x + shift + oddshift + center_shift_x), (y),
                                (short) (z + shift + oddshift + center_shift_z), id, data, false);
                    }
                }
            }
        }
        HashSet<PlotItem> items = schem3.getItems();
        if (items != null) {
            G_SCH_STATE = new HashMap<>();
            for (PlotItem item : items) {
                item.x += shift + oddshift + center_shift_x;
                item.z += shift + oddshift + center_shift_z;
                item.y += this.PLOT_HEIGHT;
                int x = item.x;
                int y = item.y;
                int z = item.z;
                PlotLoc loc = new PlotLoc(x, z);
                if (!G_SCH_STATE.containsKey(loc)) {
                    G_SCH_STATE.put(loc, new HashSet<PlotItem>());
                }
                G_SCH_STATE.get(loc).add(item);
            }
        }
    }
    if ((schem1 == null) || (schem2 == null) || (this.ROAD_WIDTH == 0)) {
        PS.log(C.PREFIX.s() + "&3 - schematic: &7false");
        return;
    }
    this.ROAD_SCHEMATIC_ENABLED = true;
    // Do not populate road if using schematic population
    this.ROAD_BLOCK = new PlotBlock(this.ROAD_BLOCK.id, (byte) 0);
    final DataCollection[] blocks1 = schem1.getBlockCollection();
    final DataCollection[] blocks2 = schem2.getBlockCollection();
    final Dimension d1 = schem1.getSchematicDimension();
    final short w1 = (short) d1.getX();
    final short l1 = (short) d1.getZ();
    final short h1 = (short) d1.getY();
    final Dimension d2 = schem2.getSchematicDimension();
    final short w2 = (short) d2.getX();
    final short l2 = (short) d2.getZ();
    final short h2 = (short) d2.getY();
    this.SCHEMATIC_HEIGHT = (short) Math.max(h2, h1);
    for (short x = 0; x < w1; x++) {
        for (short z = 0; z < l1; z++) {
            for (short y = 0; y < h1; y++) {
                final int index = (y * w1 * l1) + (z * w1) + x;
                final short id = blocks1[index].getBlock();
                final byte data = blocks1[index].getData();
                if (id != 0) {
                    addOverlayBlock((short) (x - (shift)), (y), (short) (z + shift + oddshift), id, data,
                            false);
                    addOverlayBlock((short) (z + shift + oddshift), (y), (short) (x - shift), id, data, true);
                }
            }
        }
    }
    for (short x = 0; x < w2; x++) {
        for (short z = 0; z < l2; z++) {
            for (short y = 0; y < h2; y++) {
                final int index = (y * w2 * l2) + (z * w2) + x;
                final short id = blocks2[index].getBlock();
                final byte data = blocks2[index].getData();
                if (id != 0) {
                    addOverlayBlock((short) (x - shift), (y), (short) (z - shift), id, data, false);
                }
            }
        }
    }
}

From source file:com.manning.androidhacks.hack040.ImageGridFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View v = inflater.inflate(R.layout.image_grid_fragment, container, false);
    final GridView mGridView = (GridView) v.findViewById(R.id.gridView);
    mGridView.setAdapter(mAdapter);/*from www.j av  a  2  s  . c om*/
    mGridView.setOnItemClickListener(this);

    // This listener is used to get the final width of the GridView and then
    // calculate the
    // number of columns and the width of each column. The width of each column
    // is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to
    // set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math
                        .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                }
            }
        }
    });

    return v;
}

From source file:com.duy.pascal.interperter.libraries.math.MathLib.java

@PascalMethod(description = "Round to the nearest smaller int64 value")
public long Floor64(double d) {
    return (int) Math.floor(d);
}

From source file:it.cnr.isti.smartfed.federation.generation.DatacenterGenerator.java

/**
 * Generates the list of datacenters, and assigns the host to datacenters according
 * the given distribution. //ww w.  j  a v a2  s .co m
 * 
 * Note that a distribution can very well assign zero hosts to a datacenter.
 * However, since cloudsim does not support zero-host datacenter, we do not create 
 * the empty datacenters.
 * 
 * @param approxNumberDatacenters - the approximate total number of datacenters that will be created
 * @param numberTotalHost - the total number of host in all datacenters
 * @param distribution
 * @return
 */
public List<FederationDatacenter> getDatacenters(int approxNumberDatacenters, int numberTotalHost,
        AbstractRealDistribution distribution) {

    // create the list
    List<FederationDatacenter> list = new ArrayList<FederationDatacenter>(approxNumberDatacenters);

    // Here get the assignment vector
    int[] assign = DistributionAssignment.getAssignmentArray(approxNumberDatacenters, numberTotalHost,
            distribution);

    for (int i = 0; i < approxNumberDatacenters; i++) {
        if (assign[i] <= 0)
            continue;

        int numCore, mips, ram, bw, sto;
        double costBw, costSto, costMem;
        if (type == GenerationType.UNIFORM) {
            double value = distribution.sample();
            numCore = (int) coreAmount.denormalize(value);
            mips = (int) mipsAmount.denormalize(value);
            ram = (int) ramAmount.denormalize(value);
            bw = (int) bwAmount.denormalize(value);
            sto = (int) stoAmount.denormalize(value);

            costBw = costPerBw.denormalize(value);
            costSto = costPerSto.denormalize(value);
            costMem = costPerMem.denormalize(value);
        } else {
            numCore = (int) coreAmount.denormalize(distribution.sample());
            mips = (int) mipsAmount.denormalize(distribution.sample());
            ram = (int) ramAmount.denormalize(distribution.sample());
            bw = (int) bwAmount.denormalize(distribution.sample());
            sto = (int) stoAmount.denormalize(distribution.sample());

            costBw = costPerBw.denormalize(distribution.sample());
            costSto = costPerSto.denormalize(distribution.sample());
            costMem = costPerMem.denormalize(distribution.sample());
        }

        // create the datacenters
        FederationDatacenterProfile profile = FederationDatacenterProfile.getDefault();
        profile.set(DatacenterParams.COST_PER_BW, costBw + "");
        profile.set(DatacenterParams.COST_PER_STORAGE, costSto + "");
        // profile.set(DatacenterParams.COST_PER_SEC, costPerSec.sample()+"");
        profile.set(DatacenterParams.COST_PER_SEC, "0");
        profile.set(DatacenterParams.COST_PER_MEM, costMem + "");
        profile.set(DatacenterParams.MAX_BW_FOR_VM, bw + "");

        // choose a random country
        Range rangecountry = new Range(0, countries.length);
        int index = (int) Math.floor(rangecountry.denormalize(distribution.sample()));
        Country place = countries[index];
        profile.set(DatacenterParams.COUNTRY, place.toString());

        List<Storage> storageList = new ArrayList<Storage>(); // if empty, no SAN attached
        List<Host> hostList = new ArrayList<Host>();
        List<Pe> peList = new ArrayList<Pe>();// create the virtual processor (PE)

        for (int j = 0; j < numCore; j++) {
            peList.add(new Pe(j, new PeProvisionerSimple(mips)));
        }

        // create the hosts
        HostProfile prof = HostProfile.getDefault();

        prof.set(HostParams.RAM_AMOUNT_MB, ram + "");
        prof.set(HostParams.BW_AMOUNT, bw + "");
        prof.set(HostParams.STORAGE_MB, sto + "");

        for (int k = 0; k < assign[i]; k++) {
            hostList.add(HostFactory.get(prof, peList));
        }

        // populate the list
        list.add(FederationDatacenterFactory.get(profile, hostList, storageList));
    }

    return list;
}