1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 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.common.resources.configuration; 18 19 import com.android.resources.ResourceEnum; 20 21 /** 22 * Base class for {@link ResourceQualifier} whose value is an {@link ResourceEnum}. 23 * 24 */ 25 abstract class EnumBasedResourceQualifier extends ResourceQualifier { 26 27 abstract ResourceEnum getEnumValue(); 28 29 @Override 30 public boolean isValid() { 31 return getEnumValue() != null; 32 } 33 34 @Override 35 public boolean hasFakeValue() { 36 return getEnumValue().isFakeValue(); 37 } 38 39 @Override 40 public boolean equals(Object qualifier) { 41 if (qualifier instanceof EnumBasedResourceQualifier) { 42 return getEnumValue() == ((EnumBasedResourceQualifier)qualifier).getEnumValue(); 43 } 44 45 return false; 46 } 47 48 @Override 49 public int hashCode() { 50 ResourceEnum value = getEnumValue(); 51 if (value != null) { 52 return value.hashCode(); 53 } 54 55 return 0; 56 } 57 58 /** 59 * Returns the string used to represent this qualifier in the folder name. 60 */ 61 @Override 62 public final String getFolderSegment() { 63 ResourceEnum value = getEnumValue(); 64 if (value != null) { 65 return value.getResourceValue(); 66 } 67 68 return ""; //$NON-NLS-1$ 69 } 70 71 72 @Override 73 public String getShortDisplayValue() { 74 ResourceEnum value = getEnumValue(); 75 if (value != null) { 76 return value.getShortDisplayValue(); 77 } 78 79 return ""; //$NON-NLS-1$ 80 } 81 82 @Override 83 public String getLongDisplayValue() { 84 ResourceEnum value = getEnumValue(); 85 if (value != null) { 86 return value.getLongDisplayValue(); 87 } 88 89 return ""; //$NON-NLS-1$ 90 } 91 92 } 93