Compare commits

...

5 Commits

Author SHA1 Message Date
Damien Goutte-Gattat ce283aba22 [maven-release-plugin] prepare for next development iteration 2 months ago
Damien Goutte-Gattat 6c35f22a01 [maven-release-plugin] prepare release incenp-imagej-plugins-0.9.6 2 months ago
Damien Goutte-Gattat b35fd4d14b Match header names in a case-insensitive manner by default. 2 months ago
Damien Goutte-Gattat 90f35b8bac Allow several names when looking for a specific cell. 2 months ago
Damien Goutte-Gattat 8a7339a2e8 [maven-release-plugin] prepare for next development iteration 2 months ago
  1. 4
      pom.xml
  2. 64
      src/main/java/org/incenp/imagej/BatchReader.java

4
pom.xml

@ -3,7 +3,7 @@
<groupId>org.incenp</groupId>
<artifactId>incenp-imagej-plugins</artifactId>
<version>0.9.5</version>
<version>0.9.7-SNAPSHOT</version>
<name>Incenp.org ImageJ Plugins</name>
<description>Some plugins for ImageJ</description>
<url>https://incenp.org/dvlpt/imagej-plugins/</url>
@ -29,7 +29,7 @@
<connection>scm:git:https://git.incenp.org/damien/imagej-plugins.git</connection>
<developerConnection>scm:git:ssh://git@git.incenp.org/damien/imagej-plugins.git</developerConnection>
<url>https://git.incenp.org/damien/imagej-plugins</url>
<tag>incenp-imagej-plugins-0.9.5</tag>
<tag>HEAD</tag>
</scm>
<issueManagement>

64
src/main/java/org/incenp/imagej/BatchReader.java

@ -64,6 +64,7 @@ public class BatchReader {
private String filename;
private String[] headers;
private boolean withHeaders;
private boolean caseSensitiveHeaders;
private ArrayList<String[]> rows;
private ImagePlus[] currentImages;
private Hashtable<String, Integer> headersIndex;
@ -78,6 +79,7 @@ public class BatchReader {
public BatchReader(String filename, boolean noHeaders) {
this.filename = filename;
this.withHeaders = !noHeaders;
caseSensitiveHeaders = false;
headers = null;
headersIndex = null;
cursor = subcursor = -1;
@ -114,6 +116,19 @@ public class BatchReader {
this(file.getAbsolutePath(), noHeaders);
}
/**
* Sets the case-sensitivity option. If set to true, the
* {@link #getCell(String)} method and its overloaded variants will match header
* names in a case-sensitive way. The default is false.
*
* @param caseSensitive true to match header names case-sensitively.
*/
public void setCaseSensitive(boolean caseSensitive) {
caseSensitiveHeaders = caseSensitive;
if ( headersIndex != null )
headersIndex = null;
}
/**
* Moves to the next available image. Once this method has been called and if it
* returned true, the image can be obtained by calling the {@link #getImage()}
@ -214,29 +229,62 @@ public class BatchReader {
}
/**
* Gets the contents of a specific cell within the current row.
* Gets the contents of a specific cell within the current row. The cell is
* searched for using several equally accepted names.
*
* @param name the column name, as indicated in the header row
* @param names an array of accepted column names
* @param fallback the default value to return if the cell is not found
* @return the contents of the specified cell
*/
public String getCell(String name) {
public String getCell(String[] names, String fallback) {
if ( headersIndex == null ) {
if ( (headersIndex = getHeadersIndex()) == null )
return null;
}
Integer indexObject = headersIndex.get(name);
if ( indexObject == null )
return "";
Integer index = null;
for ( int i = 0; i < names.length && index == null; i++ ) {
if ( !caseSensitiveHeaders )
index = headersIndex.get(names[i].toLowerCase());
else
index = headersIndex.get(names[i]);
}
if ( index == null )
return fallback;
return getCell(index.intValue());
}
/**
* Gets the contents of a specific cell within the current row. The cell is
* searched for using several equally accepted names.
*
* @param names an array of accepted column names
* @return the contents of the specified cell
*/
public String getCell(String[] names) {
return getCell(names, "");
}
return getCell(indexObject.intValue());
/**
* Gets the contents of a specific cell within the current row.
*
* @param name the column name, as indicated in the header row
* @return the contents of the specified cell
*/
public String getCell(String name) {
return getCell(new String[] { name }, "");
}
private Hashtable<String, Integer> getHeadersIndex() {
if ( headersIndex == null && headers != null ) {
headersIndex = new Hashtable<String, Integer>();
for ( int i = 0; i < headers.length; i++ ) {
headersIndex.put(headers[i], i);
if ( !caseSensitiveHeaders )
headersIndex.put(headers[i].toLowerCase(), i);
else
headersIndex.put(headers[i], i);
}
}

Loading…
Cancel
Save