public class FilePattern extends Object
A file pattern can be constructed from a pattern string, where
variable parts are represented by blocks delimited by angle
brackets. For instance, the pattern
img_<R,G,B>.ext
expands to
img_R.ext
, img_G.ext
and
img_B.ext
.
In addition to comma-separated series as the one shown above,
pattern blocks can contain a sequence expression in the
START-STOP:STEP
format. For instance, the pattern
<0-36:3>m.tiff
expands to 0m.tiff,
3m.tiff, 6m.tiff ... 36m.tiff
. If the step increment is one,
it can be omitted: TAABA<1-3>.PIC
expands to
TAABA1.PIC, TAABA2.PIC, TAABA3.PIC
. The start number
can have leading zeroes to denote zero-padded numbers:
img_<08-10>.ext
expands to img_08.ext,
img_09.ext, img_10.ext
. Sequence expressions also support
alphabetic ranges: img_<C-E>.ext
expands to
img_C.ext, img_D.ext, img_E.ext
.
A multi-block pattern is expanded by substituting the blocks with
the tuples from the cartesian product of all block expansions. For
instance, z<1-2><R,G,B>.tiff
expands to
z1R.tiff, z1G.tiff, z1B.tiff, z2R.tiff, z2G.tiff,
z2B.tiff
.
If a pattern has zero blocks, it will be treated as a regular
expression to be matched against the names of existing files. If
there are no matches, the pattern expands to itself. For instance,
/tmp/z.*.tif
expands to /tmp/z1.tif
if
that file exists (and it's the only matching file), otherwise it
expands to itself. If the pattern contains no special regex
syntax, it also expands to itself (a single file is a special case
of file pattern).
A FilePattern
can also be created from a Location
or from a basename and directory. In these cases, the
pattern string is inferred from the names of other files in the
same directory.
Modifier and Type | Field and Description |
---|---|
private FilePatternBlock[] |
blocks
List of pattern blocks for this file pattern.
|
private int[] |
endIndex
Indices into the pattern indicating the end of a numerical block.
|
private String[] |
files
File listing for this file pattern.
|
private boolean |
isRegex
Whether or not this FilePattern represents a regular expression.
|
private static org.slf4j.Logger |
LOGGER
Logger for this class.
|
private String |
msg
Error message generated during file pattern construction.
|
private String |
pattern
The file pattern string.
|
private int[] |
startIndex
Indices into the pattern indicating the start of a numerical block.
|
private boolean |
valid
The validity of the file pattern.
|
Constructor and Description |
---|
FilePattern(loci.common.Location file)
Creates a pattern object using the given file as a template.
|
FilePattern(String pattern)
Creates a pattern object for files with the given pattern string.
|
FilePattern(String name,
String dir)
Creates a pattern object using the given
filename and directory path as a template.
|
Modifier and Type | Method and Description |
---|---|
private void |
buildFiles(String prefix,
int ndx,
List<String> fileList) |
static String |
findPattern(File file)
Identifies the group pattern from a given file within that group.
|
static String |
findPattern(loci.common.Location file)
Identifies the group pattern from a given file within that group.
|
static String |
findPattern(String path)
Identifies the group pattern from a given file within that group.
|
static String |
findPattern(String[] names)
Generate a pattern from a list of file names.
|
static String |
findPattern(String name,
String dir)
Identifies the group pattern from a given filename and directory.
|
private static String |
findPattern(String name,
String[] nameList,
int ndx,
int end,
String p) |
static String |
findPattern(String name,
String dir,
String[] nameList)
Identifies the group pattern from a given filename, directory and
list of candidate filenames.
|
static String |
findPattern(String name,
String dir,
String[] nameList,
int[] excludeAxes)
Identifies the group pattern from a given filename, directory and
list of candidate filenames.
|
static String[] |
findSeriesPatterns(String base)
Works like
findSeriesPatterns(String, String, String[]) ,
but dir and nameList are inferred from the given file's absolute
path. |
static String[] |
findSeriesPatterns(String base,
String dir,
String[] nameList)
Similar to
findPattern(String, String, String[]) , but
this does not merge series indices into a pattern block. |
private String[] |
getAllFiles(String dir) |
String |
getBlock(int i)
Gets the specified file pattern block (e.g., <0-9>).
|
String[] |
getBlocks()
Gets all file pattern blocks.
|
private static String |
getBounds(BigInteger[] numbers,
boolean fixed)
Gets a string containing start, end and step values
for a sorted list of numbers.
|
int[] |
getCount()
Gets the number of elements for each pattern block.
|
String[][] |
getElements()
Gets individual elements for each pattern block.
|
String |
getErrorMessage()
Gets the file pattern error message, if any.
|
String[] |
getFiles()
Gets a listing of all files matching this file pattern.
|
BigInteger[] |
getFirst()
Gets the START element for all blocks.
|
BigInteger[] |
getLast()
Gets the STOP element for all blocks.
|
String |
getPattern()
Gets the file pattern string.
|
String |
getPrefix()
Gets the pattern's substring that comes before any block sections.
|
String |
getPrefix(int i)
Gets the pattern's substring between block i-1 (or the beginning
of the pattern, if i is 0) and block i.
|
String[] |
getPrefixes()
Gets all block prefixes.
|
BigInteger[] |
getStep()
Gets the STEP element for all blocks.
|
String |
getSuffix()
Gets the pattern's substring that comes after all block sections.
|
boolean |
isRegex()
Returns whether or not this pattern is a regular expression.
|
boolean |
isValid()
Returns whether or not the file pattern is valid.
|
private static String[] |
matchFiles(String[] inFiles,
NumberFilter filter) |
private static final org.slf4j.Logger LOGGER
private String pattern
private boolean valid
private String msg
private int[] startIndex
private int[] endIndex
private FilePatternBlock[] blocks
private String[] files
private boolean isRegex
public FilePattern(loci.common.Location file)
file
- the file as a Location
instance.public FilePattern(String name, String dir)
name
- file basename.dir
- directory path.public FilePattern(String pattern)
pattern
- the pattern string.public boolean isRegex()
public String getPattern()
public boolean isValid()
public String getErrorMessage()
public String[] getFiles()
public String[][] getElements()
public int[] getCount()
public String getBlock(int i)
i
- block indexpublic String[] getBlocks()
public String getPrefix()
public String getSuffix()
public String getPrefix(int i)
i
- block index.public String[] getPrefixes()
public static String findPattern(String path)
path
- The file path to use as a template for the match.public static String findPattern(loci.common.Location file)
file
- The Location
to use as a template for the match.public static String findPattern(File file)
file
- The file to use as a template for the match.public static String findPattern(String name, String dir)
name
- The file basename to use as a template for the match.dir
- The directory in which to search for matching files.public static String findPattern(String name, String dir, String[] nameList)
name
- The file basename to use as a template for the match.dir
- The directory prefix to use for matching files.nameList
- The names through which to search for matching files.public static String findPattern(String name, String dir, String[] nameList, int[] excludeAxes)
name
- The file basename to use as a template for the match.dir
- The directory prefix to use for matching files.nameList
- The names through which to search for matching files.excludeAxes
- The list of axis types which should be
excluded from the pattern (see AxisGuesser
).public static String findPattern(String[] names)
names
- the list of filenames.public static String[] findSeriesPatterns(String base)
findSeriesPatterns(String, String, String[])
,
but dir and nameList are inferred from the given file's absolute
path.base
- The file basename to use as a template for the match.public static String[] findSeriesPatterns(String base, String dir, String[] nameList)
findPattern(String, String, String[])
, but
this does not merge series indices into a pattern block. Instead,
it returns a separate pattern for each series index. For
instance, if the file names are:
"foo_s1_z1.ext", "foo_s1_z2.ext", "foo_s2_z1.ext", "foo_s2_z2.ext"
Then findPattern
will find a single "foo_s<1-2>_z<1-2>.ext" pattern, whereas this
method will find "foo_s1_z<1-2>.ext" and "foo_s2_z<1-2>.ext".base
- The file basename to use as a template for the match.dir
- The directory prefix to use for matching files.nameList
- The names through which to search for matching files.private static String findPattern(String name, String[] nameList, int ndx, int end, String p)
private static String getBounds(BigInteger[] numbers, boolean fixed)
numbers
- a sorted list of numbersfixed
- whether the numbers to a fixed width blockprivate static String[] matchFiles(String[] inFiles, NumberFilter filter)
public BigInteger[] getFirst()
public BigInteger[] getLast()
public BigInteger[] getStep()
Copyright © 2017 Open Microscopy Environment