You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/06 11:10:34 UTC
[9/51] [partial] ISIS-188: moving modules into core
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBuffer.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBuffer.java b/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBuffer.java
deleted file mode 100644
index e7fe610..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBuffer.java
+++ /dev/null
@@ -1,386 +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.util;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * Title buffer is a utility class to help produce titles for objects without
- * having to add lots of guard code. It provides two basic method: one to
- * concatenate a title to the buffer; another to append a title with a joiner
- * string, taking care adding in necessary spaces. The benefits of using this
- * class is that null references are safely ignored (rather than appearing as
- * 'null'), and joiners (a space by default) are only added when needed.
- */
-public class TitleBuffer {
- private static final String SPACE = " ";
-
- /**
- * Determines if the specified object's title (from its
- * <code>toString</code> method) is empty. Will return true if either: the
- * specified reference is null; the object's <code>toString</code> method
- * returns null; or if the <code>toString</code> returns an empty string.
- */
- public static boolean isEmpty(final Object object) {
- final String title = titleFor(object);
- return title == null || title.equals("");
- }
-
- /**
- * Reflectively run the <tt>String title()</tt> method if it exists, else
- * fall back to the <tt>toString()</tt> method.
- */
- private static String titleFor(final Object object) {
- if (object == null) {
- return null;
- } else {
- Method method;
- try {
- method = object.getClass().getMethod("title", new Class[0]);
- return (String) method.invoke(object, new Object[0]);
- } catch (final SecurityException e) {
- throw new TitleBufferException(e);
- } catch (final NoSuchMethodException e) {
- return object.toString();
- } catch (final IllegalArgumentException e) {
- throw new TitleBufferException(e);
- } catch (final IllegalAccessException e) {
- throw new TitleBufferException(e);
- } catch (final InvocationTargetException e) {
- throw new TitleBufferException(e);
- }
- }
- }
-
- /**
- * Determines if the specified text is empty. Will return true if either:
- * the specified reference is null; or if the reference is an empty string.
- */
- public static boolean isEmpty(final String text) {
- return text == null || text.equals("");
- }
-
- private final StringBuffer title;
-
- /**
- * Creates a new, empty, title object.
- */
- public TitleBuffer() {
- title = new StringBuffer();
- }
-
- /**
- * Creates a new title object, containing the title of the specified object.
- */
- public TitleBuffer(final Object object) {
- this();
- concat(object);
- }
-
- /**
- * Creates a new title object, containing the title of the specified object.
- */
- public TitleBuffer(final Object object, final String defaultTitle) {
- this();
- if (isEmpty(object)) {
- concat(defaultTitle);
- } else {
- concat(object);
- }
- }
-
- /**
- * Creates a new title object, containing the specified text.
- */
- public TitleBuffer(final String text) {
- this();
- concat(text);
- }
-
- /**
- *
- */
- public TitleBuffer append(final int number) {
- append(String.valueOf(number));
- return this;
- }
-
- /**
- * Append the title of the specified object.
- */
- public TitleBuffer append(final Object object) {
- if (!isEmpty(object)) {
- appendWithSpace(object);
- }
- return this;
- }
-
- /**
- * Appends the title of the specified object, or the specified text if the
- * objects title is null or empty. Prepends a space if there is already some
- * text in this title object.
- *
- * @param object
- * the object whose title is to be appended to this title.
- * @param defaultValue
- * a textual value to be used if the object's title is null or
- * empty.
- * @return a reference to the called object (itself).
- */
- public TitleBuffer append(final Object object, final String defaultValue) {
- if (!isEmpty(object)) {
- appendWithSpace(object);
- } else {
- appendWithSpace(defaultValue);
- }
- return this;
- }
-
- /**
- * Appends a space (if there is already some text in this title object) and
- * then the specified text.
- *
- * @return a reference to the called object (itself).
- */
- public TitleBuffer append(final String text) {
- if (!isEmpty(text)) {
- appendWithSpace(text);
- }
- return this;
- }
-
- /**
- * Appends the joining string and the title of the specified object (from
- * its <code>toString</code> method). If the object is empty then nothing
- * will be appended.
- *
- * @see #isEmpty(Object)
- */
- public TitleBuffer append(final String joiner, final Object object) {
- if (!isEmpty(object)) {
- appendJoiner(joiner);
- appendWithSpace(object);
- }
- return this;
- }
-
- /**
- * Append the <code>joiner</code> text, a space, and the title of the
- * specified ObjectAdapter (<code>object</code>) (got by calling the objects
- * title() method) to the text of this TitleString object. If the title of
- * the specified object is null then use the <code>defaultValue</code> text.
- * If both the objects title and the default value are null or equate to a
- * zero-length string then no text will be appended ; not even the joiner
- * text.
- *
- * @param joiner
- * text to append before the title
- * @param object
- * object whose title needs to be appended
- * @param defaultTitle
- * the text to use if the the object's title is null.
- * @return a reference to the called object (itself).
- */
- public TitleBuffer append(final String joiner, final Object object, final String defaultTitle) {
- appendJoiner(joiner);
- if (!isEmpty(object)) {
- appendWithSpace(object);
- } else {
- appendWithSpace(defaultTitle);
- }
- return this;
- }
-
- /**
- * Appends the joiner text, a space, and the text to the text of this
- * TitleString object. If no text yet exists in the object then the joiner
- * text and space are omitted.
- *
- * @return a reference to the called object (itself).
- */
- public TitleBuffer append(final String joiner, final String text) {
- if (!isEmpty(text)) {
- appendJoiner(joiner);
- appendWithSpace(text);
- }
- return this;
- }
-
- private void appendJoiner(final String joiner) {
- if (title.length() > 0) {
- title.append(joiner);
- }
- }
-
- /**
- * Append a space to the text of this TitleString object if, and only if,
- * there is some existing text i.e., a space is only added to existing text
- * and will not create a text entry consisting of only one space.
- *
- * @return a reference to the called object (itself).
- */
- public TitleBuffer appendSpace() {
- if (title.length() > 0) {
- title.append(SPACE);
- }
- return this;
- }
-
- private void appendWithSpace(final Object object) {
- appendSpace();
- title.append(titleFor(object));
- }
-
- /**
- * Concatenate the the title value (the result of calling an objects label()
- * method) to this TitleString object. If the value is null the no text is
- * added.
- *
- * @param object
- * the ObjectAdapter to get a title from
- * @return a reference to the called object (itself).
- */
- public final TitleBuffer concat(final Object object) {
- concat(object, "");
- return this;
- }
-
- /**
- * Concatenate the the title value (the result of calling an objects label()
- * method), or the specified default value if the title is equal to null or
- * is empty, to this TitleString object.
- *
- * @param object
- * the ObjectAdapter to get a title from
- * @param defaultValue
- * the default text to use when the ObjectAdapter is null
- * @return a reference to the called object (itself).
- */
- public final TitleBuffer concat(final Object object, final String defaultValue) {
- if (isEmpty(object)) {
- title.append(defaultValue);
- } else {
- title.append(titleFor(object));
- }
-
- return this;
- }
-
- /**
- * Concatenate the specified text on to the end of the text of this
- * TitleString.
- *
- * @param text
- * text to append
- * @return a reference to the called object (itself).
- */
- public final TitleBuffer concat(final String text) {
- title.append(text);
- return this;
- }
-
- /**
- * Concatenate the joiner text and the text to the text of this TitleString
- * object. If no text yet exists in the object then the joiner text is
- * omitted.
- *
- * @return a reference to the called object (itself).
- */
- public TitleBuffer concat(final String joiner, final String text) {
- if (!isEmpty(text)) {
- appendJoiner(joiner);
- title.append(text);
- }
- return this;
- }
-
- /**
- * Concatenate the joiner text and the title of the object to the text of
- * this TitleString object. If no object yet exists in the object then the
- * joiner text is omitted.
- *
- * @return a reference to the called object (itself).
- */
- public final TitleBuffer concat(final String joiner, final Object object) {
- if (!isEmpty(object)) {
- appendJoiner(joiner);
- concat(object, "");
- }
- return this;
- }
-
- /**
- * Concatenate the joiner text and the title of the object to the text of
- * this TitleString object. If no object yet exists in the object then
- * defaultValue is used instead.
- *
- * @return a reference to the called object (itself).
- */
- public final TitleBuffer concat(final String joiner, final Object object, final String defaultValue) {
- if (isEmpty(object)) {
- appendJoiner(joiner);
- title.append(defaultValue);
- } else {
- appendJoiner(joiner);
- title.append(titleFor(object));
- }
- return this;
- }
-
- /**
- * Returns a String that represents the value of this object.
- */
- @Override
- public String toString() {
- return title.toString();
- }
-
- /**
- * Truncates this title so it has a maximum number of words. Spaces are used
- * to determine words, thus two spaces in a title will cause two words to be
- * mistakenly identified.
- *
- * @param noWords
- * the number of words to show
- * @return a reference to the called object (itself).
- */
- public TitleBuffer truncate(final int noWords) {
- if (noWords < 1) {
- throw new IllegalArgumentException("Truncation must be to one or more words");
- }
- int pos = 0;
- int spaces = 0;
-
- while (pos < title.length() && spaces < noWords) {
- if (title.charAt(pos) == ' ') {
- spaces++;
- }
- pos++;
- }
- if (pos < title.length()) {
- title.setLength(pos - 1); // string.delete(pos - 1,
- // string.length());
- title.append("...");
- }
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBufferException.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBufferException.java b/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBufferException.java
deleted file mode 100644
index 0928182..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/util/TitleBufferException.java
+++ /dev/null
@@ -1,48 +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.util;
-
-public class TitleBufferException extends RuntimeException {
- private static final long serialVersionUID = 1L;
- private Throwable cause;
-
- public TitleBufferException() {
- super();
- }
-
- public TitleBufferException(final String msg) {
- super(msg);
- }
-
- public TitleBufferException(final Throwable cause) {
- this(cause.getMessage());
- this.cause = cause;
- }
-
- public TitleBufferException(final String msg, final Throwable cause) {
- this(msg);
- this.cause = cause;
- }
-
- @Override
- public Throwable getCause() {
- return cause;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/util/package-info.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/util/package-info.java b/framework/applib/src/main/java/org/apache/isis/applib/util/package-info.java
deleted file mode 100644
index 0425f23..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/util/package-info.java
+++ /dev/null
@@ -1,40 +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.
- */
-
-/**
- * This package defines a small number of utility classes for
- * generating {@link org.apache.isis.applib.util.TitleBuffer title}s for
- * domain objects and for generating
- * {@link org.apache.isis.applib.util.ReasonBuffer reason}s (why a
- * class member is disabled or a proposed value invalid).
- *
- * <p>
- * This is an implementation of the DDD "Specification", allowing
- * validatation that might otherwise be repeated for both properties and
- * parameters (in the <tt>validateXxx()</tt> methods to be factored out.
- *
- * <p>
- * That said, there is still some repetition in that the {@link org.apache.isis.applib.annotation.MustSatisfy}
- * annotation must be applied in all appropriate cases. If it is the case that
- * the validation rules would apply <i>every</i> case, then it is generally
- * preferable to implement a {@link org.apache.isis.applib.annotation.Value} type
- * through the {@link org.apache.isis.applib.adapters.ValueSemanticsProvider}
- * interface.
- */
-package org.apache.isis.applib.util;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Blob.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Blob.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Blob.java
deleted file mode 100644
index 58058a6..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/Blob.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.apache.isis.applib.value;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-import javax.activation.MimeType;
-import javax.activation.MimeTypeParseException;
-
-import com.google.common.io.ByteStreams;
-import com.google.common.io.OutputSupplier;
-
-public final class Blob implements Serializable {
-
- /**
- * Computed for state:
- * <pre>
- * private final MimeType mimeType;
- * private final byte[] bytes;
- * private final String name;
- * </pre>
- */
- private static final long serialVersionUID = 5659679806709601263L;
-
- private final MimeType mimeType;
- private final byte[] bytes;
- private final String name;
-
- public Blob(String name, String primaryType, String subtype, byte[] bytes) {
- this(name, newMimeType(primaryType, subtype), bytes);
- }
-
- public Blob(String name, String mimeTypeBase, byte[] bytes) {
- this(name, newMimeType(mimeTypeBase), bytes);
- }
-
- public Blob(String name, MimeType mimeType, byte[] bytes) {
- if(name.contains(":")) {
- throw new IllegalArgumentException("Name cannot contain ':'");
- }
- this.name = name;
- this.mimeType = mimeType;
- this.bytes = bytes;
- }
-
- private static MimeType newMimeType(String primaryType, String subtype) {
- try {
- return new MimeType(primaryType, subtype);
- } catch (MimeTypeParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- private static MimeType newMimeType(String baseType) {
- try {
- return new MimeType(baseType);
- } catch (MimeTypeParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public String getName() {
- return name;
- }
-
- public MimeType getMimeType() {
- return mimeType;
- }
-
- public byte[] getBytes() {
- return bytes;
- }
-
- public void writeBytesTo(final OutputStream os) throws IOException {
- ByteStreams.write(bytes, new OutputSupplier<OutputStream>() {
- @Override
- public OutputStream getOutput() throws IOException {
- return os;
- }
- });
- }
-
- @Override
- public String toString() {
- return getName() + " [" + getMimeType().getBaseType() + "]: " + getBytes().length + " bytes";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Clob.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Clob.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Clob.java
deleted file mode 100644
index a49429a..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/Clob.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.apache.isis.applib.value;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import javax.activation.MimeType;
-import javax.activation.MimeTypeParseException;
-
-import com.google.common.io.CharStreams;
-import com.google.common.io.OutputSupplier;
-
-public final class Clob {
-
- private final String name;
- private final MimeType mimeType;
- private final CharSequence chars;
-
- public Clob(String name, String primaryType, String subType, char[] chars) {
- this(name, primaryType, subType, new String(chars));
- }
-
- public Clob(String name, String mimeTypeBase, char[] chars) {
- this(name, mimeTypeBase, new String(chars));
- }
-
- public Clob(String name, MimeType mimeType, char[] chars) {
- this(name, mimeType, new String(chars));
- }
-
- public Clob(String name, String primaryType, String subType, CharSequence chars) {
- this(name, newMimeType(primaryType, subType), chars);
- }
-
- public Clob(String name, String mimeTypeBase, CharSequence chars) {
- this(name, newMimeType(mimeTypeBase), chars);
- }
-
- public Clob(String name, MimeType mimeType, CharSequence chars) {
- if(name.contains(":")) {
- throw new IllegalArgumentException("Name cannot contain ':'");
- }
- this.name = name;
- this.mimeType = mimeType;
- this.chars = chars;
- }
-
- private static MimeType newMimeType(String baseType) {
- try {
- return new MimeType(baseType);
- } catch (MimeTypeParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- private static MimeType newMimeType(String primaryType, String subType) {
- try {
- return new MimeType(primaryType, subType);
- } catch (MimeTypeParseException e) {
- throw new IllegalArgumentException(e);
- }
- }
-
- public String getName() {
- return name;
- }
-
- public MimeType getMimeType() {
- return mimeType;
- }
-
- public CharSequence getChars() {
- return chars;
- }
-
- public void writeCharsTo(final Writer wr) throws IOException {
- CharStreams.write(chars, new OutputSupplier<Writer>() {
- @Override
- public Writer getOutput() throws IOException {
- return wr;
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Color.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Color.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Color.java
deleted file mode 100644
index 588e504..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/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.core.progmodel.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();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Date.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Date.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Date.java
deleted file mode 100644
index 827ead8..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/Date.java
+++ /dev/null
@@ -1,294 +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.joda.time.DateTime;
-import org.joda.time.DateTimeFieldType;
-import org.joda.time.Period;
-import org.joda.time.format.DateTimeFormat;
-
-import org.apache.isis.applib.Defaults;
-import org.apache.isis.applib.annotation.Value;
-import org.apache.isis.applib.clock.Clock;
-
-/**
- * Value object representing a date (not time) value.
- *
- * <p>
- * TODO: other methods to implement comparison methods:
- * <ul>
- * <li>sameDateAs() day == day & month == month & year == year</li>
- * <li>withinNextDatePeriod(int days, int months, int years)</li>
- * <li>withinDatePeriod(int days, int months, int years)</li>
- * <li>withinPreviousDatePeriod(int days, int months, int years)</li>
- * </ul>
- */
-@Value(semanticsProviderName = "org.apache.isis.core.progmodel.facets.value.date.DateValueSemanticsProvider")
-public class Date extends Magnitude<Date> {
- private static final long serialVersionUID = 1L;
- private final DateTime date;
-
- /**
- * Create a Date object for today's date.
- */
- public Date() {
- final DateTime time = Clock.getTimeAsDateTime().withTime(0, 0, 0, 0);
- date = new DateTime(time, Defaults.getTimeZone());
- }
-
- /**
- * Create a Date object set to the specified day, month and year.
- */
- public Date(final int year, final int month, final int day) {
- checkDate(year, month, day);
- date = newDateTime(year, month, day);
- }
-
- /**
- * Create a Date object based on the specified Java date object. The time
- * portion of the Java date is disposed of.
- */
- public Date(final java.util.Date date) {
- this.date = new DateTime(date.getTime(), Defaults.getTimeZone());
- }
-
- public Date(final long millisSinceEpoch) {
- this.date = new DateTime(millisSinceEpoch);
- }
-
- public Date(final DateTime date) {
- this.date = new DateTime(date);
- }
-
- private DateTime newDateTime(final int year, final int month, final int day) {
- return new DateTime(year, month, day, 0, 0, 0, 0, Defaults.getTimeZone());
- }
-
- protected Date createDate(final DateTime date) {
- final Date newDate = new Date(date);
- return newDate;
- }
-
- /**
- * Add the specified days, years and months to this date value and return a
- * new date object containing the result.
- */
- public Date add(final int years, final int months, final int days) {
- final Period add = new Period(years, months, 0, days, 0, 0, 0, 0);
- final DateTime newDate = date.plus(add);
- return new Date(newDate);
- }
-
- private void checkDate(final int year, final int month, final int day) {
- if ((month < 1) || (month > 12)) {
- throw new IllegalArgumentException("Month must be in the range 1 - 12 inclusive");
- }
- final DateTime newDate = newDateTime(year, month, 1);
- final int lastDayOfMonth = newDate.dayOfMonth().getMaximumValue();
- ;
- if ((day < 1) || (day > lastDayOfMonth)) {
- throw new IllegalArgumentException("Day must be in the range 1 - " + lastDayOfMonth + " inclusive: " + day);
- }
- }
-
- /**
- * Return this date value as a Java Date object.
- *
- * @see java.util.Date
- */
- public java.util.Date dateValue() {
- final java.util.Date javaDate = date.toDate();
- return javaDate;
- }
-
- /**
- *
- * @return the milliseconds from 1970-01-01T00:00:00Z
- */
- public long getMillisSinceEpoch() {
- return date.getMillis();
- }
-
- /**
- * Calculates, and returns, a date representing the last day of the month
- * relative to the current date.
- *
- * @author Joshua Cassidy
- */
- public Date endOfMonth() {
- return new Date(date.dayOfMonth().withMaximumValue());
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Date)) {
- return false;
- }
- final Date date1 = (Date) o;
- if (!date.equals(date1.date)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- return date.hashCode();
- }
-
- /**
- * Return the day from this date, in the range 1 - 31.
- */
- public int getDay() {
- return date.getDayOfMonth();
- }
-
- /**
- * Calculates, and returns, an int representing the day of the week relative
- * to the current date. With Mon = 0 through to Sun = 6
- *
- * @author Joshua Cassidy
- */
- public int getDayOfWeek() {
- return date.getDayOfWeek() - 1; // Mon - Sun == 1 - 7
- }
-
- /**
- * Return the month from this date, in the range 1 - 12.
- */
- public int getMonth() {
- return date.getMonthOfYear();
- }
-
- /**
- * Return the year from this date.
- */
- public int getYear() {
- return date.getYear();
- }
-
- /**
- * Returns true if the date of this object has the same value as the
- * specified date
- */
- @Override
- public boolean isEqualTo(final Date date) {
- return this.date.equals((date).date);
- }
-
- /**
- * Returns true if the time of this object is earlier than the specified
- * time
- */
- @Override
- public boolean isLessThan(final Date date) {
- return this.date.isBefore((date).date);
- }
-
- private boolean sameAs(final Date as, final DateTimeFieldType field) {
-
- return date.get(field) == as.date.get(field);
- }
-
- /**
- * Determines if this date and the specified date represent the same day of
- * the month, eg both dates are for the 3rd.
- */
- public boolean sameDayOfMonthAs(final Date as) {
- return sameAs(as, DateTimeFieldType.dayOfMonth());
- }
-
- /**
- * Determines if this date and the specified date represent the same day of
- * the week, eg both dates are on a Tuesday.
- */
- public boolean sameDayOfWeekAs(final Date as) {
- return sameAs(as, DateTimeFieldType.dayOfWeek());
- }
-
- /**
- * Determines if this date and the specified date represent the same day of
- * the year, eg both dates are for the 108th day of the year.
- */
- public boolean sameDayOfYearAs(final Date as) {
- return sameAs(as, DateTimeFieldType.dayOfYear());
- }
-
- /**
- * Determines if this date and the specified date represent the same month,
- * eg both dates are for the March.
- */
- public boolean sameMonthAs(final Date as) {
- return sameAs(as, DateTimeFieldType.monthOfYear());
- }
-
- /**
- * Determines if this date and the specified date represent the same week in
- * the year, eg both dates are the for the 18th week of the year.
- */
- public boolean sameWeekAs(final Date as) {
- return sameAs(as, DateTimeFieldType.weekOfWeekyear());
- }
-
- /**
- * Determines if this date and the specified date represent the same year.
- */
- public boolean sameYearAs(final Date as) {
- return sameAs(as, DateTimeFieldType.year());
- }
-
- /**
- * Calculates, and returns, a date representing the first day of the month
- * relative to the current date.
- */
- public Date startOfMonth() {
- return new Date(date.dayOfMonth().withMinimumValue());
- }
-
- /**
- * Calculates, and returns, a date representing the first day of the week
- * relative to the current date.
- */
- public Date startOfWeek() {
- return new Date(date.dayOfWeek().withMinimumValue());
- }
-
- /**
- * Calculates, and returns, a date representing the first day of the year
- * relative to the current date.
- */
- public Date startOfYear() {
- return new Date(date.dayOfYear().withMinimumValue());
- }
-
- public String title() {
- return DateTimeFormat.mediumDate().print(date);
- }
-
- @Override
- public String toString() {
- // return getYear() + "-" + getMonth() + "-" + getDay();
- return String.format("%04d-%02d-%02d", getYear(), getMonth(), getDay());
-
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/DateTime.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/DateTime.java b/framework/applib/src/main/java/org/apache/isis/applib/value/DateTime.java
deleted file mode 100644
index 18ad79e..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/DateTime.java
+++ /dev/null
@@ -1,319 +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.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-
-import org.joda.time.DateTimeZone;
-import org.joda.time.Period;
-
-import org.apache.isis.applib.Defaults;
-import org.apache.isis.applib.annotation.Value;
-import org.apache.isis.applib.clock.Clock;
-
-/**
- * Value object representing a date and time value. By default, the time is
- * initialised to the current time, unless otherwise specified.
- */
-@Value(semanticsProviderName = "org.apache.isis.core.progmodel.facets.value.datetime.DateTimeValueSemanticsProvider")
-public class DateTime extends Magnitude<DateTime> {
-
- private static final long serialVersionUID = 1L;
- private final org.joda.time.DateTime dateTime;
-
- /**
- * Create a Time object for storing a timeStamp set to the current time.
- */
- public DateTime() {
- final org.joda.time.DateTime d = new org.joda.time.DateTime(Clock.getTime(), Defaults.getTimeZone());
- // dateTime = d.secondOfMinute().setCopy(0);
- dateTime = d;
- }
-
- /**
- * Create a DateTime from the provided java.util.Date, assuming that the
- * date is in UTC. If not, see {@link DateTime#}
- *
- * @param date
- */
- public DateTime(final Date date) {
- this.dateTime = new org.joda.time.DateTime(date, Defaults.getTimeZone());
- }
-
- public DateTime(final long millisSinceEpoch) {
- this.dateTime = new org.joda.time.DateTime(millisSinceEpoch, Defaults.getTimeZone());
- }
-
- public DateTime(final Date date, final TimeZone timeZone) {
- final DateTimeZone tz = DateTimeZone.forTimeZone(timeZone);
- this.dateTime = new org.joda.time.DateTime(date, tz);
- }
-
- public DateTime(final org.joda.time.DateTime dateTime) {
- this.dateTime = new org.joda.time.DateTime(dateTime);
- }
-
- /**
- * Creates a DateTime on the specified day/month/year, with the current time
- */
- public DateTime(final int year, final int month, final int day) {
- final Time time = new Time();
- // this(year, month, day, time.getHour(), time.getMinute(), 0);
-
- // replace below with something more like the above..
- checkTime(year, month, day, 0, 0);
- dateTime = new org.joda.time.DateTime(year, month, day, time.getHour(), time.getMinute(), time.getSecond(), 0, Defaults.getTimeZone());
- }
-
- /**
- * Create a Date object set to the specified day, month, year, hour, minute.
- */
- public DateTime(final int year, final int month, final int day, final int hour, final int minute) {
- this(year, month, day, hour, minute, 0);
- }
-
- /**
- * Create a Date object set to the specified day, month, year, hour, minute,
- * and second.
- */
- public DateTime(final int year, final int month, final int day, final int hour, final int minute, final int second) {
- checkTime(year, month, day, hour, minute);
- dateTime = new org.joda.time.DateTime(year, month, day, hour, minute, second, 0, Defaults.getTimeZone());
- }
-
- private void checkTime(final int year, final int month, final int day, final int hour, final int minute) {
- if ((month < 1) || (month > 12)) {
- throw new IllegalArgumentException("Month must be in the range 1 - 12 inclusive " + month);
- }
-
- final org.joda.time.DateTime dateTime = new org.joda.time.DateTime(year, month, 1, 0, 0, 0, 0);
- final int lastDayOfMonth = dateTime.dayOfMonth().getMaximumValue();
-
- if ((day < 1) || (day > lastDayOfMonth)) {
- throw new IllegalArgumentException("Day must be in the range 1 - " + lastDayOfMonth + " inclusive " + day);
- }
-
- if ((hour < 0) || (hour > 23)) {
- throw new IllegalArgumentException("Hour must be in the range 0 - 23 inclusive " + hour);
- }
-
- if ((minute < 0) || (minute > 59)) {
- throw new IllegalArgumentException("Minute must be in the range 0 - 59 inclusive " + minute);
- }
- }
-
- /**
- * Add the specified time period to this date value.
- */
- public DateTime add(final int years, final int months, final int days, final int hours, final int minutes) {
- final Period period = new Period(years, months, 0, days, hours, minutes, 0, 0);
- final org.joda.time.DateTime dateTime = this.dateTime.plus(period);
- return new DateTime(dateTime);
- }
-
- /**
- * Add the specified days, years and months to this date value.
- */
- public DateTime add(final int years, final int months, final int days) {
- return add(years, months, days, 0, 0);
- }
-
- public Calendar calendarValue() {
- return dateTime.toGregorianCalendar();
- }
-
- protected DateTime createDateTime(final Date date) {
- return new DateTime(date);
- }
-
- /**
- * Be careful - the TimeZone of the java.util.Date is based on the system
- * default.
- */
- public java.util.Date dateValue() {
- return new Date(dateTime.getMillis());
- }
-
- /**
- *
- * @return the milliseconds from 1970-01-01T00:00:00Z
- */
- public long getMillisSinceEpoch() {
- return dateTime.getMillis();
- }
-
- public int getSeconds() {
- return dateTime.getSecondOfMinute();
- }
-
- public int getMinute() {
- return dateTime.getMinuteOfHour();
- }
-
- public int getHour() {
- return dateTime.getHourOfDay();
- }
-
- public int getDay() {
- return dateTime.getDayOfMonth();
- }
-
- public int getMonth() {
- return dateTime.getMonthOfYear();
- }
-
- public int getYear() {
- return dateTime.getYear();
- }
-
- /**
- * Day of year (1 to 365 [366 in leap years]) for Gregorian calendar.
- *
- * @return
- */
- public int getDayOfYear() {
- return dateTime.getDayOfYear();
- }
-
- /**
- * A DateTime that is at the start of the current week. Time is preserved.
- */
- public DateTime startOfWeek() {
- return new DateTime(dateTime.withDayOfWeek(1));
- }
-
- /**
- * A DateTime that represents the start of the current month. Time is
- * preserved.
- */
- public DateTime startOfMonth() {
- return new DateTime(dateTime.withDayOfMonth(1));
- }
-
- /**
- * This DateTime, but on the first day of the year. Time is preserved.
- */
- public DateTime startOfYear() {
- return new DateTime(dateTime.withDayOfYear(1));
- }
-
- /**
- * returns true if the time stamp of this object has the same value as the
- * specified time
- */
- @Override
- public boolean isEqualTo(final DateTime timeStamp) {
- return this.dateTime.equals((timeStamp).dateTime);
- }
-
- /**
- * returns true if the timeStamp of this object is earlier than the
- * specified timeStamp
- */
- @Override
- public boolean isLessThan(final DateTime timeStamp) {
- return dateTime.isBefore((timeStamp).dateTime);
- }
-
- public boolean isSameDayAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : getDayOfYear() == dateTime2.getDayOfYear();
- }
-
- public boolean sameDayOfWeekAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : dateTime.getDayOfWeek() == dateTime2.dateTime.getDayOfWeek();
- }
-
- public boolean sameDayOfMonthAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : dateTime.getDayOfMonth() == dateTime2.dateTime.getDayOfMonth();
- }
-
- public boolean sameDayOfYearAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : dateTime.getDayOfYear() == dateTime2.dateTime.getDayOfYear();
- }
-
- public boolean sameWeekAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : dateTime.getWeekOfWeekyear() == dateTime2.dateTime.getWeekOfWeekyear();
- }
-
- public boolean sameMonthAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : getMonth() == dateTime2.getMonth();
- }
-
- public boolean sameYearAs(final DateTime dateTime2) {
- return dateTime2 == null ? false : getYear() == dateTime2.getYear();
- }
-
- @Deprecated
- /**
- * See millisSinceEpoch()
- */
- public long longValue() {
- return millisSinceEpoch();
- }
-
- /**
- * Gets the milliseconds since the Java epoch of 1970-01-01T00:00:00Z
- */
- public long millisSinceEpoch() {
- return dateTime.getMillis();
- }
-
-
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final DateTime other = (DateTime) obj;
- if (dateTime == null) {
- if (other.dateTime != null) {
- return false;
- }
- } else if (!dateTime.equals(other.dateTime)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((dateTime == null) ? 0 : dateTime.hashCode());
- return result;
- }
-
- @Override
- public String toString() {
- // return getYear() + "-" + getMonth() + "-" + getDay() + " " +
- // getHour() + ":" + getMinute();
- return String.format("%04d-%02d-%02d %02d:%02d", getYear(), getMonth(), getDay(), getHour(), getMinute());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Image.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Image.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Image.java
deleted file mode 100644
index 90d05e9..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/Image.java
+++ /dev/null
@@ -1,59 +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;
-
-import org.apache.isis.applib.annotation.Value;
-
-/**
- * Represents an image.
- */
-@Value(semanticsProviderName = "org.apache.isis.core.progmodel.facets.value.image.ImageValueSemanticsProvider")
-public class Image implements Serializable {
- private static final long serialVersionUID = 1L;
- private final int[][] image;
-
- public Image(final int[][] image) {
- this.image = image;
- }
-
- public Object getValue() {
- return image;
- }
-
- @Override
- public String toString() {
- final int height = getHeight();
- return "Image [size=" + height + "x" + (height == 0 || image[0] == null ? 0 : image[0].length) + "]";
- }
-
- public int[][] getImage() {
- return image;
- }
-
- public int getHeight() {
- return image == null ? 0 : image.length;
- }
-
- public int getWidth() {
- return image == null ? 0 : image[0].length;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Magnitude.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Magnitude.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Magnitude.java
deleted file mode 100644
index c1dd052..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Money.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Money.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Money.java
deleted file mode 100644
index 30105cd..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/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.core.progmodel.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;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Password.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Password.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Password.java
deleted file mode 100644
index 8715997..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/Password.java
+++ /dev/null
@@ -1,78 +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;
-
-import org.apache.isis.applib.annotation.Value;
-
-@Value(semanticsProviderName = "org.apache.isis.core.progmodel.facets.value.password.PasswordValueSemanticsProvider")
-public class Password implements Serializable {
- private static final long serialVersionUID = 1L;
- private static final String STARS = "********************";
- private final String password;
-
- public Password(final String password) {
- this.password = password;
- }
-
- public boolean checkPassword(final String password) {
- return this.password.equals(password);
- }
-
- public String getPassword() {
- return password;
- }
-
- @Override
- public boolean equals(final Object other) {
- if (other == this) {
- return true;
- }
- if (other == null) {
- return false;
- }
- return other.getClass() == this.getClass() && equals((Password) other);
- }
-
- public boolean equals(final Password other) {
- final String otherPassword = other.getPassword();
- if (getPassword() == null && otherPassword == null) {
- return true;
- }
- if (getPassword() == null || otherPassword == null) {
- return false;
- }
- return getPassword().equals(otherPassword);
- }
-
- @Override
- public int hashCode() {
- return password != null ? password.hashCode() : 0;
- }
-
- @Override
- public String toString() {
- if (password == null) {
- return "";
- }
- return STARS.substring(0, Math.min(STARS.length(), password.length()));
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Percentage.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Percentage.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Percentage.java
deleted file mode 100644
index 2e30354..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/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.core.progmodel.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;
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/Time.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/Time.java b/framework/applib/src/main/java/org/apache/isis/applib/value/Time.java
deleted file mode 100644
index 974cc03..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/Time.java
+++ /dev/null
@@ -1,260 +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.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.Period;
-import org.joda.time.format.DateTimeFormat;
-
-import org.apache.isis.applib.Defaults;
-import org.apache.isis.applib.annotation.Value;
-import org.apache.isis.applib.clock.Clock;
-
-/**
- * Value object representing a time value.
- *
- * <p>
- * TODO: other methods to implement:
- * <ul>
- * <li>comparison methods</li>
- * <li>sameHourAs() hour ==hour sameMinuteAs() minutes = minutes
- * sameTimeAs(hour, min) hour == hour & minutes == minutes</li>
- * <li>withinNextTimePeriod(int hours, int minutes); withinTimePeriod(Date d,
- * int hours, int minutes)</li>
- * <li>withinPreviousTimePeriod(int hours, int minutes); d.hour >= this.hour >=
- * d.hour + hours & d.minutes >= this.minutes >= d.minutes + minutes</li>
- * </ul>
- */
-@Value(semanticsProviderName = "org.apache.isis.core.progmodel.facets.value.time.TimeValueSemanticsProvider")
-public class Time extends Magnitude<Time> {
-
- private static final long serialVersionUID = 1L;
- public static final int MINUTE = 60;
- public static final int HOUR = 60 * MINUTE;
- public static final int DAY = 24 * HOUR;
-
- private final DateTime time;
-
- /**
- * Create a Time object set to the current time.
- */
- public Time() {
- final DateTime dateTime = Clock.getTimeAsDateTime();
- time = dateTime.withDate(1970, 1, 1); // Epoch is 1970-01-01
- }
-
- private DateTime newDateTime(final int hourOfDay, final int minuteOfHour, final int secondsOfMinute) {
- return new DateTime(1970, 1, 1, hourOfDay, minuteOfHour, secondsOfMinute, 0, Defaults.getTimeZone());
- }
-
- /**
- * Create a Time object for storing a time with the time set to the
- * specified hours and minutes.
- */
- public Time(final int hour, final int minute) {
- this(hour, minute, 0);
- }
-
- public Time(final int hour, final int minute, final int second) {
- time = time(hour, minute, second);
- }
-
- private DateTime time(final int hour, final int minute, final int seconds) {
- checkTime(hour, minute, seconds);
- return newDateTime(hour, minute, seconds);
- }
-
- /**
- * Create a Time object for storing a time with the time set to the
- * specified time of the Java Date object.
- */
- public Time(final java.sql.Date date) {
-
- this.time = new DateTime(date.getTime(), Defaults.getTimeZone());
- }
-
- /**
- *
- * @param date
- * must have Date portion equal to Epoch
- * @param calendar
- */
-
- public Time(final java.util.Date date, final DateTimeZone dateTimeZone) {
- final DateTime DateTime = new DateTime(date.getTime(), dateTimeZone);
- this.time = DateTime.secondOfMinute().setCopy(0);
- }
-
- /**
- * Create a Time object for storing a time with the time set to the
- * specified time of the Joda Time DateTime object.
- */
- public Time(final DateTime dateTime) {
- this.time = newDateTime(dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute());
- }
-
- /**
- * Create a new Time object from the millisSinceEpoch, using UTC.
- */
- public Time(final long millisSinceEpoch) {
- this.time = new DateTime(millisSinceEpoch, Defaults.getTimeZone());
- }
-
- /**
- * Add the specified hours and minutes to this time value, returned as a new
- * Time object.
- */
- public Time add(final int hours, final int minutes) {
- final Period period = new Period(hours, minutes, 0, 0);
- return new Time(time.plus(period));
- }
-
- private void checkTime(final int hour, final int minute, final int second) {
- if ((hour < 0) || (hour > 23)) {
- throw new IllegalArgumentException("Hour must be in the range 0 - 23 inclusive");
- }
-
- if ((minute < 0) || (minute > 59)) {
- throw new IllegalArgumentException("Minute must be in the range 0 - 59 inclusive");
- }
-
- if ((second < 0) || (second > 59)) {
- throw new IllegalArgumentException("Second must be in the range 0 - 59 inclusive");
- }
- }
-
- /*
- * public java.util.Date dateValue() { return (date == null) ? null : date;
- * }
- */
-
- public int getHour() {
- return time.getHourOfDay();
- }
-
- public int getMinute() {
- return time.getMinuteOfHour();
- }
-
- public int getSecond() {
- return time.getSecondOfMinute();
- }
-
- /**
- * returns true if the time of this object has the same value as the
- * specified time
- */
- @Override
- public boolean isEqualTo(final Time time) {
- return (time == null) ? false : (this.equals(time));
- }
-
- /**
- * returns true if the time of this object is earlier than the specified
- * time
- */
- @Override
- public boolean isLessThan(final Time time) {
- return (time != null) && this.time.isBefore((time).time);
- }
-
- /**
- * The number of seconds since midnight.
- */
- @Deprecated
- public long longValue() {
- return time.getMillisOfDay() / 1000;
- }
-
- /**
- * The number of seconds since midnight.
- */
- public long secondsSinceMidnight() {
- return milliSecondsSinceMidnight() / 1000;
- }
-
- public long milliSecondsSinceMidnight() {
- return time.getMillisOfDay();
- }
-
- public String titleString() {
- return (time == null) ? "" : DateTimeFormat.shortTime().print(time);
- }
-
- public boolean sameHourAs(final Time time) {
- return getHour() == time.getHour();
- }
-
- public boolean sameMinuteAs(final Time time) {
- return getMinute() == time.getMinute();
- }
-
- public Time onTheHour() {
- return new Time(getHour(), 0);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((time == null) ? 0 : time.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Time other = (Time) obj;
- if (time == null) {
- if (other.time != null) {
- return false;
- }
- } else if (!time.equals(other.time)) {
- return false;
- }
- return true;
- }
-
- public java.util.Date asJavaDate() {
- return time.toDate();
- }
-
- public java.sql.Time asJavaTime() {
- final java.sql.Time time1 = java.sql.Time.valueOf(toString());
- // TODO: confirm that this is in UTC
- return time1;
- }
-
- @Override
- public String toString() {
- return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
- // return String.format("%02d:%02d", getHour(), getMinute());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/TimeStamp.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/TimeStamp.java b/framework/applib/src/main/java/org/apache/isis/applib/value/TimeStamp.java
deleted file mode 100644
index 94c4a6e..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/TimeStamp.java
+++ /dev/null
@@ -1,76 +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;
-import org.apache.isis.applib.clock.Clock;
-
-/**
- * Value object representing a date/time value marking a point in time This is a
- * user facing date/time value, more a marker used to indicate the temporal
- * relationship between two objects.
- *
- * @see DateTime
- */
-@Value(semanticsProviderName = "org.apache.isis.core.progmodel.facets.value.timestamp.TimeStampValueSemanticsProvider")
-public class TimeStamp extends Magnitude<TimeStamp> {
-
- private static final long serialVersionUID = 1L;
- private final long time;
-
- /**
- * Create a TimeStamp object for storing a timeStamp set to the current
- * time.
- */
- public TimeStamp() {
- time = Clock.getTime();
- }
-
- public TimeStamp(final long time) {
- this.time = time;
- }
-
- /**
- * returns true if the time stamp of this object has the same value as the
- * specified timeStamp
- */
- @Override
- public boolean isEqualTo(final TimeStamp timeStamp) {
- return this.time == (timeStamp).time;
- }
-
- /**
- * returns true if the timeStamp of this object is earlier than the
- * specified timeStamp
- */
- @Override
- public boolean isLessThan(final TimeStamp timeStamp) {
- return time < (timeStamp).time;
- }
-
- public long longValue() {
- return time;
- }
-
- @Override
- public String toString() {
- return "Time Stamp " + longValue();
- }
-}
http://git-wip-us.apache.org/repos/asf/isis/blob/dbb64345/framework/applib/src/main/java/org/apache/isis/applib/value/package-info.java
----------------------------------------------------------------------
diff --git a/framework/applib/src/main/java/org/apache/isis/applib/value/package-info.java b/framework/applib/src/main/java/org/apache/isis/applib/value/package-info.java
deleted file mode 100644
index 6848cd3..0000000
--- a/framework/applib/src/main/java/org/apache/isis/applib/value/package-info.java
+++ /dev/null
@@ -1,31 +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.
- */
-
-/**
- * This package defines an additional set of
- * {@link org.apache.isis.applib.annotation.Value} types, supported in addition
- * to the usual JDK ones (of {@link java.lang.String}, {@link java.lang.Integer}, {@link java.math.BigDecimal}, {@link java.util.Date}
- * etc and the primitives).
- *
- * <p>
- * Each of these value types has a corresponding implementation of
- * {@link org.apache.isis.applib.adapters.ValueSemanticsProvider} (implemented
- * within the <tt>core.progmodel</tt> module).
- */
-package org.apache.isis.applib.value;
\ No newline at end of file