Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

In this page you can find the example usage for java.lang Double doubleValue.

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:org.polymap.kaps.ui.form.WohnungLiegenschaftzinsFormEditorPage.java

@SuppressWarnings("unchecked")
@Override/*  ww w . j  a  v a 2  s .c  om*/
public void createFormContent(final IFormEditorPageSite site) {
    super.createFormContent(site);

    Control newLine, lastLine = null;
    Composite parent = pageSite.getPageBody();

    newLine = createLabel(parent, "Richtwert in /m", one().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bodenrichtwert(), two().top(lastLine), parent, false);
    createLabel(parent, "Bodenpreis in /m", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bodenpreis(), five().top(lastLine), parent, true);

    lastLine = newLine;
    newLine = createLabel(parent, "Mietfestsetzung seit", one().top(lastLine), SWT.RIGHT);
    newFormField(IFormFieldLabel.NO_LABEL).setProperty(new PropertyAdapter(wohnung.mietfestsetzungSeit()))
            .setField(new DateTimeFormField()).setLayoutData(two().top(lastLine).create()).create();
    createLabel(parent, "Bebauungsabschlag in %", three().top(lastLine), SWT.RIGHT);
    createFlaecheField(wohnung.bebauungsabschlagInProzent(), four().top(lastLine), parent, true);
    createPreisField(wohnung.bebauungsabschlag(), five().top(lastLine), parent, false);
    site.addFieldListener(bebabschlag = new FieldCalculation(site, 2, wohnung.bebauungsabschlag(),
            wohnung.bebauungsabschlagInProzent(), wohnung.bodenpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double prozent = values.get(wohnung.bebauungsabschlagInProzent());
            Double preis = values.get(wohnung.bodenpreis());
            if (preis == null) {
                return null;
            }
            if (prozent == null) {
                return null;
            }
            return preis * prozent / 100;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "bereinigter Bodenpreis", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bereinigterBodenpreis(), five().top(lastLine), parent, true);
    site.addFieldListener(berPreis = new FieldCalculation(site, 2, wohnung.bereinigterBodenpreis(),
            wohnung.bebauungsabschlag(), wohnung.bodenpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double abschlag = values.get(wohnung.bebauungsabschlag());
            Double preis = values.get(wohnung.bodenpreis());
            if (preis == null) {
                return null;
            }
            if (abschlag == null) {
                return preis;
            }
            return preis - abschlag;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "monatlicher Rohertrag in ", one().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.monatlicherRohertrag(), two().top(lastLine), parent, true);
    createLabel(parent, "Jahresrohertrag in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.jahresRohertrag(), five().top(lastLine), parent, true);
    site.addFieldListener(jahresRohertrag = new FieldCalculation(site, 2, wohnung.jahresRohertrag(),
            wohnung.monatlicherRohertrag()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double abschlag = values.get(wohnung.monatlicherRohertrag());
            if (abschlag != null) {
                return abschlag * 12;
            }
            return null;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "Rohertrag in /m", one().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.monatlicherRohertragJeQm(), two().top(lastLine), parent, true);
    createLabel(parent, "Bewirtschaftungkosten in %", three().top(lastLine), SWT.RIGHT);
    createFlaecheField(wohnung.bewirtschaftungsKostenInProzent(), four().top(lastLine), parent, true);
    createPreisField(wohnung.bewirtschaftungsKosten(), five().top(lastLine), parent, false);
    site.addFieldListener(
            bewirtschaftungskosten = new FieldCalculation(site, 2, wohnung.bewirtschaftungsKosten(),
                    wohnung.bewirtschaftungsKostenInProzent(), wohnung.jahresRohertrag()) {

                @Override
                protected Double calculate(ValueProvider values) {
                    Double prozent = values.get(wohnung.bewirtschaftungsKostenInProzent());
                    Double preis = values.get(wohnung.jahresRohertrag());
                    if (preis == null) {
                        return null;
                    }
                    if (prozent == null) {
                        return null;
                    }
                    return preis * prozent / 100;
                }

            });

    lastLine = newLine;
    newLine = createLabel(parent, "Jahresreinertrag in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.jahresReinertrag(), five().top(lastLine), parent, true);
    site.addFieldListener(jahresReinertrag = new FieldCalculation(site, 2, wohnung.jahresReinertrag(),
            wohnung.bewirtschaftungsKosten(), wohnung.jahresRohertrag()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double ertrag = values.get(wohnung.jahresRohertrag());
            if (ertrag != null) {
                Double kosten = values.get(wohnung.bewirtschaftungsKosten());
                if (kosten == null) {
                    return ertrag;
                } else {
                    return MathUtil.round(ertrag - kosten);
                }
            }
            return null;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "Bodenwertanteil der Wohnung in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.bodenwertAnteilDerWohnung(), five().top(lastLine), parent, true);
    site.addFieldListener(bodenwertAnteilDerWohnung = new FieldCalculation(site, 2,
            wohnung.bodenwertAnteilDerWohnung(), wohnung.wohnflaeche(), wohnung.bereinigterBodenpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            if (wohnung.flurstueck().get() != null) {
                Double flaeche = wohnung.flurstueck().get().flaeche().get();
                if (flaeche != null) {
                    Double zaehler = wohnung.flurstueck().get().flaechenAnteilZaehler().get();
                    Double nenner = wohnung.flurstueck().get().flaechenAnteilNenner().get();
                    Double preis = values.get(wohnung.bereinigterBodenpreis());
                    if (zaehler != null) {
                        flaeche *= zaehler;
                    }
                    if (nenner != null && !nenner.equals(Double.valueOf(0.0d))) {
                        flaeche /= nenner;
                    }
                    if (preis != null) {
                        flaeche *= preis;
                    } else {
                        flaeche = Double.valueOf(0.0d);
                    }
                    return MathUtil.round(flaeche);
                }
            }
            return null;
        }

    });

    lastLine = newLine;
    newLine = createLabel(parent, "Abschlge bercksichtigen?",
            "beim Kaufpreis die Zu/Abschlge bei\nGaragen/Stellplatz/Anderes bercksichtigen?",
            one().top(lastLine), SWT.RIGHT);
    newFormField(IFormFieldLabel.NO_LABEL)
            .setToolTipText(
                    "beim Kaufpreis die Zu/Abschlge bei\nGaragen/Stellplatz/Anderes bercksichtigen?")
            .setProperty(new PropertyAdapter(wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen()))
            .setField(new CheckboxFormField()).setLayoutData(two().top(lastLine).create()).create();
    createLabel(parent, "Gebudewertanteil der Wohnung in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.gebaeudewertAnteilDerWohnung(), five().top(lastLine), parent, true);
    site.addFieldListener(gebaeudewertAnteilDerWohnung = new FieldCalculationWithTrigger(site, 2,
            wohnung.gebaeudewertAnteilDerWohnung(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.bodenwertAnteilDerWohnung(), wohnung.bereinigterVollpreis(), wohnung.kaufpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double bodenwert = values.get(wohnung.bodenwertAnteilDerWohnung());
            if (bodenwert != null) {
                Double preis = this.triggerValue() != null && this.triggerValue().booleanValue()
                        ? values.get(wohnung.bereinigterVollpreis())
                        : values.get(wohnung.kaufpreis());
                if (preis != null) {
                    return MathUtil.round(preis - bodenwert);
                }
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Sachwert der Wohnung in ", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.sachwertDerWohnung(), five().top(lastLine), parent, false);
    site.addFieldListener(sachwertDerWohnung = new FieldSummation(site, 2, wohnung.sachwertDerWohnung(),
            wohnung.bodenwertAnteilDerWohnung(), wohnung.gebaeudewertAnteilDerWohnung()));

    lastLine = newLine;
    newLine = createLabel(parent, "Jahresreinertrag/Kaufpreis", three().top(lastLine), SWT.RIGHT);
    createNumberField(IFormFieldLabel.NO_LABEL, null, wohnung.jahresReinErtragZuKaufpreis(),
            five().top(lastLine), parent, false, 4);
    site.addFieldListener(jahresReinErtragZuKaufpreis = new FieldCalculationWithTrigger(site, 4,
            wohnung.jahresReinErtragZuKaufpreis(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.jahresReinertrag(), wohnung.bereinigterVollpreis(), wohnung.kaufpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double reinertrag = values.get(wohnung.jahresReinertrag());
            if (reinertrag != null) {
                Double preis = this.triggerValue() != null && this.triggerValue().booleanValue()
                        ? values.get(wohnung.bereinigterVollpreis())
                        : values.get(wohnung.kaufpreis());
                if (preis != null && !preis.equals(Double.valueOf(0.0d))) {
                    return reinertrag / preis;
                }
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Gebudewertanteil/Kaufpreis", three().top(lastLine), SWT.RIGHT);
    createNumberField(IFormFieldLabel.NO_LABEL, null, wohnung.gebaeudewertAnteilZuKaufpreis(),
            five().top(lastLine), parent, false, 4);
    site.addFieldListener(gebaeudewertAnteilZuKaufpreis = new FieldCalculationWithTrigger(site, 4,
            wohnung.gebaeudewertAnteilZuKaufpreis(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.gebaeudewertAnteilDerWohnung(), wohnung.bereinigterVollpreis(), wohnung.kaufpreis()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double gebaeudewertAnteil = values.get(wohnung.gebaeudewertAnteilDerWohnung());
            if (gebaeudewertAnteil != null) {
                Double preis = this.triggerValue() != null && this.triggerValue().booleanValue()
                        ? values.get(wohnung.bereinigterVollpreis())
                        : values.get(wohnung.kaufpreis());
                if (preis != null && !preis.equals(Double.valueOf(0.0d))) {
                    return gebaeudewertAnteil / preis;
                }
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Liegenschaftszins in %", three().top(lastLine), SWT.RIGHT);
    createPreisField(wohnung.liegenschaftsZins(), five().top(lastLine), parent, false);
    site.addFieldListener(liegenschaftsZins = new FieldCalculationWithTrigger(site, 2,
            wohnung.liegenschaftsZins(), wohnung.garagenBeiLiegenschaftszinsBeruecksichtigen(),
            wohnung.gebaeudewertAnteilZuKaufpreis(), wohnung.jahresReinErtragZuKaufpreis(),
            wohnung.gesamtNutzungsDauer(), wohnung.bereinigtesBaujahr(), wohnung.baujahr()) {

        @Override
        protected Double calculate(ValueProvider values) {
            Double faktor1 = values.get(wohnung.jahresReinErtragZuKaufpreis());
            Double faktor2 = values.get(wohnung.gebaeudewertAnteilZuKaufpreis());
            Double GND = values.get(wohnung.gesamtNutzungsDauer());
            Double baujahr = values.get(wohnung.bereinigtesBaujahr());
            if (baujahr == null || baujahr.doubleValue() == 0.0d) {
                baujahr = values.get(wohnung.baujahr());
            }

            VertragComposite vertrag = wohnung.vertrag().get();
            int currentYear = (vertrag != null ? vertrag.vertragsDatum().get().getYear() : new Date().getYear())
                    + 1900;
            Double RND = (GND != null && baujahr != null) ? baujahr + GND - currentYear : null;
            if (RND != null && faktor1 != null && faktor2 != null) {
                Double liziV = faktor1;
                Double liziN = faktor1 - ((liziV) / (Math.pow(1 + liziV, RND) - 1) * faktor2);
                int iteration = 1;
                while (Math.abs(liziN - liziV) > 0.005d) {
                    liziV = liziN;
                    liziN = faktor1 - ((liziV) / (Math.pow(1 + liziV, RND) - 1) * faktor2);
                    iteration++;
                }
                // in % umrechnen
                double result = liziN * 100;
                return Double.isNaN(result) ? 0.0d : result;
            }
            return null;
        }
    });

    lastLine = newLine;
    newLine = createLabel(parent, "Zur Auswertung geeignet?",
            "Ist der Liegenschaftszins geeignet fr Auswertungen?", three().top(lastLine), SWT.RIGHT);
    newFormField(IFormFieldLabel.NO_LABEL)
            .setToolTipText("Ist der Liegenschaftszins geeignet fr Auswertungen?")
            .setProperty(new PropertyAdapter(wohnung.geeignet())).setField(new CheckboxFormField())
            .setLayoutData(five().top(lastLine).create()).create();

}

From source file:it.eng.spagobi.engines.kpi.bo.ChartImpl.java

/**
 * This function fills up the vector "intervals" with the intervals of the chart, getting them from a list of Thresholds 
 * /* ww  w.ja  v a  2s  .  co  m*/
 * @param List of thresholds to set
 */
public void setThresholdValues(List thresholdValues) {
    logger.debug("IN");
    if (thresholdValues != null && !thresholdValues.isEmpty()) {
        Iterator it = thresholdValues.iterator();

        while (it.hasNext()) {
            ThresholdValue t = (ThresholdValue) it.next();
            String type = t.getThresholdType();
            Double min = t.getMinValue();
            Double max = t.getMaxValue();
            String label = t.getLabel();
            Color c = t.getColor();

            if (type.equals("RANGE")) {
                if (min != null && min.doubleValue() < lower) {
                    lower = min.doubleValue();
                } else if (min == null && max != null) {
                    if (max.doubleValue() == 0) {
                        lower = -10;
                    } else if (max.doubleValue() > 0) {
                        lower = 0;
                    } else if (max.doubleValue() < 0) {
                        lower = max.doubleValue() * 2;
                    }
                }

                if (max != null && max.doubleValue() > upper) {
                    upper = max.doubleValue();
                } else if (max == null && min != null) {
                    if (min.doubleValue() == 0) {
                        upper = 10;
                    } else if (min.doubleValue() > 0) {
                        upper = min.doubleValue() * 2;
                    } else if (min.doubleValue() < 0) {
                        upper = 0;
                    }
                }

                KpiInterval interval = new KpiInterval();

                if (c != null) {
                    interval.setColor(c);
                } else {
                    interval.setColor(Color.WHITE);
                }
                if (label != null) {
                    interval.setLabel(label);
                } else {
                    interval.setLabel("");
                }

                if (max != null) {
                    interval.setMax(max);
                } else {
                    interval.setMax(upper);
                }

                if (min != null) {
                    interval.setMin(min);
                } else {
                    interval.setMin(lower);
                }
                String color = Integer.toHexString(interval.getColor().getRGB() & 0x00ffffff);
                intervals.add(interval);
            } else if (type.equals("MINIMUM")) {

                if (min.doubleValue() < lower) {
                    lower = min.doubleValue() * 2;
                }
                if (min.doubleValue() > 0) {
                    upper = min.doubleValue() * 2;
                } else if (min.doubleValue() == 0) {
                    upper = 10;
                    lower = -10;
                }

                KpiInterval interval1 = new KpiInterval();

                if (c != null) {
                    interval1.setColor(c);
                } else {
                    interval1.setColor(Color.WHITE);
                }
                if (label != null) {
                    interval1.setLabel(label);
                } else {
                    interval1.setLabel("");
                }
                interval1.setMax(min);
                interval1.setMin(lower);
                String color1 = Integer.toHexString(interval1.getColor().getRGB() & 0x00ffffff);
                intervals.add(interval1);
                KpiInterval interval2 = new KpiInterval();
                interval2.setColor(Color.WHITE);
                interval2.setLabel("");
                interval2.setMax(upper);
                interval2.setMin(min);
                String color2 = Integer.toHexString(interval2.getColor().getRGB() & 0x00ffffff);
                intervals.add(interval2);

            } else if (type.equals("MAXIMUM")) {

                if (max.doubleValue() > upper) {
                    upper = max.doubleValue() * 2;
                }
                if (max.doubleValue() < 0) {
                    lower = max.doubleValue() * 2;
                } else if (max.doubleValue() == 0) {
                    lower = -10;
                    upper = 10;
                }

                KpiInterval interval1 = new KpiInterval();
                interval1.setColor(Color.WHITE);

                interval1.setLabel("");
                interval1.setMax(max);
                interval1.setMin(lower);
                String color1 = Integer.toHexString(interval1.getColor().getRGB() & 0x00ffffff);
                intervals.add(interval1);
                KpiInterval interval2 = new KpiInterval();
                if (c != null) {
                    interval2.setColor(c);
                } else {
                    interval2.setColor(Color.WHITE);
                }
                if (label != null) {
                    interval2.setLabel(label);
                } else {
                    interval2.setLabel("");
                }
                interval2.setMax(upper);
                interval2.setMin(max);
                String color2 = Integer.toHexString(interval2.getColor().getRGB() & 0x00ffffff);
                intervals.add(interval2);
            }
            logger.debug("New interval added to the Vector");
        }
    }
    logger.debug("OUT");
}

From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java

License:asdf

@Test
public void putValueDouble() {
    ObjectNode parent = new ObjectNode(factory);
    String name = "foo";
    Double value = new Double("12928.222");

    parser.putValue(parent, name, value);

    JsonNode x = parent.get(name);//from  w  ww  .j  a  va 2s . c  om

    Assert.assertNotNull(x);
    Assert.assertEquals(value.doubleValue(), x.doubleValue(), 0.001);
}

From source file:com.datatorrent.lib.math.MarginKeyVal.java

/**
 * Generates tuples for each key and emits them. Only keys that are in the
 * denominator are iterated on If the key is only in the numerator, it gets
 * ignored (cannot do divide by 0) Clears internal data
 *//*from  ww w . jav  a2s  . c o m*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void endWindow() {
    Double val;
    for (Map.Entry<K, MutableDouble> e : denominators.entrySet()) {
        K key = e.getKey();
        MutableDouble nval = numerators.get(key);
        if (nval == null) {
            nval = new MutableDouble(0.0);
        } else {
            numerators.remove(key); // so that all left over keys can be reported
        }
        if (percent) {
            val = (1 - nval.doubleValue() / e.getValue().doubleValue()) * 100;
        } else {
            val = 1 - nval.doubleValue() / e.getValue().doubleValue();
        }

        margin.emit(new KeyValPair(key, getValue(val.doubleValue())));
    }

    numerators.clear();
    denominators.clear();
}

From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java

/**
 * Selecting the solenoid valves corresponding to the currently selected ones in the properties file
 *//*from  www . ja v  a  2  s.co  m*/
private void selectSolenoidValves() {
    int allCount = 5;
    int count = -1;

    if (solenoidValvesOfInterest.size() == allCount) {
        getAllSolenoidValveCheckBox().setSelected(true);
        selectAllCheckBox();
        return;
    } else {
        for (Double valve : solenoidValvesOfInterest) {
            count++;
            if (valve.doubleValue() == 0.0)
                getSolenoidValveZeroCheckBox().setSelected(true);
            if (valve.doubleValue() == 1.0)
                getSolenoidValveOneCheckBox().setSelected(true);
            if (valve.doubleValue() == 2.0)
                getSolenoidValveTwoCheckBox().setSelected(true);
            if (valve.doubleValue() == 4.0)
                getSolenoidValveFourCheckBox().setSelected(true);
            if (valve.doubleValue() == 8.0)
                getSolenoidValveEightCheckBox().setSelected(true);
            if (valve.doubleValue() == 16.0)
                getSolenoidValveSixteenCheckBox().setSelected(true);
        }
    }
    log.info(Messages.getString("OptionsDialog.17") + count); //$NON-NLS-1$
    if (count >= allCount) {
        getAllSolenoidValveCheckBox().setSelected(true);
        selectAllCheckBox();
    }
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.pages.StoreLocatorPageController.java

@RequestMapping(method = RequestMethod.GET, params = "q")
public String findStores(@RequestParam(value = "page", defaultValue = "0") final int page,
        @RequestParam(value = "show", defaultValue = "Page") final AbstractSearchPageController.ShowMode showMode,
        @RequestParam(value = "sort", required = false) final String sortCode,
        @RequestParam(value = "q") final String locationQuery,
        @RequestParam(value = "latitude", required = false) final Double latitude,
        @RequestParam(value = "longitude", required = false) final Double longitude,
        final StoreFinderForm storeFinderForm, final Model model, final BindingResult bindingResult)
        throws GeoLocatorException, MapServiceException, CMSItemNotFoundException {
    final String sanitizedSearchQuery = XSSFilterUtil.filter(locationQuery);

    if (latitude != null && longitude != null) {
        final GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(latitude.doubleValue());
        geoPoint.setLongitude(longitude.doubleValue());

        setUpSearchResultsForPosition(geoPoint,
                createPageableData(page, getStoreLocatorPageSize(), sortCode, showMode), model);

    } else if (StringUtils.isNotBlank(sanitizedSearchQuery)) {

        setUpSearchResultsForLocationQuery(sanitizedSearchQuery,
                createPageableData(page, getStoreLocatorPageSize(), sortCode, showMode), model);
        setUpMetaData(sanitizedSearchQuery, model);
        setUpPageForms(model);//from   ww  w  .j  a  va  2 s.c  o  m
        setUpPageTitle(sanitizedSearchQuery, model);

    } else {

        GlobalMessages.addErrorMessage(model, "storelocator.error.no.results.subtitle");
        model.addAttribute(WebConstants.BREADCRUMBS_KEY,
                storefinderBreadcrumbBuilder.getBreadcrumbsForLocationSearch(sanitizedSearchQuery));

    }

    storeCmsPageInModel(model, getStoreFinderPage());

    return ControllerConstants.Views.Pages.StoreFinder.StoreFinderSearchPage;
}

From source file:es.udc.gii.common.eaf.algorithm.population.Individual.java

/**
 * This method is called whenever an instance of this class has to be serialized.<p>
 * // w w w  .j av  a 2s  .co  m
 * It might write to the output <code>out</code> the evaluation results
 * or the genotype information or both, deppending on the value of 
 * Individual#getSerializeEvalResults and Individual#getSerializeGenotype,
 * which are always writen at the beginning of the output to know later what
 * type of information is contained in the data.<p>
 * 
 * Subclasses should override this method if they introduce new attibutes.
 * Remember to call <code>super.writeExternal()</code> in order to
 * be sure that the state of the parent class is serialized.    
 * 
 * @param out - DataOutput to write the serialized bytes to.
 * @throws java.io.IOException
 */
@Override
public void writeExternal(ObjectOutput out) throws IOException {

    /* Phenotype serialized? */
    out.writeBoolean(this.serializeEvalResults);

    /* Genotype serialized? */
    out.writeBoolean(this.serializeGenotype);

    if (this.serializeEvalResults) {
        /* Serialize number of violated constraints */
        out.writeInt(this.violatedConstraints);

        /* Serialize fitness */
        out.writeDouble(this.fitness);

        /* Serialize objective values */
        if (this.objectives == null) {
            out.writeInt(-1);
        } else {
            out.writeInt(this.objectives.size());
            for (Double d : this.objectives) {
                out.writeDouble(d.doubleValue());
            }
        }

        /* Serialize constraint values */
        if (this.constraints == null) {
            out.writeInt(-1);
        } else {
            out.writeInt(this.constraints.size());
            for (Double d : this.constraints) {
                out.writeDouble(d.doubleValue());
            }
        }
    }

    if (this.serializeGenotype) {
        /* Serialize the chromosomes */
        if (this.chromosomes == null) {
            out.writeInt(-1);
        } else {
            out.writeInt(this.chromosomes.length);
            for (int i = 0; i < this.chromosomes.length; i++) {
                int genes = this.chromosomes[i].getNumElements();
                out.writeInt(genes);

                for (int j = 0; j < genes; j++) {
                    out.writeDouble(this.chromosomes[i].getElement(j));
                }
            }
        }
    }

}

From source file:es.udc.gii.common.eaf.algorithm.population.Individual.java

/**
 * Clones the current individual./*from  w ww. j a va2  s . c  om*/
 * @return a new individual which is a copy of the current one.
 */
@Override
public Object clone() {

    Individual clone = null;
    DoubleArray[] clone_chromosomes = null;

    try {
        clone = (Individual) super.clone();
    } catch (CloneNotSupportedException e) {
        assert false;
    }

    //Clono los cromosomas:
    if (this.chromosomes != null) {
        clone_chromosomes = new DoubleArray[this.chromosomes.length];

        for (int i = 0; i < this.chromosomes.length; i++) {

            clone_chromosomes[i] = new ResizableDoubleArray(this.chromosomes[i].getNumElements());
            for (int j = 0; j < this.chromosomes[i].getNumElements(); j++) {

                clone_chromosomes[i].setElement(j, this.chromosomes[i].getElement(j));

            }

        }
    }

    clone.setChromosomes(clone_chromosomes);

    clone.setFitness(this.fitness);
    clone.setSerializeGenotype(serializeGenotype);
    clone.setSerializeEvalResults(serializeEvalResults);
    clone.setViolatedConstraints(violatedConstraints);

    /* Clone objective values */
    List<Double> obj = null;
    if (objectives != null) {
        obj = new ArrayList<Double>(objectives.size());

        for (Double d : objectives) {
            obj.add(new Double(d.doubleValue()));
        }
    }

    clone.setObjectives(obj);

    /* Clone constraint values */
    List<Double> contr = null;
    if (constraints != null) {
        contr = new ArrayList<Double>(constraints.size());

        for (Double d : constraints) {
            contr.add(new Double(d.doubleValue()));
        }
    }

    clone.setConstraints(contr);

    /* Copy comparator. */
    clone.setComparator(getComparator());

    return clone;
}

From source file:org.sakaiproject.tool.gradebook.business.impl.GradebookCalculationImpl.java

@Override
List getTotalPointsEarnedInternal(final String studentId, final Gradebook gradebook, final List categories,
        final List<AssignmentGradeRecord> gradeRecs, List<Assignment> countedAssigns) {
    int gbGradeType = gradebook.getGrade_type();
    if (gbGradeType != GradebookService.GRADE_TYPE_POINTS
            && gbGradeType != GradebookService.GRADE_TYPE_PERCENTAGE) {
        if (log.isInfoEnabled())
            log.error("Wrong grade type in GradebookCalculationImpl.getTotalPointsEarnedInternal");
        return new ArrayList();
    }/* www.  j av  a 2  s  .c  o  m*/

    if (gradeRecs == null || countedAssigns == null) {
        if (log.isDebugEnabled())
            log.debug("getTotalPointsEarnedInternal for " + "studentId=" + studentId
                    + " returning 0 because null gradeRecs or countedAssigns");
        List returnList = new ArrayList();
        returnList.add(new Double(0));
        returnList.add(new Double(0));
        returnList.add(new Double(0)); // 3rd one is for the pre-adjusted course grade
        return returnList;
    }

    double totalPointsEarned = 0;
    BigDecimal literalTotalPointsEarned = new BigDecimal(0d);

    Map cateScoreMap = new HashMap();
    Map cateTotalScoreMap = new HashMap();

    Set assignmentsTaken = new HashSet();
    for (AssignmentGradeRecord gradeRec : gradeRecs) {
        if (gradeRec.getPointsEarned() != null && !gradeRec.getPointsEarned().equals("")
                && !gradeRec.getDroppedFromGrade()) {
            Assignment go = gradeRec.getAssignment();
            if (go.isIncludedInCalculations() && countedAssigns.contains(go)) {
                Double pointsEarned = new Double(gradeRec.getPointsEarned());
                //if(gbGradeType == GradebookService.GRADE_TYPE_POINTS)
                //{
                if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY) {
                    totalPointsEarned += pointsEarned.doubleValue();
                    literalTotalPointsEarned = (new BigDecimal(pointsEarned.doubleValue()))
                            .add(literalTotalPointsEarned);
                    assignmentsTaken.add(go.getId());
                } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY
                        && go != null) {
                    totalPointsEarned += pointsEarned.doubleValue();
                    literalTotalPointsEarned = (new BigDecimal(pointsEarned.doubleValue()))
                            .add(literalTotalPointsEarned);
                    assignmentsTaken.add(go.getId());
                } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY
                        && go != null && categories != null) {
                    for (int i = 0; i < categories.size(); i++) {
                        Category cate = (Category) categories.get(i);
                        if (cate != null && !cate.isRemoved() && go.getCategory() != null
                                && cate.getId().equals(go.getCategory().getId())) {
                            assignmentsTaken.add(go.getId());
                            literalTotalPointsEarned = (new BigDecimal(pointsEarned.doubleValue()))
                                    .add(literalTotalPointsEarned);
                            if (cateScoreMap.get(cate.getId()) != null) {
                                cateScoreMap.put(cate.getId(),
                                        new Double(((Double) cateScoreMap.get(cate.getId())).doubleValue()
                                                + pointsEarned.doubleValue()));
                            } else {
                                cateScoreMap.put(cate.getId(), new Double(pointsEarned));
                            }
                            break;
                        }
                    }
                }
            }

        }
    }

    if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY
            && categories != null) {
        Iterator assgnsIter = countedAssigns.iterator();
        while (assgnsIter.hasNext()) {
            Assignment asgn = (Assignment) assgnsIter.next();
            if (assignmentsTaken.contains(asgn.getId())) {
                for (int i = 0; i < categories.size(); i++) {
                    Category cate = (Category) categories.get(i);
                    if (cate != null && !cate.isRemoved() && asgn.getCategory() != null
                            && cate.getId().equals(asgn.getCategory().getId()) && !asgn.isExtraCredit()) {

                        if (cateTotalScoreMap.get(cate.getId()) == null) {
                            cateTotalScoreMap.put(cate.getId(), asgn.getPointsPossible());
                        } else {
                            cateTotalScoreMap.put(cate.getId(),
                                    new Double(((Double) cateTotalScoreMap.get(cate.getId())).doubleValue()
                                            + asgn.getPointsPossible().doubleValue()));
                        }

                    }
                }
            }
        }
    }

    if (assignmentsTaken.isEmpty())
        totalPointsEarned = -1;

    if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) {
        for (int i = 0; i < categories.size(); i++) {
            Category cate = (Category) categories.get(i);
            if (cate != null && !cate.isRemoved() && cateScoreMap.get(cate.getId()) != null
                    && cateTotalScoreMap.get(cate.getId()) != null) {
                totalPointsEarned += ((Double) cateScoreMap.get(cate.getId())).doubleValue()
                        * cate.getWeight().doubleValue()
                        / ((Double) cateTotalScoreMap.get(cate.getId())).doubleValue();
            }
        }
    }

    if (log.isDebugEnabled())
        log.debug(
                "getTotalPointsEarnedInternal for studentId=" + studentId + " returning " + totalPointsEarned);
    List returnList = new ArrayList();
    returnList.add(new Double(totalPointsEarned));
    returnList.add(
            new Double((new BigDecimal(literalTotalPointsEarned.doubleValue(), GradebookService.MATH_CONTEXT))
                    .doubleValue()));
    return returnList;
}

From source file:hr.restart.util.chart.ChartXYZ.java

/**
 * Creates a org.jfree.data.CategoryDataset from a Map.
 * @param map The Map//from  www  .  j a  v  a  2 s  . c o m
 * @return The org.jfree.data.CategoryDataset
 */
final public CategoryDataset createDataset(Map map) {

    //creates the dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Set set = map.keySet();
    Iterator iterator = set.iterator();
    while (iterator.hasNext()) {

        Pair element = (Pair) iterator.next();
        Double value = (Double) map.get(element);

        dataset.addValue(value.doubleValue(), element.getFirst(), element.getSecond());

    }

    return dataset;

}