public abstract class DataSet<I extends com.android.ide.common.resources.DataItem<F>,F extends DataFile<I>> extends java.lang.Object implements SourceSet
DataItems.
The items can be coming from multiple source folders, and duplicates are detected.
Each source folders is considered to be at the same level. To use overlays, a DataMerger must be used.
Creating the set and adding folders does not load the data. The data can be loaded from the files, or from a blob which is generated by the set itself.
Upon loading the data from the blob, the data can be updated with fresher files. Each item that is updated is flagged as such, in order to manage incremental update.
Writing/Loading the blob is not done through this class directly, but instead through the
DataMerger which contains DataSet objects.
| Modifier | Constructor and Description |
|---|---|
protected |
DataSet(java.lang.String configName,
boolean validateEnabled)
Creates a DataSet with a given configName.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addItem(I item,
java.lang.String key) |
void |
addSource(java.io.File file)
Adds a new source file
|
void |
addSources(java.util.Collection<java.io.File> files)
Adds a collection of source files.
|
protected boolean |
checkFileForAndroidRes(java.io.File file)
Checks a file to make sure it is a valid file in the android res/asset folders.
|
protected void |
checkItems()
Checks for duplicate items across all source files.
|
protected abstract F |
createFileAndItems(java.io.File sourceFolder,
java.io.File file,
com.android.utils.ILogger logger) |
protected abstract F |
createFileAndItemsFromXml(java.io.File file,
org.w3c.dom.Node fileNode)
Creates a DataFile and associated DataItems from an XML node from a file created with
appendToXml(Node, Document, MergeConsumer, boolean) |
protected abstract DataSet<I,F> |
createSet(java.lang.String name) |
boolean |
equals(java.lang.Object o) |
java.io.File |
findMatchingSourceFile(java.io.File file)
Returns the longest path matching Source file that contains a given file.
|
java.lang.String |
getConfigName()
Returns the config name.
|
protected F |
getDataFile(java.io.File file) |
com.google.common.collect.ListMultimap<java.lang.String,I> |
getDataMap()
Returns a map of the items.
|
java.util.List<java.io.File> |
getSourceFiles()
Returns the list of source files.
|
protected boolean |
getValidateEnabled() |
protected boolean |
handleChangedFile(java.io.File sourceFolder,
java.io.File changedFile,
com.android.utils.ILogger logger) |
protected F |
handleNewFile(java.io.File sourceFolder,
java.io.File file,
com.android.utils.ILogger logger) |
protected boolean |
handleRemovedFile(java.io.File removedFile) |
int |
hashCode() |
boolean |
isEmpty()
Returns whether the set is empty of items.
|
boolean |
isIgnored(java.io.File file)
Returns whether the given file should be ignored.
|
protected boolean |
isValidSourceFile(java.io.File sourceFolder,
java.io.File file) |
F |
loadFile(java.io.File sourceFolder,
java.io.File dataFile,
com.android.utils.ILogger logger)
Loads a single dataFile from the given source folder (rather than load / parse from all
source folders).
|
void |
loadFromFiles(com.android.utils.ILogger logger)
Loads the DataSet from the files its source folders contain.
|
protected void |
processNewDataFile(java.io.File sourceFolder,
F dataFile,
boolean setTouched) |
protected abstract void |
readSourceFolder(java.io.File sourceFolder,
com.android.utils.ILogger logger)
Reads the content of a data folders and loads the DataItem.
|
void |
setFolderFilter(java.util.function.Function<java.io.File,java.lang.Boolean> folderFilter) |
void |
setIgnoredPatterns(java.lang.String aaptStylePattern) |
int |
size()
Returns the number of items.
|
java.lang.String |
toString() |
boolean |
updateWith(java.io.File sourceFolder,
java.io.File changedFile,
FileStatus fileStatus,
com.android.utils.ILogger logger)
Update the DataSet with a given file.
|
protected DataSet(@NonNull
java.lang.String configName,
boolean validateEnabled)
configName - the name of the config this set is associated withprotected abstract F createFileAndItemsFromXml(@NonNull java.io.File file, @NonNull org.w3c.dom.Node fileNode) throws MergingException
appendToXml(Node, Document, MergeConsumer, boolean)file - the file represented by the DataFilefileNode - the XML node.MergingExceptionprotected abstract void readSourceFolder(java.io.File sourceFolder,
com.android.utils.ILogger logger)
throws MergingException
processNewDataFile(java.io.File, DataFile, boolean).sourceFolder - the source folder to load the resources from.MergingException - if something goes wrong@Nullable protected abstract F createFileAndItems(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger) throws MergingException
MergingExceptionpublic void addSources(java.util.Collection<java.io.File> files)
files - the source files to add.public void addSource(java.io.File file)
file - the source file.@NonNull public java.util.List<java.io.File> getSourceFiles()
getSourceFiles in interface SourceSetpublic java.lang.String getConfigName()
public java.io.File findMatchingSourceFile(java.io.File file)
findMatchingSourceFile in interface SourceSetfile - the file to search forpublic int size()
DataMappublic boolean isEmpty()
@NonNull public com.google.common.collect.ListMultimap<java.lang.String,I> getDataMap()
DataMappublic void loadFromFiles(com.android.utils.ILogger logger)
throws MergingException
MergingException - if something goes wrong@Nullable public F loadFile(@NonNull java.io.File sourceFolder, @NonNull java.io.File dataFile, @NonNull com.android.utils.ILogger logger) throws MergingException
Like loadFromFiles, all loaded items are set to TOUCHED.
sourceFolder - the source folderdataFile - the data file within source folderlogger - logs errorsMergingExceptionprotected void checkItems()
throws DuplicateDataException
DuplicateDataException - if a duplicated item is found.public boolean updateWith(java.io.File sourceFolder,
java.io.File changedFile,
FileStatus fileStatus,
com.android.utils.ILogger logger)
throws MergingException
sourceFolder - the sourceFile containing the changedFilechangedFile - The changed filefileStatus - the change stateMergingException - if something goes wrongprotected boolean handleRemovedFile(java.io.File removedFile)
protected boolean isValidSourceFile(@NonNull
java.io.File sourceFolder,
@NonNull
java.io.File file)
@Nullable protected F handleNewFile(java.io.File sourceFolder, java.io.File file, com.android.utils.ILogger logger) throws MergingException
MergingExceptionprotected void processNewDataFile(@NonNull
java.io.File sourceFolder,
@NonNull
F dataFile,
boolean setTouched)
throws MergingException
MergingExceptionprotected boolean handleChangedFile(@NonNull
java.io.File sourceFolder,
@NonNull
java.io.File changedFile,
@NonNull
com.android.utils.ILogger logger)
throws MergingException
MergingExceptionprotected void addItem(@NonNull
I item,
@Nullable
java.lang.String key)
throws MergingException
MergingExceptionprotected F getDataFile(@NonNull java.io.File file)
public java.lang.String toString()
toString in class java.lang.Objectprotected boolean checkFileForAndroidRes(@NonNull
java.io.File file)
file - the file to checkpublic void setIgnoredPatterns(java.lang.String aaptStylePattern)
public void setFolderFilter(@NonNull
java.util.function.Function<java.io.File,java.lang.Boolean> folderFilter)
public boolean isIgnored(@NonNull
java.io.File file)
file - the file to checkprotected boolean getValidateEnabled()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object