FileDocCategorySizeDatePackage
FolderTypeRelationship.javaAPI DocAndroid 1.5 API7120Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources.manager

FolderTypeRelationship

public final class FolderTypeRelationship extends Object
This class gives access to the bi directional relationship between {@link ResourceType} and {@link ResourceFolderType}.

Fields Summary
private static final HashMap
mTypeToFolderMap
private static final HashMap
mFolderToTypeMap
Constructors Summary
Methods Summary
private static voidadd(com.android.ide.eclipse.common.resources.ResourceType type, ResourceFolderType folder, java.util.HashMap typeToFolderMap, java.util.HashMap folderToTypeMap)
Adds a {@link ResourceType} - {@link ResourceFolderType} relationship. this indicates that a file in the folder can generate a resource of the specified type.

param
type The resourceType
param
folder The {@link ResourceFolderType}
param
folderToTypeMap
param
typeToFolderMap

        // first we add the folder to the list associated with the type.
        List<ResourceFolderType> folderList = typeToFolderMap.get(type);
        if (folderList == null) {
            folderList = new ArrayList<ResourceFolderType>();
            typeToFolderMap.put(type, folderList);
        }
        if (folderList.indexOf(folder) == -1) {
            folderList.add(folder);
        }
        
        // now we add the type to the list associated with the folder.
        List<ResourceType> typeList = folderToTypeMap.get(folder);
        if (typeList == null) {
            typeList = new ArrayList<ResourceType>();
            folderToTypeMap.put(folder, typeList);
        }
        if (typeList.indexOf(type) == -1) {
            typeList.add(type);
        }
    
public static ResourceFolderType[]getRelatedFolders(com.android.ide.eclipse.common.resources.ResourceType resType)
Returns a list of {@link ResourceFolderType} that can contain files generating resources of the specified type.

param
resType the type of resource.
return
an array of {@link ResourceFolderType}

        ResourceFolderType[] array = mTypeToFolderMap.get(resType);
        if (array != null) {
            return array;
        }
        return new ResourceFolderType[0];
    
public static com.android.ide.eclipse.common.resources.ResourceType[]getRelatedResourceTypes(ResourceFolderType folderType)
Returns a list of {@link ResourceType}s that can be generated from files inside a folder of the specified type.

param
folderType The folder type.
return
an array of {@link ResourceType}

    
    // generate the relationships.
     
        HashMap<ResourceType, List<ResourceFolderType>> typeToFolderMap =
            new HashMap<ResourceType, List<ResourceFolderType>>();
        
        HashMap<ResourceFolderType, List<ResourceType>> folderToTypeMap =
            new HashMap<ResourceFolderType, List<ResourceType>>();

        add(ResourceType.ANIM, ResourceFolderType.ANIM, typeToFolderMap, folderToTypeMap);
        add(ResourceType.ARRAY, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.COLOR, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.COLOR, ResourceFolderType.COLOR, typeToFolderMap, folderToTypeMap);
        add(ResourceType.DIMEN, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.DRAWABLE, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.DRAWABLE, ResourceFolderType.DRAWABLE, typeToFolderMap, folderToTypeMap);
        add(ResourceType.ID, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.LAYOUT, ResourceFolderType.LAYOUT, typeToFolderMap, folderToTypeMap);
        add(ResourceType.MENU, ResourceFolderType.MENU, typeToFolderMap, folderToTypeMap);
        add(ResourceType.RAW, ResourceFolderType.RAW, typeToFolderMap, folderToTypeMap);
        add(ResourceType.STRING, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.STYLE, ResourceFolderType.VALUES, typeToFolderMap, folderToTypeMap);
        add(ResourceType.XML, ResourceFolderType.XML, typeToFolderMap, folderToTypeMap);
        
        optimize(typeToFolderMap, folderToTypeMap);
    
        ResourceType[] array = mFolderToTypeMap.get(folderType);
        if (array != null) {
            return array;
        }
        return new ResourceType[0];
    
public static booleanmatch(com.android.ide.eclipse.common.resources.ResourceType resType, ResourceFolderType folderType)
Returns true if the {@link ResourceType} and the {@link ResourceFolderType} values match.

param
resType the resource type.
param
folderType the folder type.
return
true if files inside the folder of the specified {@link ResourceFolderType} could generate a resource of the specified {@link ResourceType}

        ResourceFolderType[] array = mTypeToFolderMap.get(resType);
        
        if (array != null && array.length > 0) {
            for (ResourceFolderType fType : array) {
                if (fType == folderType) {
                    return true;
                }
            }
        }
        
        return false;
    
private static voidoptimize(java.util.HashMap typeToFolderMap, java.util.HashMap folderToTypeMap)
Optimize the map to contains array instead of lists (since the api returns arrays)

param
typeToFolderMap
param
folderToTypeMap

        Set<ResourceType> types = typeToFolderMap.keySet();
        for (ResourceType type : types) {
            List<ResourceFolderType> list = typeToFolderMap.get(type);
            mTypeToFolderMap.put(type, list.toArray(new ResourceFolderType[list.size()]));
        }

        Set<ResourceFolderType> folders = folderToTypeMap.keySet();
        for (ResourceFolderType folder : folders) {
            List<ResourceType> list = folderToTypeMap.get(folder);
            mFolderToTypeMap.put(folder, list.toArray(new ResourceType[list.size()]));
        }