com.android.ide.common.res2
Class AbstractResourceRepository

java.lang.Object
  extended by com.android.ide.common.res2.AbstractResourceRepository
Direct Known Subclasses:
ResourceRepository

public abstract class AbstractResourceRepository
extends java.lang.Object


Field Summary
protected static java.lang.Object ITEM_MAP_LOCK
          Lock used to protect map access
 
Constructor Summary
AbstractResourceRepository(boolean isFramework)
           
 
Method Summary
 void clear()
           
 MergeConsumer<ResourceItem> createMergeConsumer()
           
 java.util.List<com.android.resources.ResourceType> getAvailableResourceTypes()
           
 java.util.Map<com.android.resources.ResourceType,java.util.Map<java.lang.String,com.android.ide.common.rendering.api.ResourceValue>> getConfiguredResources(FolderConfiguration referenceConfig)
          Returns the resources values matching a given FolderConfiguration.
 java.util.Map<java.lang.String,com.android.ide.common.rendering.api.ResourceValue> getConfiguredResources(java.util.Map<com.android.resources.ResourceType,com.google.common.collect.ListMultimap<java.lang.String,ResourceItem>> itemMap, com.android.resources.ResourceType type, FolderConfiguration referenceConfig)
           
 java.util.Map<java.lang.String,com.android.ide.common.rendering.api.ResourceValue> getConfiguredResources(com.android.resources.ResourceType type, FolderConfiguration referenceConfig)
          Returns a map of (resource name, resource value) for the given ResourceType.
 com.android.ide.common.rendering.api.ResourceValue getConfiguredValue(com.android.resources.ResourceType type, java.lang.String name, FolderConfiguration referenceConfig)
           
 java.util.Map<com.android.resources.ResourceType,com.google.common.collect.ListMultimap<java.lang.String,ResourceItem>> getItems()
           
 java.util.Collection<java.lang.String> getItemsOfType(com.android.resources.ResourceType type)
           
 java.util.SortedSet<java.lang.String> getLanguages()
          Returns the sorted list of languages used in the resources.
protected abstract  java.util.Map<com.android.resources.ResourceType,com.google.common.collect.ListMultimap<java.lang.String,ResourceItem>> getMap()
           
protected  com.google.common.collect.ListMultimap<java.lang.String,ResourceItem> getMap(com.android.resources.ResourceType type)
           
protected abstract  com.google.common.collect.ListMultimap<java.lang.String,ResourceItem> getMap(com.android.resources.ResourceType type, boolean create)
           
 ResourceFile getMatchingFile(java.lang.String name, com.android.resources.ResourceType type, FolderConfiguration config)
          Returns the ResourceFile matching the given name, ResourceType and configuration.
 java.util.List<ResourceFile> getMatchingFiles(java.lang.String name, com.android.resources.ResourceType type, FolderConfiguration config)
          Returns a list of ResourceFile matching the given name, ResourceType and configuration.
 java.util.SortedSet<java.lang.String> getRegions(java.lang.String currentLanguage)
          Returns the sorted list of regions used in the resources with the given language.
 java.util.List<ResourceItem> getResourceItem(com.android.resources.ResourceType resourceType, java.lang.String resourceName)
           
 boolean hasResourceItem(com.android.resources.ResourceType resourceType, java.lang.String resourceName)
          Returns true if this resource repository contains a resource of the given name.
 boolean hasResourceItem(java.lang.String url)
          Returns true if this resource repository contains a resource of the given name.
 boolean hasResourcesOfType(com.android.resources.ResourceType resourceType)
          Returns whether the repository has resources of a given ResourceType.
 boolean isFramework()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ITEM_MAP_LOCK

protected static final java.lang.Object ITEM_MAP_LOCK
Lock used to protect map access

Constructor Detail

AbstractResourceRepository

public AbstractResourceRepository(boolean isFramework)
Method Detail

isFramework

public boolean isFramework()

createMergeConsumer

@NonNull
public MergeConsumer<ResourceItem> createMergeConsumer()

getMap

@NonNull
protected abstract java.util.Map<com.android.resources.ResourceType,com.google.common.collect.ListMultimap<java.lang.String,ResourceItem>> getMap()

getMap

@Nullable
protected abstract com.google.common.collect.ListMultimap<java.lang.String,ResourceItem> getMap(com.android.resources.ResourceType type,
                                                                                                         boolean create)

getMap

@NonNull
protected com.google.common.collect.ListMultimap<java.lang.String,ResourceItem> getMap(com.android.resources.ResourceType type)

getItems

@NonNull
public java.util.Map<com.android.resources.ResourceType,com.google.common.collect.ListMultimap<java.lang.String,ResourceItem>> getItems()

getResourceItem

@Nullable
public java.util.List<ResourceItem> getResourceItem(@NonNull
                                                             com.android.resources.ResourceType resourceType,
                                                             @NonNull
                                                             java.lang.String resourceName)

getItemsOfType

@NonNull
public java.util.Collection<java.lang.String> getItemsOfType(@NonNull
                                                                     com.android.resources.ResourceType type)

hasResourceItem

public boolean hasResourceItem(@NonNull
                               java.lang.String url)
Returns true if this resource repository contains a resource of the given name.

Parameters:
url - the resource URL
Returns:
true if the resource is known

hasResourceItem

public boolean hasResourceItem(@NonNull
                               com.android.resources.ResourceType resourceType,
                               @NonNull
                               java.lang.String resourceName)
Returns true if this resource repository contains a resource of the given name.

Parameters:
resourceType - the type of resource to look up
resourceName - the name of the resource
Returns:
true if the resource is known

hasResourcesOfType

public boolean hasResourcesOfType(@NonNull
                                  com.android.resources.ResourceType resourceType)
Returns whether the repository has resources of a given ResourceType.

Parameters:
resourceType - the type of resource to check.
Returns:
true if the repository contains resources of the given type, false otherwise.

getAvailableResourceTypes

@NonNull
public java.util.List<com.android.resources.ResourceType> getAvailableResourceTypes()

getMatchingFile

@Nullable
public ResourceFile getMatchingFile(@NonNull
                                             java.lang.String name,
                                             @NonNull
                                             com.android.resources.ResourceType type,
                                             @NonNull
                                             FolderConfiguration config)
Returns the ResourceFile matching the given name, ResourceType and configuration.

This only works with files generating one resource named after the file (for instance, layouts, bitmap based drawable, xml, anims).

Parameters:
name - the resource name
type - the folder type search for
config - the folder configuration to match for
Returns:
the matching file or null if no match was found.

getMatchingFiles

@NonNull
public java.util.List<ResourceFile> getMatchingFiles(@NonNull
                                                             java.lang.String name,
                                                             @NonNull
                                                             com.android.resources.ResourceType type,
                                                             @NonNull
                                                             FolderConfiguration config)
Returns a list of ResourceFile matching the given name, ResourceType and configuration. This ignores the qualifiers which are missing from the configuration.

This only works with files generating one resource named after the file (for instance, layouts, bitmap based drawable, xml, anims).

Parameters:
name - the resource name
type - the folder type search for
config - the folder configuration to match for
See Also:
getMatchingFile(String, ResourceType, FolderConfiguration)

getConfiguredResources

@NonNull
public java.util.Map<com.android.resources.ResourceType,java.util.Map<java.lang.String,com.android.ide.common.rendering.api.ResourceValue>> getConfiguredResources(@NonNull
                                                                                                                                                                           FolderConfiguration referenceConfig)
Returns the resources values matching a given FolderConfiguration.

Parameters:
referenceConfig - the configuration that each value must match.
Returns:
a map with guaranteed to contain an entry for each ResourceType

getConfiguredResources

@NonNull
public java.util.Map<java.lang.String,com.android.ide.common.rendering.api.ResourceValue> getConfiguredResources(@NonNull
                                                                                                                         com.android.resources.ResourceType type,
                                                                                                                         @NonNull
                                                                                                                         FolderConfiguration referenceConfig)
Returns a map of (resource name, resource value) for the given ResourceType.

The values returned are taken from the resource files best matching a given FolderConfiguration.

Parameters:
type - the type of the resources.
referenceConfig - the configuration to best match.

getConfiguredResources

@NonNull
public java.util.Map<java.lang.String,com.android.ide.common.rendering.api.ResourceValue> getConfiguredResources(@NonNull
                                                                                                                         java.util.Map<com.android.resources.ResourceType,com.google.common.collect.ListMultimap<java.lang.String,ResourceItem>> itemMap,
                                                                                                                         @NonNull
                                                                                                                         com.android.resources.ResourceType type,
                                                                                                                         @NonNull
                                                                                                                         FolderConfiguration referenceConfig)

getConfiguredValue

@Nullable
public com.android.ide.common.rendering.api.ResourceValue getConfiguredValue(@NonNull
                                                                                      com.android.resources.ResourceType type,
                                                                                      @NonNull
                                                                                      java.lang.String name,
                                                                                      @NonNull
                                                                                      FolderConfiguration referenceConfig)

getLanguages

@NonNull
public java.util.SortedSet<java.lang.String> getLanguages()
Returns the sorted list of languages used in the resources.


getRegions

@NonNull
public java.util.SortedSet<java.lang.String> getRegions(@NonNull
                                                                java.lang.String currentLanguage)
Returns the sorted list of regions used in the resources with the given language.

Parameters:
currentLanguage - the current language the region must be associated with.

clear

public void clear()