01: /*
02: * Copyright 2006 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.cfg;
17:
18: import java.util.Arrays;
19: import java.util.HashSet;
20: import java.util.Set;
21:
22: /**
23: * Represents a single named deferred binding property that can answer with its
24: * value.
25: */
26: public class Property implements Comparable {
27:
28: private String activeValue;
29:
30: private Set knownValues = new HashSet();
31:
32: private String[] knownValuesLazyArray;
33:
34: private final String name;
35:
36: private PropertyProvider provider;
37:
38: public Property(String name) {
39: this .name = name;
40: }
41:
42: public void addKnownValue(String knownValue) {
43: knownValues.add(knownValue);
44: knownValuesLazyArray = null;
45: }
46:
47: public int compareTo(Object other) {
48: return name.compareTo(((Property) other).name);
49: }
50:
51: /**
52: * Gets the property value or <code>null</code> if the property has no
53: * value.
54: */
55: public String getActiveValue() {
56: return activeValue;
57: }
58:
59: /**
60: * Lists all the known values for this property in sorted order.
61: */
62: public String[] getKnownValues() {
63: if (knownValuesLazyArray == null) {
64: int n = knownValues.size();
65: knownValuesLazyArray = (String[]) knownValues
66: .toArray(new String[n]);
67: Arrays.sort(knownValuesLazyArray);
68: }
69: return knownValuesLazyArray;
70: }
71:
72: public String getName() {
73: return name;
74: }
75:
76: public PropertyProvider getProvider() {
77: return provider;
78: }
79:
80: public boolean isKnownValue(String value) {
81: return knownValues.contains(value);
82: }
83:
84: /**
85: * Sets the property value, or clears it by specifying <code>null</code>.
86: */
87: public void setActiveValue(String value) {
88: this .activeValue = value;
89: }
90:
91: public void setProvider(PropertyProvider provider) {
92: this .provider = provider;
93: }
94:
95: public String toString() {
96: return name;
97: }
98: }
|