001: /*
002: * Copyright 2005-2007 Noelios Consulting.
003: *
004: * The contents of this file are subject to the terms of the Common Development
005: * and Distribution License (the "License"). You may not use this file except in
006: * compliance with the License.
007: *
008: * You can obtain a copy of the license at
009: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
010: * language governing permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL HEADER in each file and
013: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
014: * applicable, add the following below this CDDL HEADER, with the fields
015: * enclosed by brackets "[]" replaced with your own identifying information:
016: * Portions Copyright [yyyy] [name of copyright owner]
017: */
018:
019: package org.restlet.data;
020:
021: import org.restlet.util.Series;
022:
023: /**
024: * Metadata preference definition.
025: *
026: * @author Jerome Louvel (contact@noelios.com)
027: */
028: public final class Preference<T extends Metadata> {
029: /** The metadata associated with this preference. */
030: private T metadata;
031:
032: /** The quality/preference level. */
033: private float quality;
034:
035: /** The modifiable list of parameters. */
036: private Series<Parameter> parameters;
037:
038: /**
039: * Constructor.
040: */
041: public Preference() {
042: this (null, 1F, null);
043: }
044:
045: /**
046: * Constructor.
047: *
048: * @param metadata
049: * The associated metadata.
050: */
051: public Preference(T metadata) {
052: this (metadata, 1F, null);
053: }
054:
055: /**
056: * Constructor.
057: *
058: * @param metadata
059: * The associated metadata.
060: * @param quality
061: * The quality/preference level.
062: */
063: public Preference(T metadata, float quality) {
064: this (metadata, quality, null);
065: }
066:
067: /**
068: * Constructor.
069: *
070: * @param metadata
071: * The associated metadata.
072: * @param quality
073: * The quality/preference level.
074: * @param parameters
075: * The list of parameters.
076: */
077: public Preference(T metadata, float quality,
078: Series<Parameter> parameters) {
079: this .metadata = metadata;
080: this .quality = quality;
081: this .parameters = parameters;
082: }
083:
084: /**
085: * Returns the metadata associated with this preference.
086: *
087: * @return The metadata associated with this preference.
088: */
089: public T getMetadata() {
090: return metadata;
091: }
092:
093: /**
094: * Returns the modifiable list of parameters.
095: *
096: * @return The modifiable list of parameters.
097: */
098: public Series<Parameter> getParameters() {
099: if (this .parameters == null)
100: this .parameters = new Form();
101: return this .parameters;
102: }
103:
104: /**
105: * Returns the quality/preference level.
106: *
107: * @return The quality/preference level.
108: */
109: public float getQuality() {
110: return quality;
111: }
112:
113: /**
114: * Sets the metadata associated with this preference.
115: *
116: * @param metadata
117: * The metadata associated with this preference.
118: */
119: public void setMetadata(T metadata) {
120: this .metadata = metadata;
121: }
122:
123: /**
124: * Sets the quality/preference level.
125: *
126: * @param quality
127: * The quality/preference level.
128: */
129: public void setQuality(float quality) {
130: this .quality = quality;
131: }
132:
133: @Override
134: public String toString() {
135: return (getMetadata() == null) ? "" : (getMetadata().getName()
136: + ":" + getQuality());
137: }
138: }
|