001: /*
002: * (c) Copyright 2007 by Volker Bergmann. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, is permitted under the terms of the
006: * GNU General Public License.
007: *
008: * For redistributing this software or a derivative work under a license other
009: * than the GPL-compatible Free Software License as defined by the Free
010: * Software Foundation or approved by OSI, you must first obtain a commercial
011: * license to this software product from Volker Bergmann.
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014: * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015: * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017: * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGE.
025: */
026:
027: package org.databene.model.data;
028:
029: import org.databene.commons.Operation;
030: import org.databene.commons.operation.FirstArgSelector;
031:
032: /**
033: * A FeatureDescriptor is composed og FeatureDetails, which have name, value, type and default value.<br/>
034: * <br/>
035: * Created: 03.08.2007 06:57:42
036: * @author Volker Bergmann
037: */
038: public class FeatureDetail<E> {
039:
040: // properties ------------------------------------------------------------------------------------------------------
041:
042: private String name;
043: private Class<E> type;
044: private E value;
045: private E defaultValue;
046: private Operation<E, E> combinator;
047: private boolean constraint;
048:
049: // constructors ----------------------------------------------------------------------------------------------------
050:
051: public FeatureDetail(String name, Class<E> type,
052: boolean constraint, E defaultValue) {
053: this (name, type, constraint, defaultValue,
054: new FirstArgSelector<E>());
055: }
056:
057: public FeatureDetail(String name, Class<E> type,
058: boolean constraint, E defaultValue,
059: Operation<E, E> combinator) {
060: this (name, type, constraint, defaultValue, null, combinator);
061: }
062:
063: public FeatureDetail(String name, Class<E> type,
064: boolean constraint, E defaultValue, E value,
065: Operation<E, E> combinator) {
066: this .name = name;
067: this .type = type;
068: this .defaultValue = defaultValue;
069: this .value = value;
070: this .constraint = constraint;
071: this .combinator = combinator;
072: }
073:
074: // interface -------------------------------------------------------------------------------------------------------
075:
076: public String getName() {
077: return name;
078: }
079:
080: public Class<E> getType() {
081: return type;
082: }
083:
084: public E getValue() {
085: return value;
086: }
087:
088: public void setValue(E value) {
089: this .value = value;
090: }
091:
092: public Object getDefault() {
093: return defaultValue;
094: }
095:
096: public E combineWith(E otherValue) {
097: return combinator.perform(this .value, otherValue);
098: }
099:
100: public boolean isConstraint() {
101: return constraint;
102: }
103:
104: public String getDescription() {
105: return name + '=' + value + " (" + type + ')';
106: }
107:
108: // java.lang.Object overrides --------------------------------------------------------------------------------------
109:
110: public String toString() {
111: return name + '=' + value;
112: }
113:
114: public boolean equals(Object o) {
115: if (this == o)
116: return true;
117: if (o == null || getClass() != o.getClass())
118: return false;
119: final FeatureDetail that = (FeatureDetail) o;
120: if (!name.equals(that.name))
121: return false;
122: return !(value != null ? !value.equals(that.value)
123: : that.value != null);
124: }
125:
126: public int hashCode() {
127: int result;
128: result = name.hashCode();
129: result = 29 * result + (value != null ? value.hashCode() : 0);
130: return result;
131: }
132:
133: }
|