mirror of
https://github.com/paulscherrerinstitute/ch.psi.imagej.hdf5.git
synced 2025-04-20 05:00:03 +02:00
Removed compiler warnings
This commit is contained in:
parent
b381b87ff9
commit
c0dd33436e
17
pom.xml
17
pom.xml
@ -13,4 +13,21 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<finalName>HDF5_Viewer-${pom.version}</finalName>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<archive />
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,51 +0,0 @@
|
||||
package ch.psi.imagej.hdf5;
|
||||
/* =========================================================================
|
||||
*
|
||||
* Copyright 2011 Matthias Schlachter
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*=========================================================================*/
|
||||
|
||||
public class HDF5_Batch_
|
||||
{
|
||||
public static void run(String arg)
|
||||
{
|
||||
parseArgs(arg);
|
||||
System.out.println("filename");
|
||||
System.out.println(_filename);
|
||||
System.out.println("varnames");
|
||||
for(int i=0; i<_varnames.length; i++)
|
||||
System.out.println(_varnames[i]);
|
||||
HDF5_Writer_ w = new HDF5_Writer_();
|
||||
w.setToBatchMode(_filename,_varnames);
|
||||
w.run(null);
|
||||
}
|
||||
|
||||
|
||||
private static void parseArgs(String arg)
|
||||
{
|
||||
String[] result = arg.split("]\\s");
|
||||
_filename = result[0].replaceAll("file=\\[","");
|
||||
String[] splitVars = result[1].split("\\s");
|
||||
_varnames = new String[splitVars.length];
|
||||
for (int x=0; x<splitVars.length; x++)
|
||||
_varnames[x] = splitVars[x];
|
||||
|
||||
}
|
||||
|
||||
static private String _filename = null;
|
||||
static private String[] _varnames = null;
|
||||
|
||||
// end of class
|
||||
}
|
@ -1,22 +1,4 @@
|
||||
package ch.psi.imagej.hdf5;
|
||||
/* =========================================================================
|
||||
*
|
||||
* Copyright 2011 Matthias Schlachter
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*=========================================================================*/
|
||||
|
||||
|
||||
import ij.Prefs;
|
||||
import ij.gui.GenericDialog;
|
||||
@ -24,210 +6,143 @@ import ij.plugin.PlugIn;
|
||||
import java.util.regex.*;
|
||||
import java.lang.String;
|
||||
|
||||
public class HDF5_Config implements PlugIn {
|
||||
|
||||
public class HDF5_Config implements PlugIn
|
||||
{
|
||||
public void run(String arg)
|
||||
{
|
||||
// set default values
|
||||
setDefaultsIfNoValueExists();
|
||||
// read ImageJ Preferences
|
||||
boolean groupVarsByName =
|
||||
Boolean.getBoolean(getDefaultValue("HDF5.groupVarsByName"));
|
||||
groupVarsByName = Prefs.get("HDF5.groupVarsByName", groupVarsByName);
|
||||
public void run(String arg) {
|
||||
// set default values
|
||||
setDefaultsIfNoValueExists();
|
||||
// read ImageJ Preferences
|
||||
boolean groupVarsByName = Boolean.getBoolean(getDefaultValue("HDF5.groupVarsByName"));
|
||||
groupVarsByName = Prefs.get("HDF5.groupVarsByName", groupVarsByName);
|
||||
|
||||
boolean showUnmatchedDataSetNames =
|
||||
Boolean.getBoolean(getDefaultValue("HDF5.showUnmatchedDataSetNames"));
|
||||
showUnmatchedDataSetNames = Prefs.get("HDF5.showUnmatchedDataSetNames",
|
||||
showUnmatchedDataSetNames);
|
||||
|
||||
String groupVarsByNameFormatGroup =
|
||||
getDefaultValue("HDF5.groupVarsByNameFormatGroup");
|
||||
groupVarsByNameFormatGroup
|
||||
= Prefs.get("HDF5.groupVarsByNameFormatGroup",
|
||||
groupVarsByNameFormatGroup);
|
||||
|
||||
String groupVarsByNameFormat =
|
||||
getDefaultValue("HDF5.groupVarsByNameFormat");
|
||||
groupVarsByNameFormat = Prefs.get("HDF5.groupVarsByNameFormat",
|
||||
groupVarsByNameFormat);
|
||||
boolean showUnmatchedDataSetNames = Boolean.getBoolean(getDefaultValue("HDF5.showUnmatchedDataSetNames"));
|
||||
showUnmatchedDataSetNames = Prefs.get("HDF5.showUnmatchedDataSetNames", showUnmatchedDataSetNames);
|
||||
|
||||
String dollarRegexpForGrouping =
|
||||
getDefaultValue("HDF5.dollarRegexpForGrouping");
|
||||
dollarRegexpForGrouping = Prefs.get("HDF5.dollarRegexpForGrouping",
|
||||
dollarRegexpForGrouping);
|
||||
|
||||
GenericDialog configDiag =
|
||||
new GenericDialog("HDF5 Preferences");
|
||||
configDiag.addMessage("Reader:");
|
||||
configDiag.addCheckbox("Group data set names instead of showing a list " +
|
||||
"of data set names.",
|
||||
groupVarsByName);
|
||||
configDiag.addCheckbox("Show unmatched data set names in a separate list",
|
||||
showUnmatchedDataSetNames);
|
||||
configDiag.addStringField("HDF5 group containing pattern " +
|
||||
"for data set grouping: ",
|
||||
groupVarsByNameFormatGroup,15);
|
||||
configDiag.addStringField("Pattern for grouping (if no attributes" +
|
||||
" are found): ",
|
||||
groupVarsByNameFormat,15);
|
||||
// configDiag.addStringField("$ regexp (ignored because only numbers" +
|
||||
// " work right now): ",
|
||||
// dollarRegexpForGrouping,15);
|
||||
configDiag.addMessage("Writer:");
|
||||
String groupVarsByNameFormatGroup = getDefaultValue("HDF5.groupVarsByNameFormatGroup");
|
||||
groupVarsByNameFormatGroup = Prefs.get("HDF5.groupVarsByNameFormatGroup", groupVarsByNameFormatGroup);
|
||||
|
||||
String yesLabel = "Save";
|
||||
String noLabel = "Reset";
|
||||
configDiag.enableYesNoCancel(yesLabel,noLabel);
|
||||
configDiag.showDialog();
|
||||
|
||||
if(configDiag.wasCanceled())
|
||||
{
|
||||
// do nothing
|
||||
return;
|
||||
}
|
||||
if(!configDiag.wasOKed())
|
||||
{
|
||||
// reset button was pressed
|
||||
System.out.println("reset button was pressed");
|
||||
// reset all and return a new dialog
|
||||
configDiag.setVisible(false);
|
||||
this.run(arg);
|
||||
return;
|
||||
}
|
||||
// get parameters check if they are correct
|
||||
|
||||
groupVarsByName = configDiag.getNextBoolean();
|
||||
System.out.println("groupVarsByName: " +
|
||||
Boolean.toString(groupVarsByName));
|
||||
String groupVarsByNameFormat = getDefaultValue("HDF5.groupVarsByNameFormat");
|
||||
groupVarsByNameFormat = Prefs.get("HDF5.groupVarsByNameFormat", groupVarsByNameFormat);
|
||||
|
||||
showUnmatchedDataSetNames = configDiag.getNextBoolean();
|
||||
System.out.println("showUnmatchedDataSetNames: " +
|
||||
Boolean.toString(showUnmatchedDataSetNames));
|
||||
String dollarRegexpForGrouping = getDefaultValue("HDF5.dollarRegexpForGrouping");
|
||||
dollarRegexpForGrouping = Prefs.get("HDF5.dollarRegexpForGrouping", dollarRegexpForGrouping);
|
||||
|
||||
groupVarsByNameFormatGroup = configDiag.getNextString();
|
||||
System.out.println("groupVarsByNameFormatGroup: " +
|
||||
groupVarsByNameFormatGroup);
|
||||
GenericDialog configDiag = new GenericDialog("HDF5 Preferences");
|
||||
configDiag.addMessage("Reader:");
|
||||
configDiag.addCheckbox("Group data set names instead of showing a list " + "of data set names.", groupVarsByName);
|
||||
configDiag.addCheckbox("Show unmatched data set names in a separate list", showUnmatchedDataSetNames);
|
||||
configDiag.addStringField("HDF5 group containing pattern " + "for data set grouping: ", groupVarsByNameFormatGroup, 15);
|
||||
configDiag.addStringField("Pattern for grouping (if no attributes" + " are found): ", groupVarsByNameFormat, 15);
|
||||
// configDiag.addStringField("$ regexp (ignored because only numbers" +
|
||||
// " work right now): ",
|
||||
// dollarRegexpForGrouping,15);
|
||||
configDiag.addMessage("Writer:");
|
||||
|
||||
groupVarsByNameFormat = configDiag.getNextString();
|
||||
System.out.println("groupVarsByNameFormat: " +
|
||||
groupVarsByNameFormat);
|
||||
String yesLabel = "Save";
|
||||
String noLabel = "Reset";
|
||||
configDiag.enableYesNoCancel(yesLabel, noLabel);
|
||||
configDiag.showDialog();
|
||||
|
||||
// dollarRegexpForGrouping = configDiag.getNextString();
|
||||
// System.out.println("dollarRegexpForGrouping: " +
|
||||
// dollarRegexpForGrouping);
|
||||
if (configDiag.wasCanceled()) {
|
||||
// do nothing
|
||||
return;
|
||||
}
|
||||
if (!configDiag.wasOKed()) {
|
||||
// reset button was pressed
|
||||
System.out.println("reset button was pressed");
|
||||
// reset all and return a new dialog
|
||||
configDiag.setVisible(false);
|
||||
this.run(arg);
|
||||
return;
|
||||
}
|
||||
// get parameters check if they are correct
|
||||
|
||||
groupVarsByName = configDiag.getNextBoolean();
|
||||
System.out.println("groupVarsByName: " + Boolean.toString(groupVarsByName));
|
||||
|
||||
try
|
||||
{
|
||||
String[] formatTokens
|
||||
= HDF5_GroupedVarnames.parseFormatString(groupVarsByNameFormat,
|
||||
dollarRegexpForGrouping);
|
||||
for(int i=0; i<formatTokens.length; i++)
|
||||
{
|
||||
System.out.println("tok " + Integer.toString(i) + " : "
|
||||
+ formatTokens[i]);
|
||||
}
|
||||
}
|
||||
catch(PatternSyntaxException e)
|
||||
{
|
||||
// produce an error dialog an start over
|
||||
String errMsg = e.getMessage();
|
||||
System.out.println(errMsg);
|
||||
// reset all and return a new dialog
|
||||
configDiag.setVisible(false);
|
||||
this.run(arg);
|
||||
return;
|
||||
}
|
||||
System.out.println("Saving...");
|
||||
showUnmatchedDataSetNames = configDiag.getNextBoolean();
|
||||
System.out.println("showUnmatchedDataSetNames: " + Boolean.toString(showUnmatchedDataSetNames));
|
||||
|
||||
// all OK and "Save" was pressed, so save it...
|
||||
Prefs.set("HDF5.groupVarsByName",
|
||||
groupVarsByName);
|
||||
Prefs.set("HDF5.showUnmatchedDataSetNames",
|
||||
showUnmatchedDataSetNames);
|
||||
Prefs.set("HDF5.groupVarsByNameFormatGroup",
|
||||
groupVarsByNameFormatGroup);
|
||||
Prefs.set("HDF5.groupVarsByNameFormat",
|
||||
groupVarsByNameFormat);
|
||||
//
|
||||
// ignore the $ regexp for now, because only numbers work
|
||||
//
|
||||
Prefs.set("HDF5.dollarRegexpForGrouping",
|
||||
dollarRegexpForGrouping);
|
||||
|
||||
}
|
||||
|
||||
public static void setDefaultsIfNoValueExists()
|
||||
{
|
||||
boolean groupVarsByName =
|
||||
Boolean.getBoolean(getDefaultValue("HDF5.groupVarsByName"));
|
||||
groupVarsByName = Prefs.get("HDF5.groupVarsByName", groupVarsByName);
|
||||
Prefs.set("HDF5.groupVarsByName",
|
||||
groupVarsByName);
|
||||
groupVarsByNameFormatGroup = configDiag.getNextString();
|
||||
System.out.println("groupVarsByNameFormatGroup: " + groupVarsByNameFormatGroup);
|
||||
|
||||
boolean showUnmatchedDataSetNames =
|
||||
Boolean.getBoolean(getDefaultValue("HDF5.showUnmatchedDataSetNames"));
|
||||
showUnmatchedDataSetNames = Prefs.get("HDF5.showUnmatchedDataSetNames",
|
||||
showUnmatchedDataSetNames);
|
||||
Prefs.set("HDF5.showUnmatchedDataSetNames",
|
||||
showUnmatchedDataSetNames);
|
||||
|
||||
String groupVarsByNameFormatGroup =
|
||||
getDefaultValue("HDF5.groupVarsByNameFormatGroup");
|
||||
groupVarsByNameFormatGroup
|
||||
= Prefs.get("HDF5.groupVarsByNameFormatGroup",
|
||||
groupVarsByNameFormatGroup);
|
||||
Prefs.set("HDF5.groupVarsByNameFormatGroup",
|
||||
groupVarsByNameFormatGroup);
|
||||
|
||||
String groupVarsByNameFormat =
|
||||
getDefaultValue("HDF5.groupVarsByNameFormat");
|
||||
groupVarsByNameFormat = Prefs.get("HDF5.groupVarsByNameFormat",
|
||||
groupVarsByNameFormat);
|
||||
Prefs.set("HDF5.groupVarsByNameFormat",
|
||||
groupVarsByNameFormat);
|
||||
groupVarsByNameFormat = configDiag.getNextString();
|
||||
System.out.println("groupVarsByNameFormat: " + groupVarsByNameFormat);
|
||||
|
||||
String dollarRegexpForGrouping =
|
||||
getDefaultValue("HDF5.dollarRegexpForGrouping");
|
||||
dollarRegexpForGrouping = Prefs.get("HDF5.dollarRegexpForGrouping",
|
||||
dollarRegexpForGrouping);
|
||||
Prefs.set("HDF5.dollarRegexpForGrouping",
|
||||
dollarRegexpForGrouping);
|
||||
}
|
||||
// dollarRegexpForGrouping = configDiag.getNextString();
|
||||
// System.out.println("dollarRegexpForGrouping: " +
|
||||
// dollarRegexpForGrouping);
|
||||
|
||||
public static String getDefaultValue(String key)
|
||||
{
|
||||
if(key.equals("HDF5.groupVarsByName"))
|
||||
{
|
||||
boolean groupVarsByName = true; // default
|
||||
return Boolean.toString(groupVarsByName);
|
||||
}
|
||||
else if(key.equals("HDF5.showUnmatchedDataSetNames"))
|
||||
{
|
||||
boolean showUnmatchedDataSetNames = true; // default
|
||||
return Boolean.toString(showUnmatchedDataSetNames);
|
||||
}
|
||||
else if(key.equals("HDF5.groupVarsByNameFormatGroup"))
|
||||
{
|
||||
String groupVarsByNameFormatGroup = "/hints"; // default
|
||||
return groupVarsByNameFormatGroup;
|
||||
}
|
||||
else if(key.equals("HDF5.groupVarsByNameFormat"))
|
||||
{
|
||||
String groupVarsByNameFormat = "/t$T/channel$C"; // default
|
||||
return groupVarsByNameFormat;
|
||||
}
|
||||
else if(key.equals("HDF5.dollarRegexpForGrouping"))
|
||||
{
|
||||
String dollarRegexpForGrouping = "[0-9]+"; // default
|
||||
return dollarRegexpForGrouping;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("No default value for key: " + key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
String[] formatTokens = HDF5_GroupedVarnames.parseFormatString(groupVarsByNameFormat, dollarRegexpForGrouping);
|
||||
for (int i = 0; i < formatTokens.length; i++) {
|
||||
System.out.println("tok " + Integer.toString(i) + " : " + formatTokens[i]);
|
||||
}
|
||||
} catch (PatternSyntaxException e) {
|
||||
// produce an error dialog an start over
|
||||
String errMsg = e.getMessage();
|
||||
System.out.println(errMsg);
|
||||
// reset all and return a new dialog
|
||||
configDiag.setVisible(false);
|
||||
this.run(arg);
|
||||
return;
|
||||
}
|
||||
System.out.println("Saving...");
|
||||
|
||||
// all OK and "Save" was pressed, so save it...
|
||||
Prefs.set("HDF5.groupVarsByName", groupVarsByName);
|
||||
Prefs.set("HDF5.showUnmatchedDataSetNames", showUnmatchedDataSetNames);
|
||||
Prefs.set("HDF5.groupVarsByNameFormatGroup", groupVarsByNameFormatGroup);
|
||||
Prefs.set("HDF5.groupVarsByNameFormat", groupVarsByNameFormat);
|
||||
//
|
||||
// ignore the $ regexp for now, because only numbers work
|
||||
//
|
||||
Prefs.set("HDF5.dollarRegexpForGrouping", dollarRegexpForGrouping);
|
||||
|
||||
}
|
||||
|
||||
public static void setDefaultsIfNoValueExists() {
|
||||
boolean groupVarsByName = Boolean.getBoolean(getDefaultValue("HDF5.groupVarsByName"));
|
||||
groupVarsByName = Prefs.get("HDF5.groupVarsByName", groupVarsByName);
|
||||
Prefs.set("HDF5.groupVarsByName", groupVarsByName);
|
||||
|
||||
boolean showUnmatchedDataSetNames = Boolean.getBoolean(getDefaultValue("HDF5.showUnmatchedDataSetNames"));
|
||||
showUnmatchedDataSetNames = Prefs.get("HDF5.showUnmatchedDataSetNames", showUnmatchedDataSetNames);
|
||||
Prefs.set("HDF5.showUnmatchedDataSetNames", showUnmatchedDataSetNames);
|
||||
|
||||
String groupVarsByNameFormatGroup = getDefaultValue("HDF5.groupVarsByNameFormatGroup");
|
||||
groupVarsByNameFormatGroup = Prefs.get("HDF5.groupVarsByNameFormatGroup", groupVarsByNameFormatGroup);
|
||||
Prefs.set("HDF5.groupVarsByNameFormatGroup", groupVarsByNameFormatGroup);
|
||||
|
||||
String groupVarsByNameFormat = getDefaultValue("HDF5.groupVarsByNameFormat");
|
||||
groupVarsByNameFormat = Prefs.get("HDF5.groupVarsByNameFormat", groupVarsByNameFormat);
|
||||
Prefs.set("HDF5.groupVarsByNameFormat", groupVarsByNameFormat);
|
||||
|
||||
String dollarRegexpForGrouping = getDefaultValue("HDF5.dollarRegexpForGrouping");
|
||||
dollarRegexpForGrouping = Prefs.get("HDF5.dollarRegexpForGrouping", dollarRegexpForGrouping);
|
||||
Prefs.set("HDF5.dollarRegexpForGrouping", dollarRegexpForGrouping);
|
||||
}
|
||||
|
||||
public static String getDefaultValue(String key) {
|
||||
if (key.equals("HDF5.groupVarsByName")) {
|
||||
boolean groupVarsByName = true; // default
|
||||
return Boolean.toString(groupVarsByName);
|
||||
} else if (key.equals("HDF5.showUnmatchedDataSetNames")) {
|
||||
boolean showUnmatchedDataSetNames = true; // default
|
||||
return Boolean.toString(showUnmatchedDataSetNames);
|
||||
} else if (key.equals("HDF5.groupVarsByNameFormatGroup")) {
|
||||
String groupVarsByNameFormatGroup = "/hints"; // default
|
||||
return groupVarsByNameFormatGroup;
|
||||
} else if (key.equals("HDF5.groupVarsByNameFormat")) {
|
||||
String groupVarsByNameFormat = "/t$T/channel$C"; // default
|
||||
return groupVarsByNameFormat;
|
||||
} else if (key.equals("HDF5.dollarRegexpForGrouping")) {
|
||||
String dollarRegexpForGrouping = "[0-9]+"; // default
|
||||
return dollarRegexpForGrouping;
|
||||
} else {
|
||||
System.out.println("No default value for key: " + key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,4 @@
|
||||
package ch.psi.imagej.hdf5;
|
||||
/* =========================================================================
|
||||
*
|
||||
* Copyright 2011 Matthias Schlachter
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*=========================================================================*/
|
||||
|
||||
import java.util.regex.*;
|
||||
import java.util.ArrayList;
|
||||
@ -23,339 +6,265 @@ import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class HDF5_GroupedVarnames
|
||||
{
|
||||
public static String[] parseFormatString(String groupVarsByNameFormat,
|
||||
String dollarRegexpForGrouping)
|
||||
throws PatternSyntaxException
|
||||
{
|
||||
String[] formatTokens = null;
|
||||
formatTokens = groupVarsByNameFormat.split("([$]T|[$]C)");
|
||||
boolean containsFormatVars
|
||||
= groupVarsByNameFormat.contains("$T") &&
|
||||
groupVarsByNameFormat.contains("$C");
|
||||
boolean rightOrderOfFormatVars
|
||||
= groupVarsByNameFormat.indexOf("$T")
|
||||
< groupVarsByNameFormat.indexOf("$C");
|
||||
|
||||
for(int i=0; i<formatTokens.length; i++)
|
||||
{
|
||||
System.out.println("tok " + Integer.toString(i) + " : "
|
||||
+ formatTokens[i]);
|
||||
}
|
||||
if(formatTokens.length < 2 ||
|
||||
!containsFormatVars ||
|
||||
!rightOrderOfFormatVars)
|
||||
{
|
||||
throw new PatternSyntaxException("Your format string has errors. "+
|
||||
"You must provide $T and $C and "+
|
||||
"also in correct order!",
|
||||
groupVarsByNameFormat,
|
||||
-1);
|
||||
}
|
||||
String regexp = groupVarsByNameFormat;
|
||||
regexp = regexp.replace("$T",
|
||||
dollarRegexpForGrouping);
|
||||
regexp = regexp.replace("$C",
|
||||
dollarRegexpForGrouping);
|
||||
System.out.println(regexp);
|
||||
// check if we have a regexp;
|
||||
Pattern p = null;
|
||||
p = Pattern.compile(regexp);
|
||||
return formatTokens;
|
||||
}
|
||||
|
||||
public void parseVarNames(String[] varNames,
|
||||
String groupVarsByNameFormat,
|
||||
String dollarRegexpForGrouping)
|
||||
{
|
||||
// save format string
|
||||
formatString = groupVarsByNameFormat;
|
||||
try
|
||||
{
|
||||
formatTokens = parseFormatString(groupVarsByNameFormat,
|
||||
dollarRegexpForGrouping);
|
||||
}
|
||||
catch(PatternSyntaxException e)
|
||||
{
|
||||
// produce an error dialog an start over
|
||||
String errMsg = e.getMessage();
|
||||
System.out.println(errMsg);
|
||||
return;
|
||||
}
|
||||
String regexp = groupVarsByNameFormat;
|
||||
regexp = regexp.replace("$T",
|
||||
dollarRegexpForGrouping);
|
||||
regexp = regexp.replace("$C",
|
||||
dollarRegexpForGrouping);
|
||||
|
||||
System.out.println(regexp);
|
||||
// check if we have a regexp;
|
||||
Pattern p = null;
|
||||
p = Pattern.compile(regexp);
|
||||
/*---------------------------------------------------------------------
|
||||
* parse var names
|
||||
*---------------------------------------------------------------------*/
|
||||
for (int i = 0; i < varNames.length; i++)
|
||||
{
|
||||
Matcher m=p.matcher(varNames[i]);
|
||||
boolean b=m.matches();
|
||||
if(b)
|
||||
{
|
||||
System.out.println(varNames[i]);
|
||||
matchedVarNames.add(varNames[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
unMatchedVarNames.add(varNames[i]);
|
||||
}
|
||||
}
|
||||
splitGroupedVarnames();
|
||||
// ugly hack for sorting ArrayList
|
||||
Object[] frameListAsArray = frameList.toArray();
|
||||
Arrays.sort(frameListAsArray);
|
||||
for(int i=0;i<frameListAsArray.length;i++)
|
||||
frameList.set(i,(TimeFrame)frameListAsArray[i]);
|
||||
}
|
||||
|
||||
public TimeFrame getFrame(int i)
|
||||
{
|
||||
if(i < frameList.size() && i > -1)
|
||||
return frameList.get(i);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
public class HDF5_GroupedVarnames {
|
||||
|
||||
private final List<String> matchedVarNames = new ArrayList<String>();
|
||||
private final List<String> unMatchedVarNames = new ArrayList<String>();
|
||||
private final List<TimeFrame> frameList = new ArrayList<TimeFrame>();
|
||||
private String[] formatTokens = null;
|
||||
private String formatString = null;
|
||||
private int minFrameIndex = -1;
|
||||
private int maxFrameIndex = -1;
|
||||
private int minChannelIndex = -1;
|
||||
private int maxChannelIndex = -1;
|
||||
private int nChannels = -1;
|
||||
|
||||
public static String[] parseFormatString(String groupVarsByNameFormat, String dollarRegexpForGrouping) throws PatternSyntaxException {
|
||||
String[] formatTokens = null;
|
||||
formatTokens = groupVarsByNameFormat.split("([$]T|[$]C)");
|
||||
boolean containsFormatVars = groupVarsByNameFormat.contains("$T") && groupVarsByNameFormat.contains("$C");
|
||||
boolean rightOrderOfFormatVars = groupVarsByNameFormat.indexOf("$T") < groupVarsByNameFormat.indexOf("$C");
|
||||
|
||||
private void splitGroupedVarnames()
|
||||
{
|
||||
Iterator<String> vars = matchedVarNames.iterator();
|
||||
while(vars.hasNext())
|
||||
{
|
||||
String varName = vars.next();
|
||||
String[] tokens = null;
|
||||
if(formatTokens.length == 2)
|
||||
{
|
||||
tokens = varName.split(formatTokens[1]);
|
||||
}
|
||||
else if(formatTokens.length == 3)
|
||||
{
|
||||
tokens = varName.split(formatTokens[2]);
|
||||
varName = tokens[0];
|
||||
tokens = varName.split(formatTokens[1]);
|
||||
}
|
||||
|
||||
if(tokens.length < 2 || tokens.length > 3)
|
||||
{
|
||||
System.out.println("Error parsing varname!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Integer channelIndex = new Integer(tokens[1]);
|
||||
System.out.println("channelIndex: " + channelIndex.toString());
|
||||
System.out.println("left token: " + tokens[0]);
|
||||
tokens = tokens[0].split("/t");
|
||||
Integer frameIndex = new Integer(tokens[1]);
|
||||
System.out.println("frameIndex: " + frameIndex.toString());
|
||||
for (int i = 0; i < formatTokens.length; i++) {
|
||||
System.out.println("tok " + Integer.toString(i) + " : " + formatTokens[i]);
|
||||
}
|
||||
if (formatTokens.length < 2 || !containsFormatVars || !rightOrderOfFormatVars) {
|
||||
throw new PatternSyntaxException("Your format string has errors. " + "You must provide $T and $C and " + "also in correct order!", groupVarsByNameFormat, -1);
|
||||
}
|
||||
String regexp = groupVarsByNameFormat;
|
||||
regexp = regexp.replace("$T", dollarRegexpForGrouping);
|
||||
regexp = regexp.replace("$C", dollarRegexpForGrouping);
|
||||
System.out.println(regexp);
|
||||
// check if we have a regexp;
|
||||
Pattern.compile(regexp);
|
||||
return formatTokens;
|
||||
}
|
||||
|
||||
if(minFrameIndex == -1)
|
||||
minFrameIndex = frameIndex.intValue();
|
||||
minFrameIndex = Math.min(minFrameIndex,frameIndex.intValue());
|
||||
public void parseVarNames(String[] varNames, String groupVarsByNameFormat, String dollarRegexpForGrouping) {
|
||||
// save format string
|
||||
formatString = groupVarsByNameFormat;
|
||||
try {
|
||||
formatTokens = parseFormatString(groupVarsByNameFormat, dollarRegexpForGrouping);
|
||||
} catch (PatternSyntaxException e) {
|
||||
// produce an error dialog an start over
|
||||
String errMsg = e.getMessage();
|
||||
System.out.println(errMsg);
|
||||
return;
|
||||
}
|
||||
String regexp = groupVarsByNameFormat;
|
||||
regexp = regexp.replace("$T", dollarRegexpForGrouping);
|
||||
regexp = regexp.replace("$C", dollarRegexpForGrouping);
|
||||
|
||||
if(maxFrameIndex == -1)
|
||||
maxFrameIndex = frameIndex.intValue();
|
||||
maxFrameIndex = Math.max(maxFrameIndex,frameIndex.intValue());
|
||||
|
||||
if(minChannelIndex == -1)
|
||||
minChannelIndex = channelIndex.intValue();
|
||||
minChannelIndex = Math.min(minChannelIndex,channelIndex.intValue());
|
||||
System.out.println(regexp);
|
||||
// check if we have a regexp;
|
||||
Pattern p = null;
|
||||
p = Pattern.compile(regexp);
|
||||
/*---------------------------------------------------------------------
|
||||
* parse var names
|
||||
*---------------------------------------------------------------------*/
|
||||
for (int i = 0; i < varNames.length; i++) {
|
||||
Matcher m = p.matcher(varNames[i]);
|
||||
boolean b = m.matches();
|
||||
if (b) {
|
||||
System.out.println(varNames[i]);
|
||||
matchedVarNames.add(varNames[i]);
|
||||
} else {
|
||||
unMatchedVarNames.add(varNames[i]);
|
||||
}
|
||||
}
|
||||
splitGroupedVarnames();
|
||||
// ugly hack for sorting ArrayList
|
||||
Object[] frameListAsArray = frameList.toArray();
|
||||
Arrays.sort(frameListAsArray);
|
||||
for (int i = 0; i < frameListAsArray.length; i++)
|
||||
frameList.set(i, (TimeFrame) frameListAsArray[i]);
|
||||
}
|
||||
|
||||
if(maxChannelIndex == -1)
|
||||
maxChannelIndex = channelIndex.intValue();
|
||||
maxChannelIndex = Math.max(maxChannelIndex,channelIndex.intValue());
|
||||
public TimeFrame getFrame(int i) {
|
||||
if (i < frameList.size() && i > -1)
|
||||
return frameList.get(i);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
TimeFrame frame = new TimeFrame(frameIndex.intValue());
|
||||
int idx = frameList.indexOf(frame);
|
||||
if(idx != -1)
|
||||
{
|
||||
frame = (TimeFrame) frameList.get(idx);
|
||||
frame.addChannel(channelIndex.intValue());
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.addChannel(channelIndex.intValue());
|
||||
frameList.add(frame);
|
||||
}
|
||||
//System.out.println(frame.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
private void splitGroupedVarnames() {
|
||||
Iterator<String> vars = matchedVarNames.iterator();
|
||||
while (vars.hasNext()) {
|
||||
String varName = vars.next();
|
||||
String[] tokens = null;
|
||||
if (formatTokens.length == 2) {
|
||||
tokens = varName.split(formatTokens[1]);
|
||||
} else if (formatTokens.length == 3) {
|
||||
tokens = varName.split(formatTokens[2]);
|
||||
varName = tokens[0];
|
||||
tokens = varName.split(formatTokens[1]);
|
||||
}
|
||||
|
||||
public int getMinFrameIndex()
|
||||
{
|
||||
return minFrameIndex;
|
||||
}
|
||||
public int getMaxFrameIndex()
|
||||
{
|
||||
return maxFrameIndex;
|
||||
}
|
||||
public int getMinChannelIndex()
|
||||
{
|
||||
return minChannelIndex;
|
||||
}
|
||||
public int getMaxChannelIndex()
|
||||
{
|
||||
return maxChannelIndex;
|
||||
}
|
||||
public int getNFrames()
|
||||
{
|
||||
return frameList.size();
|
||||
}
|
||||
public int getNChannels()
|
||||
{
|
||||
// TODO: check all frames for min/max of channels not index
|
||||
if(nChannels == -1)
|
||||
return maxChannelIndex-minChannelIndex+1;
|
||||
else
|
||||
return nChannels;
|
||||
}
|
||||
public boolean hasAllFramesInRange()
|
||||
{
|
||||
return frameList.size() == (maxFrameIndex-minFrameIndex+1);
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
String s = "Data set statistics\n";
|
||||
s = s + "----------------------------------\n";
|
||||
s = s + "nFrames: " + Integer.toString(frameList.size()) + "\n";
|
||||
s = s + "minFrameIndex: " + Integer.toString(minFrameIndex) + "\n";
|
||||
s = s + "maxFrameIndex: " + Integer.toString(maxFrameIndex) + "\n";
|
||||
s = s
|
||||
+ "hasAllFramesInRange: "
|
||||
+ Boolean.toString(hasAllFramesInRange()) + "\n";
|
||||
s = s + "minChannelIndex: " + Integer.toString(minChannelIndex) + "\n";
|
||||
s = s + "maxChannelIndex: " + Integer.toString(maxChannelIndex) + "\n";
|
||||
if (tokens.length < 2 || tokens.length > 3) {
|
||||
System.out.println("Error parsing varname!");
|
||||
} else {
|
||||
Integer channelIndex = new Integer(tokens[1]);
|
||||
System.out.println("channelIndex: " + channelIndex.toString());
|
||||
System.out.println("left token: " + tokens[0]);
|
||||
tokens = tokens[0].split("/t");
|
||||
Integer frameIndex = new Integer(tokens[1]);
|
||||
System.out.println("frameIndex: " + frameIndex.toString());
|
||||
|
||||
// String[] toks = getFormatTokens();
|
||||
Iterator<TimeFrame> frames = frameList.iterator();
|
||||
while(frames.hasNext())
|
||||
{
|
||||
TimeFrame f = frames.next();
|
||||
s = s + f.toString() + "\n";
|
||||
// s = s + "(" + toks[0] +
|
||||
// Integer.toString(f.getFrameIndex())
|
||||
// + toks[1] + "$C";
|
||||
// if(toks.length>2)
|
||||
// s = s + toks[2] + "\n";
|
||||
// else
|
||||
// s = s + "\n";
|
||||
}
|
||||
s = s + "----------------------------------";
|
||||
return s;
|
||||
}
|
||||
if (minFrameIndex == -1)
|
||||
minFrameIndex = frameIndex.intValue();
|
||||
minFrameIndex = Math.min(minFrameIndex, frameIndex.intValue());
|
||||
|
||||
public List<String> getUnmatchedVarNames()
|
||||
{
|
||||
return unMatchedVarNames;
|
||||
}
|
||||
|
||||
public String[] getFormatTokens()
|
||||
{
|
||||
return formatTokens;
|
||||
}
|
||||
if (maxFrameIndex == -1)
|
||||
maxFrameIndex = frameIndex.intValue();
|
||||
maxFrameIndex = Math.max(maxFrameIndex, frameIndex.intValue());
|
||||
|
||||
public String getFormatString()
|
||||
{
|
||||
return formatString;
|
||||
}
|
||||
if (minChannelIndex == -1)
|
||||
minChannelIndex = channelIndex.intValue();
|
||||
minChannelIndex = Math.min(minChannelIndex, channelIndex.intValue());
|
||||
|
||||
public void setFrameAndChannelRange(int minFrame,
|
||||
int skipFrame,
|
||||
int maxFrame,
|
||||
int minChannel,
|
||||
int skipChannel,
|
||||
int maxChannel)
|
||||
{
|
||||
System.out.println("Setting frame range: " +
|
||||
Integer.toString(minFrame) + ":" +
|
||||
Integer.toString(skipFrame) + ":" +
|
||||
Integer.toString(maxFrame));
|
||||
System.out.println("Setting channel range: " +
|
||||
Integer.toString(minChannel) + ":" +
|
||||
Integer.toString(skipChannel) + ":" +
|
||||
Integer.toString(maxChannel));
|
||||
if(hasAllFramesInRange())
|
||||
{
|
||||
// copy frames
|
||||
List<TimeFrame> completeFrameList = new ArrayList<TimeFrame>(frameList);
|
||||
// clear frames
|
||||
frameList.clear();
|
||||
// insert wanted frames and channels
|
||||
for(int f=minFrame;f<maxFrame+1;f+=skipFrame)
|
||||
{
|
||||
TimeFrame frameAllChannels = completeFrameList.get(f);
|
||||
TimeFrame frame = new TimeFrame(frameAllChannels.getFrameIndex());
|
||||
// TODO remove unwanted channels
|
||||
for(int c=minChannel;c<maxChannel+1;c+=skipChannel)
|
||||
{
|
||||
//System.out.println("Adding channels: " + Integer.toString(c));
|
||||
frame.addChannel(c);
|
||||
}
|
||||
// if(nChannels == -1)
|
||||
// nChannels = frame.getNChannels();
|
||||
frameList.add(frame);
|
||||
}
|
||||
// TODO update min/max of frames/channels
|
||||
nChannels = ((maxChannel-minChannel) / skipChannel)+1;
|
||||
System.out.println("Adding nChannels: " + Integer.toString(nChannels));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("-------------------------\n"+
|
||||
"hasAllFramesInRange==false\n"+
|
||||
"-------------------------");
|
||||
// copy frames
|
||||
List<TimeFrame> completeFrameList = new ArrayList<TimeFrame>(frameList);
|
||||
// clear frames
|
||||
frameList.clear();
|
||||
// insert wanted frames and channels
|
||||
for(int f=minFrame;f<maxFrame+1;f+=skipFrame)
|
||||
{
|
||||
TimeFrame frame = new TimeFrame(f);
|
||||
int idx = completeFrameList.indexOf(frame);
|
||||
// System.out.println("index of frame in list: " +
|
||||
// Integer.toString(idx));
|
||||
if(idx != -1)
|
||||
{
|
||||
// TODO remove unwanted channels
|
||||
for(int c=minChannel;c<maxChannel+1;c+=skipChannel)
|
||||
{
|
||||
//System.out.println("Adding channels: " + Integer.toString(c));
|
||||
frame.addChannel(c);
|
||||
}
|
||||
// if(nChannels == -1)
|
||||
// nChannels = frame.getNChannels();
|
||||
frameList.add(frame);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Timestep "+Integer.toString(f)+
|
||||
" is missing!");
|
||||
}
|
||||
}
|
||||
// TODO update min/max of frames/channels
|
||||
nChannels = ((maxChannel-minChannel) / skipChannel)+1;
|
||||
System.out.println("Adding nChannels: " + Integer.toString(nChannels));
|
||||
}
|
||||
}
|
||||
if (maxChannelIndex == -1)
|
||||
maxChannelIndex = channelIndex.intValue();
|
||||
maxChannelIndex = Math.max(maxChannelIndex, channelIndex.intValue());
|
||||
|
||||
private final List<String> matchedVarNames = new ArrayList<String>();
|
||||
private final List<String> unMatchedVarNames = new ArrayList<String>();
|
||||
private final List<TimeFrame> frameList = new ArrayList<TimeFrame>();
|
||||
private String[] formatTokens = null;
|
||||
private String formatString = null;
|
||||
private int minFrameIndex = -1;
|
||||
private int maxFrameIndex = -1;
|
||||
private int minChannelIndex = -1;
|
||||
private int maxChannelIndex = -1;
|
||||
private int nChannels = -1;
|
||||
TimeFrame frame = new TimeFrame(frameIndex.intValue());
|
||||
int idx = frameList.indexOf(frame);
|
||||
if (idx != -1) {
|
||||
frame = (TimeFrame) frameList.get(idx);
|
||||
frame.addChannel(channelIndex.intValue());
|
||||
} else {
|
||||
frame.addChannel(channelIndex.intValue());
|
||||
frameList.add(frame);
|
||||
}
|
||||
// System.out.println(frame.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getMinFrameIndex() {
|
||||
return minFrameIndex;
|
||||
}
|
||||
|
||||
public int getMaxFrameIndex() {
|
||||
return maxFrameIndex;
|
||||
}
|
||||
|
||||
public int getMinChannelIndex() {
|
||||
return minChannelIndex;
|
||||
}
|
||||
|
||||
public int getMaxChannelIndex() {
|
||||
return maxChannelIndex;
|
||||
}
|
||||
|
||||
public int getNFrames() {
|
||||
return frameList.size();
|
||||
}
|
||||
|
||||
public int getNChannels() {
|
||||
// TODO: check all frames for min/max of channels not index
|
||||
if (nChannels == -1)
|
||||
return maxChannelIndex - minChannelIndex + 1;
|
||||
else
|
||||
return nChannels;
|
||||
}
|
||||
|
||||
public boolean hasAllFramesInRange() {
|
||||
return frameList.size() == (maxFrameIndex - minFrameIndex + 1);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String s = "Data set statistics\n";
|
||||
s = s + "----------------------------------\n";
|
||||
s = s + "nFrames: " + Integer.toString(frameList.size()) + "\n";
|
||||
s = s + "minFrameIndex: " + Integer.toString(minFrameIndex) + "\n";
|
||||
s = s + "maxFrameIndex: " + Integer.toString(maxFrameIndex) + "\n";
|
||||
s = s + "hasAllFramesInRange: " + Boolean.toString(hasAllFramesInRange()) + "\n";
|
||||
s = s + "minChannelIndex: " + Integer.toString(minChannelIndex) + "\n";
|
||||
s = s + "maxChannelIndex: " + Integer.toString(maxChannelIndex) + "\n";
|
||||
|
||||
// String[] toks = getFormatTokens();
|
||||
Iterator<TimeFrame> frames = frameList.iterator();
|
||||
while (frames.hasNext()) {
|
||||
TimeFrame f = frames.next();
|
||||
s = s + f.toString() + "\n";
|
||||
// s = s + "(" + toks[0] +
|
||||
// Integer.toString(f.getFrameIndex())
|
||||
// + toks[1] + "$C";
|
||||
// if(toks.length>2)
|
||||
// s = s + toks[2] + "\n";
|
||||
// else
|
||||
// s = s + "\n";
|
||||
}
|
||||
s = s + "----------------------------------";
|
||||
return s;
|
||||
}
|
||||
|
||||
public List<String> getUnmatchedVarNames() {
|
||||
return unMatchedVarNames;
|
||||
}
|
||||
|
||||
public String[] getFormatTokens() {
|
||||
return formatTokens;
|
||||
}
|
||||
|
||||
public String getFormatString() {
|
||||
return formatString;
|
||||
}
|
||||
|
||||
public void setFrameAndChannelRange(int minFrame, int skipFrame, int maxFrame, int minChannel, int skipChannel, int maxChannel) {
|
||||
System.out.println("Setting frame range: " + Integer.toString(minFrame) + ":" + Integer.toString(skipFrame) + ":" + Integer.toString(maxFrame));
|
||||
System.out.println("Setting channel range: " + Integer.toString(minChannel) + ":" + Integer.toString(skipChannel) + ":" + Integer.toString(maxChannel));
|
||||
if (hasAllFramesInRange()) {
|
||||
// copy frames
|
||||
List<TimeFrame> completeFrameList = new ArrayList<TimeFrame>(frameList);
|
||||
// clear frames
|
||||
frameList.clear();
|
||||
// insert wanted frames and channels
|
||||
for (int f = minFrame; f < maxFrame + 1; f += skipFrame) {
|
||||
TimeFrame frameAllChannels = completeFrameList.get(f);
|
||||
TimeFrame frame = new TimeFrame(frameAllChannels.getFrameIndex());
|
||||
// TODO remove unwanted channels
|
||||
for (int c = minChannel; c < maxChannel + 1; c += skipChannel) {
|
||||
// System.out.println("Adding channels: " +
|
||||
// Integer.toString(c));
|
||||
frame.addChannel(c);
|
||||
}
|
||||
// if(nChannels == -1)
|
||||
// nChannels = frame.getNChannels();
|
||||
frameList.add(frame);
|
||||
}
|
||||
// TODO update min/max of frames/channels
|
||||
nChannels = ((maxChannel - minChannel) / skipChannel) + 1;
|
||||
System.out.println("Adding nChannels: " + Integer.toString(nChannels));
|
||||
} else {
|
||||
System.out.println("-------------------------\n" + "hasAllFramesInRange==false\n" + "-------------------------");
|
||||
// copy frames
|
||||
List<TimeFrame> completeFrameList = new ArrayList<TimeFrame>(frameList);
|
||||
// clear frames
|
||||
frameList.clear();
|
||||
// insert wanted frames and channels
|
||||
for (int f = minFrame; f < maxFrame + 1; f += skipFrame) {
|
||||
TimeFrame frame = new TimeFrame(f);
|
||||
int idx = completeFrameList.indexOf(frame);
|
||||
// System.out.println("index of frame in list: " +
|
||||
// Integer.toString(idx));
|
||||
if (idx != -1) {
|
||||
// TODO remove unwanted channels
|
||||
for (int c = minChannel; c < maxChannel + 1; c += skipChannel) {
|
||||
// System.out.println("Adding channels: " +
|
||||
// Integer.toString(c));
|
||||
frame.addChannel(c);
|
||||
}
|
||||
// if(nChannels == -1)
|
||||
// nChannels = frame.getNChannels();
|
||||
frameList.add(frame);
|
||||
} else {
|
||||
System.out.println("Timestep " + Integer.toString(f) + " is missing!");
|
||||
}
|
||||
}
|
||||
// TODO update min/max of frames/channels
|
||||
nChannels = ((maxChannel - minChannel) / skipChannel) + 1;
|
||||
System.out.println("Adding nChannels: " + Integer.toString(nChannels));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,102 +1,74 @@
|
||||
package ch.psi.imagej.hdf5;
|
||||
/* =========================================================================
|
||||
*
|
||||
* Copyright 2011 Matthias Schlachter
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*=========================================================================*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TimeFrame implements Comparable
|
||||
{
|
||||
public TimeFrame(int index)
|
||||
{
|
||||
frameIndex = index;
|
||||
}
|
||||
public class TimeFrame implements Comparable<TimeFrame> {
|
||||
|
||||
private final int frameIndex;
|
||||
private final List<Integer> channels = new ArrayList<Integer>();
|
||||
|
||||
public TimeFrame(int index) {
|
||||
frameIndex = index;
|
||||
}
|
||||
|
||||
public TimeFrame(String index)
|
||||
{
|
||||
frameIndex = Integer.parseInt(index);
|
||||
}
|
||||
public TimeFrame(String index) {
|
||||
frameIndex = Integer.parseInt(index);
|
||||
}
|
||||
|
||||
public void addChannel(int index)
|
||||
{
|
||||
Integer channelIndex = new Integer(index);
|
||||
if(!channels.contains(channelIndex))
|
||||
channels.add(new Integer(index));
|
||||
else
|
||||
System.out.println("channel" + channelIndex.toString()
|
||||
+ " already in list!");
|
||||
}
|
||||
public void addChannel(Integer index) {
|
||||
if (!channels.contains(index)){
|
||||
channels.add(new Integer(index));
|
||||
}
|
||||
}
|
||||
|
||||
public void addChannel(String index)
|
||||
{
|
||||
addChannel(Integer.parseInt(index));
|
||||
}
|
||||
public void addChannel(String index) {
|
||||
addChannel(Integer.parseInt(index));
|
||||
}
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
TimeFrame f = (TimeFrame) obj;
|
||||
if(f.frameIndex == frameIndex)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public boolean equals(Object o) {
|
||||
return (((TimeFrame)o).frameIndex == frameIndex);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String s = "FrameIdx: " + Integer.toString(frameIndex) + "; ";
|
||||
s = s + "nChannels: " + Integer.toString(channels.size()) + "; ";
|
||||
s = s + "channels: ";
|
||||
for(int i=0;i<channels.size();i++)
|
||||
s = s + Integer.toString(channels.get(i)) + ";";
|
||||
|
||||
return s;
|
||||
}
|
||||
public String toString() {
|
||||
String s = "FrameIdx: " + Integer.toString(frameIndex) + "; ";
|
||||
s = s + "nChannels: " + Integer.toString(channels.size()) + "; ";
|
||||
s = s + "channels: ";
|
||||
for (int i = 0; i < channels.size(); i++){
|
||||
s = s + Integer.toString(channels.get(i)) + ";";
|
||||
}
|
||||
|
||||
public int getNChannels()
|
||||
{
|
||||
return channels.size();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public int getFrameIndex()
|
||||
{
|
||||
return frameIndex;
|
||||
}
|
||||
|
||||
public int[] getChannelIndices()
|
||||
{
|
||||
Object[] channelsAsArray = channels.toArray();
|
||||
Arrays.sort(channelsAsArray);
|
||||
int[] channelsIdx = new int[channelsAsArray.length];
|
||||
for(int i=0;i<channelsAsArray.length;i++)
|
||||
channelsIdx[i] = ((Integer) channelsAsArray[i]).intValue();
|
||||
return channelsIdx;
|
||||
}
|
||||
|
||||
public int compareTo(Object obj)
|
||||
{
|
||||
TimeFrame f = (TimeFrame) obj;
|
||||
if(frameIndex<f.frameIndex)
|
||||
return -1;
|
||||
else if(frameIndex>f.frameIndex)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
private final int frameIndex;
|
||||
private final ArrayList<Integer> channels = new ArrayList<Integer>();
|
||||
public int getNChannels() {
|
||||
return channels.size();
|
||||
}
|
||||
|
||||
public int getFrameIndex() {
|
||||
return frameIndex;
|
||||
}
|
||||
|
||||
public int[] getChannelIndices() {
|
||||
Object[] channelsAsArray = channels.toArray();
|
||||
Arrays.sort(channelsAsArray);
|
||||
int[] channelsIdx = new int[channelsAsArray.length];
|
||||
for (int i = 0; i < channelsAsArray.length; i++){
|
||||
channelsIdx[i] = ((Integer) channelsAsArray[i]).intValue();
|
||||
}
|
||||
return channelsIdx;
|
||||
}
|
||||
|
||||
public int compareTo(TimeFrame f) {
|
||||
if (frameIndex < f.frameIndex){
|
||||
return -1;
|
||||
}
|
||||
else if (frameIndex > f.frameIndex){
|
||||
return 1;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user