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 com.android.sdklib.IAndroidTarget; 20 21 import org.eclipse.swt.graphics.Image; 22 23 /** 24 * Base class for resource qualifiers. 25 * <p/>The resource qualifier classes are designed as immutable. 26 */ 27 public abstract class ResourceQualifier implements Comparable<ResourceQualifier> { 28 29 /** 30 * Returns the human readable name of the qualifier. 31 */ getName()32 public abstract String getName(); 33 34 /** 35 * Returns a shorter human readable name for the qualifier. 36 * @see #getName() 37 */ getShortName()38 public abstract String getShortName(); 39 40 /** 41 * Returns the icon for the qualifier. 42 */ getIcon()43 public abstract Image getIcon(); 44 45 /** 46 * Returns whether the qualifier has a valid filter value. 47 */ isValid()48 public abstract boolean isValid(); 49 50 /** 51 * Check if the value is valid for this qualifier, and if so sets the value 52 * into a Folder Configuration. 53 * @param value The value to check and set. Must not be null. 54 * @param config The folder configuration to receive the value. Must not be null. 55 * @return true if the value was valid and was set. 56 */ checkAndSet(String value, FolderConfiguration config)57 public abstract boolean checkAndSet(String value, FolderConfiguration config); 58 59 /** 60 * Returns a string formated to be used in a folder name. 61 * <p/>This is declared as abstract to force children classes to implement it. 62 */ getFolderSegment(IAndroidTarget target)63 public abstract String getFolderSegment(IAndroidTarget target); 64 65 /** 66 * Returns whether the given qualifier is a match for the receiver. 67 * <p/>The default implementation returns the result of {@link #equals(Object)}. 68 * <p/>Children class that re-implements this must implement 69 * {@link #isBetterMatchThan(ResourceQualifier, ResourceQualifier)} too. 70 * @param qualifier the reference qualifier 71 * @return true if the receiver is a match. 72 */ isMatchFor(ResourceQualifier qualifier)73 public boolean isMatchFor(ResourceQualifier qualifier) { 74 return equals(qualifier); 75 } 76 77 /** 78 * Returns true if the receiver is a better match for the given <var>reference</var> than 79 * the given <var>compareTo</var> comparable. 80 * @param compareTo The {@link ResourceQualifier} to compare to. Can be null, in which 81 * case the method must return <code>true</code>. 82 * @param reference The reference qualifier value for which the match is. 83 * @return true if the receiver is a better match. 84 */ isBetterMatchThan(ResourceQualifier compareTo, ResourceQualifier reference)85 public boolean isBetterMatchThan(ResourceQualifier compareTo, ResourceQualifier reference) { 86 // the default is to always return false. This gives less overhead than always returning 87 // true, as it would only compare same values anyway. 88 return false; 89 } 90 91 @Override toString()92 public String toString() { 93 return getFolderSegment(null); 94 } 95 96 /** 97 * Returns a string formatted for display purpose. 98 */ getStringValue()99 public abstract String getStringValue(); 100 101 /** 102 * Returns <code>true</code> if both objects are equal. 103 * <p/>This is declared as abstract to force children classes to implement it. 104 */ 105 @Override equals(Object object)106 public abstract boolean equals(Object object); 107 108 /** 109 * Returns a hash code value for the object. 110 * <p/>This is declared as abstract to force children classes to implement it. 111 */ 112 @Override hashCode()113 public abstract int hashCode(); 114 compareTo(ResourceQualifier o)115 public final int compareTo(ResourceQualifier o) { 116 return toString().compareTo(o.toString()); 117 } 118 } 119