You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/01/04 12:04:31 UTC

[isis] branch master updated: ISIS-2249: sync adoc

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 88e9a07  ISIS-2249: sync adoc
88e9a07 is described below

commit 88e9a0706a134813098945c91c8c95ebde422062
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Jan 4 13:04:23 2020 +0100

    ISIS-2249: sync adoc
---
 .../modules/applib-cm/examples/value/Color.java    | 107 ------------
 .../applib-cm/examples/value/Magnitude.java        |  60 -------
 .../modules/applib-cm/examples/value/Money.java    | 184 ---------------------
 .../applib-cm/examples/value/Percentage.java       | 127 --------------
 4 files changed, 478 deletions(-)

diff --git a/core/applib/src/main/doc/modules/applib-cm/examples/value/Color.java b/core/applib/src/main/doc/modules/applib-cm/examples/value/Color.java
deleted file mode 100644
index 1cf887f..0000000
--- a/core/applib/src/main/doc/modules/applib-cm/examples/value/Color.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.applib.value;
-
-import org.apache.isis.applib.annotation.Value;
-
-/**
- * Color is simple numerical representation of a color using the brightness of
- * red, green and blue (RGB) components.
- *
- * <p>
- * Where there is no basic colors (RGB all equal 0) then you get black; where
- * each color is at maximum (RGB all equal 255) you get white.
- */
-@Value(semanticsProviderName = "org.apache.isis.metamodel.facets.value.color.ColorValueSemanticsProvider")
-public class Color extends Magnitude<Color> {
-
-    private static final long serialVersionUID = 1L;
-
-    public final static Color WHITE = new Color(0xffffff);
-    public final static Color BLACK = new Color(0);
-
-    private final int color;
-
-    public Color(final int color) {
-        this.color = color;
-    }
-
-    public int intValue() {
-        return color;
-    }
-
-    /**
-     * returns true if the number of this object has the same value as the
-     * specified number
-     */
-    @Override
-    public boolean isEqualTo(final Color number) {
-        return (number).color == color;
-    }
-
-    /**
-     * Returns true if this value is less than the specified value.
-     */
-    @Override
-    public boolean isLessThan(final Color value) {
-        return color < (value).color;
-    }
-
-    public String title() {
-        if (color == 0) {
-            return "Black";
-        } else if (color == 0xffffff) {
-            return "White";
-        } else {
-            return "#" + Integer.toHexString(color).toUpperCase();
-        }
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final Color other = (Color) obj;
-        if (color != other.color) {
-            return false;
-        }
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + color;
-        return result;
-    }
-
-    @Override
-    public String toString() {
-        return "Color: #" + Integer.toHexString(color).toUpperCase();
-    }
-}
diff --git a/core/applib/src/main/doc/modules/applib-cm/examples/value/Magnitude.java b/core/applib/src/main/doc/modules/applib-cm/examples/value/Magnitude.java
deleted file mode 100644
index c1dd052..0000000
--- a/core/applib/src/main/doc/modules/applib-cm/examples/value/Magnitude.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.applib.value;
-
-import java.io.Serializable;
-
-public abstract class Magnitude<T extends Magnitude<T>> implements Serializable {
-    private static final long serialVersionUID = 1L;
-
-    public boolean isBetween(final T minMagnitude, final T maxMagnitude) {
-        return isGreaterThanOrEqualTo(minMagnitude) && isLessThanOrEqualTo(maxMagnitude);
-    }
-
-    public abstract boolean isEqualTo(final T magnitude);
-
-    public boolean isGreaterThan(final T magnitude) {
-        return magnitude.isLessThan(thisAsT());
-    }
-
-    public boolean isGreaterThanOrEqualTo(final T magnitude) {
-        return !isLessThan(magnitude);
-    }
-
-    public abstract boolean isLessThan(final T magnitude);
-
-    public boolean isLessThanOrEqualTo(final T magnitude) {
-        return !isGreaterThan(magnitude);
-    }
-
-    public T max(final T magnitude) {
-        return isGreaterThan(magnitude) ? thisAsT() : magnitude;
-    }
-
-    public T min(final T magnitude) {
-        return isLessThan(magnitude) ? thisAsT() : magnitude;
-    }
-
-    @SuppressWarnings("unchecked")
-    private T thisAsT() {
-        return (T) this;
-    }
-
-}
diff --git a/core/applib/src/main/doc/modules/applib-cm/examples/value/Money.java b/core/applib/src/main/doc/modules/applib-cm/examples/value/Money.java
deleted file mode 100644
index 0d057c5..0000000
--- a/core/applib/src/main/doc/modules/applib-cm/examples/value/Money.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.applib.value;
-
-import java.math.BigDecimal;
-
-import org.apache.isis.applib.annotation.Value;
-
-@Value(semanticsProviderName = "org.apache.isis.metamodel.facets.value.money.MoneyValueSemanticsProvider")
-public class Money extends Magnitude<Money> {
-
-    private static final long serialVersionUID = 1L;
-    private static final int[] cents = new int[] { 1, 10, 100, 100 };
-    private final long amount;
-    private final String currency;
-
-    public Money(final double amount, final String currency) {
-        assertCurrencySet(currency);
-        this.currency = currency.toUpperCase();
-        this.amount = Math.round(amount * centFactor());
-    }
-
-    public Money(final long amount, final String currency) {
-        assertCurrencySet(currency);
-        this.currency = currency.toUpperCase();
-        this.amount = amount * centFactor();
-    }
-
-    private void assertCurrencySet(final String currency) {
-        if (currency == null || currency.equals("")) {
-            throw new IllegalArgumentException("Currency must be specified");
-        }
-        if (currency.length() != 3) {
-            throw new IllegalArgumentException("Invalid currency code '" + currency + "'");
-        }
-    }
-
-    /**
-     * Add the specified money to this money.
-     */
-    public Money add(final Money money) {
-        assertSameCurrency(money);
-        return newMoney(amount + money.amount);
-    }
-
-    private void assertSameCurrency(final Money money) {
-        if (!money.getCurrency().equals(getCurrency())) {
-            throw new IllegalArgumentException("Not the same currency: " + getCurrency() + " & " + money.getCurrency());
-        }
-    }
-
-    private int centFactor() {
-        return cents[getFractionalDigits()];
-    }
-
-    /**
-     * Returns this value as a double.
-     */
-    public double doubleValue() {
-        return amount / (double) centFactor();
-    }
-
-    /**
-     * Returns this value as a float.
-     */
-    public float floatValue() {
-        return amount;
-    }
-
-    public BigDecimal getAmount() {
-        return BigDecimal.valueOf(amount, getFractionalDigits());
-    }
-
-    public String getCurrency() {
-        return currency;
-    }
-
-    private int getFractionalDigits() {
-        return 2;
-    }
-
-    public boolean hasSameCurrency(final Money money) {
-        return currency.equals(money.currency);
-    }
-
-    /**
-     * Returns this value as an int.
-     */
-    public int intValue() {
-        return (int) amount;
-    }
-
-    @Override
-    public boolean isEqualTo(final Money magnitude) {
-        if (!hasSameCurrency(magnitude)) {
-            throw new IllegalArgumentException("Parameter must be of type Money and have the same currency");
-        }
-        return (magnitude).amount == amount;
-    }
-
-    public boolean isGreaterThanZero() {
-        return amount > 0;
-    }
-
-    @Override
-    public boolean isLessThan(final Money magnitude) {
-        if (!hasSameCurrency(magnitude)) {
-            throw new IllegalArgumentException("Parameter must be of type Money and have the same currency");
-        }
-        return amount < (magnitude).amount;
-    }
-
-    /**
-     * Returns true if this value is less than zero.
-     */
-    public boolean isLessThanZero() {
-        return amount < 0;
-    }
-
-    public boolean isZero() {
-        return amount == 0;
-    }
-
-    /**
-     * Returns this value as an long.
-     */
-    public long longValue() {
-        return amount;
-    }
-
-    private Money newMoney(final long amount) {
-        return new Money(amount / (centFactor() * 1.0), this.currency);
-    }
-
-    /**
-     * Subtract the specified amount from this value.
-     */
-    public Money subtract(final Money money) {
-        assertSameCurrency(money);
-        return newMoney(amount - money.amount);
-    }
-
-    @Override
-    public boolean equals(final Object other) {
-        if (this == other) {
-            return true;
-        }
-        if (other == null) {
-            return false;
-        }
-        return other.getClass() == this.getClass() && equals((Money) other);
-    }
-
-    public boolean equals(final Money other) {
-        return other.currency.equals(currency) && other.amount == amount;
-    }
-
-    @Override
-    public int hashCode() {
-        return (int) amount;
-    }
-
-    @Override
-    public String toString() {
-        return amount / (centFactor() * 1.0) + " " + currency;
-    }
-}
diff --git a/core/applib/src/main/doc/modules/applib-cm/examples/value/Percentage.java b/core/applib/src/main/doc/modules/applib-cm/examples/value/Percentage.java
deleted file mode 100644
index 86576c2..0000000
--- a/core/applib/src/main/doc/modules/applib-cm/examples/value/Percentage.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- */
-
-package org.apache.isis.applib.value;
-
-import org.apache.isis.applib.annotation.Value;
-
-@Value(semanticsProviderName = "org.apache.isis.metamodel.facets.value.percentage.PercentageValueSemanticsProvider")
-public class Percentage extends Magnitude<Percentage> {
-
-    private static final long serialVersionUID = 1L;
-    private final float value;
-
-    public Percentage(final float value) {
-        this.value = value;
-    }
-
-    public Percentage add(final float value) {
-        return new Percentage((floatValue() + value));
-    }
-
-    public Percentage add(final Percentage value) {
-        return add(value.floatValue());
-    }
-
-    /**
-     * Returns this value as an double.
-     */
-    public double doubleValue() {
-        return value;
-    }
-
-    /**
-     * Returns this value as an float.
-     */
-    public float floatValue() {
-        return value;
-    }
-
-    /**
-     * Returns this value as an int.
-     */
-    public int intValue() {
-        return (int) value;
-    }
-
-    /**
-     */
-    @Override
-    public boolean isEqualTo(final Percentage magnitude) {
-        return (magnitude).value == value;
-    }
-
-    @Override
-    public boolean isLessThan(final Percentage magnitude) {
-        return value < (magnitude).value;
-    }
-
-    /**
-     * Returns this value as an long.
-     */
-    public long longValue() {
-        return (long) value;
-    }
-
-    public Percentage multiply(final float value) {
-        return new Percentage((floatValue() * value));
-    }
-
-    /**
-     * Returns this value as an short.
-     */
-    public short shortValue() {
-        return (short) value;
-    }
-
-    public Percentage subtract(final float value) {
-        return add(-value);
-    }
-
-    public Percentage subtract(final Percentage value) {
-        return add(-value.floatValue());
-    }
-
-    @Override
-    public boolean equals(final Object other) {
-        if (this == other) {
-            return true;
-        }
-        if (other == null) {
-            return false;
-        }
-        return other.getClass() == this.getClass() && equals((Percentage) other);
-    }
-
-    public boolean equals(final Percentage other) {
-        return value == other.value;
-    }
-
-    @Override
-    public int hashCode() {
-        // multiply by 100 just in case the percentage is being stored as 0.0 to
-        // 1.0
-        return (int) (floatValue() * 100);
-    }
-
-    @Override
-    public String toString() {
-        return "" + value;
-    }
-}