1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 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 7 * 8 * http://www.eclipse.org/org/documents/epl-v10.php 9 * 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. 15 */ 16 17 package com.android.ide.eclipse.adt.internal.resources.configurations; 18 19 import org.eclipse.swt.graphics.Image; 20 21 /** 22 * Base class for resource qualifiers. 23 * <p/>The resource qualifier classes are designed as immutable. 24 */ 25 public abstract class ResourceQualifier implements Comparable<ResourceQualifier> { 26 27 /** 28 * Returns the human readable name of the qualifier. 29 */ 30 public abstract String getName(); 31 32 /** 33 * Returns a shorter human readable name for the qualifier. 34 * @see #getName() 35 */ 36 public abstract String getShortName(); 37 38 /** 39 * Returns the icon for the qualifier. 40 */ 41 public abstract Image getIcon(); 42 43 /** 44 * Returns whether the qualifier has a valid filter value. 45 */ 46 public abstract boolean isValid(); 47 48 /** 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. 51 */ 52 public abstract boolean hasFakeValue(); 53 54 /** 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. 60 */ 61 public abstract boolean checkAndSet(String value, FolderConfiguration config); 62 63 /** 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. 66 */ 67 public abstract String getFolderSegment(); 68 69 /** 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. 76 */ 77 public boolean isMatchFor(ResourceQualifier qualifier) { 78 return equals(qualifier); 79 } 80 81 /** 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. 88 */ 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. 92 return false; 93 } 94 95 @Override 96 public String toString() { 97 return getFolderSegment(); 98 } 99 100 /** 101 * Returns a string formatted for display purpose. 102 */ 103 public abstract String getShortDisplayValue(); 104 105 /** 106 * Returns a string formatted for display purpose. 107 */ 108 public abstract String getLongDisplayValue(); 109 110 /** 111 * Returns <code>true</code> if both objects are equal. 112 * <p/>This is declared as abstract to force children classes to implement it. 113 */ 114 @Override 115 public abstract boolean equals(Object object); 116 117 /** 118 * Returns a hash code value for the object. 119 * <p/>This is declared as abstract to force children classes to implement it. 120 */ 121 @Override 122 public abstract int hashCode(); 123 124 public final int compareTo(ResourceQualifier o) { 125 return toString().compareTo(o.toString()); 126 } 127 } 128