2 * Copyright (C) 2007 The Android Open Source Project
4 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.eclipse.org/org/documents/epl-v10.php
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.ide.eclipse.adt.internal.resources.configurations;
19 import org.eclipse.swt.graphics.Image;
22 * Base class for resource qualifiers.
23 * <p/>The resource qualifier classes are designed as immutable.
25 public abstract class ResourceQualifier implements Comparable<ResourceQualifier> {
28 * Returns the human readable name of the qualifier.
30 public abstract String getName();
33 * Returns a shorter human readable name for the qualifier.
36 public abstract String getShortName();
39 * Returns the icon for the qualifier.
41 public abstract Image getIcon();
44 * Returns whether the qualifier has a valid filter value.
46 public abstract boolean isValid();
49 * Returns whether the qualifier has a fake value.
50 * <p/>Fake values are used internally and should not be used as real qualifier value.
52 public abstract boolean hasFakeValue();
55 * Check if the value is valid for this qualifier, and if so sets the value
56 * into a Folder Configuration.
57 * @param value The value to check and set. Must not be null.
58 * @param config The folder configuration to receive the value. Must not be null.
59 * @return true if the value was valid and was set.
61 public abstract boolean checkAndSet(String value, FolderConfiguration config);
64 * Returns a string formated to be used in a folder name.
65 * <p/>This is declared as abstract to force children classes to implement it.
67 public abstract String getFolderSegment();
70 * Returns whether the given qualifier is a match for the receiver.
71 * <p/>The default implementation returns the result of {@link #equals(Object)}.
72 * <p/>Children class that re-implements this must implement
73 * {@link #isBetterMatchThan(ResourceQualifier, ResourceQualifier)} too.
74 * @param qualifier the reference qualifier
75 * @return true if the receiver is a match.
77 public boolean isMatchFor(ResourceQualifier qualifier) {
78 return equals(qualifier);
82 * Returns true if the receiver is a better match for the given <var>reference</var> than
83 * the given <var>compareTo</var> comparable.
84 * @param compareTo The {@link ResourceQualifier} to compare to. Can be null, in which
85 * case the method must return <code>true</code>.
86 * @param reference The reference qualifier value for which the match is.
87 * @return true if the receiver is a better match.
89 public boolean isBetterMatchThan(ResourceQualifier compareTo, ResourceQualifier reference) {
90 // the default is to always return false. This gives less overhead than always returning
91 // true, as it would only compare same values anyway.
96 public String toString() {
97 return getFolderSegment();
101 * Returns a string formatted for display purpose.
103 public abstract String getShortDisplayValue();
106 * Returns a string formatted for display purpose.
108 public abstract String getLongDisplayValue();
111 * Returns <code>true</code> if both objects are equal.
112 * <p/>This is declared as abstract to force children classes to implement it.
115 public abstract boolean equals(Object object);
118 * Returns a hash code value for the object.
119 * <p/>This is declared as abstract to force children classes to implement it.
122 public abstract int hashCode();
124 public final int compareTo(ResourceQualifier o) {
125 return toString().compareTo(o.toString());