Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,50 @@ public class BandGroupingPath {
BandGroupingPath(String[] groups) {
this.groups = groups;
entries = new Entry[groups.length];

// Default for SNAP and SeaDAS differs here, SeaDAS uses 'true', SNAP uses 'false'
// Ideally this would be defined in preferences
boolean useStartsWithInsteadOfContains = false;

for (int i = 0; i < groups.length; i++) {
final String groupPattern = groups[i];
if (groupPattern.contains("*") || groupPattern.contains("?")) {
if (groupPattern.contains("*") || groupPattern.contains("?")) {
// Wildcard Matching
entries[i] = new WildCardEntry(groupPattern);
} else if (groupPattern.contains("#")) {
final String[] split = StringUtils.split(groupPattern, new char[]{'#'}, true);
final String groupName = split[0];
this.groups[i] = groupName;
entries[i] = new BandNamesEntry(groupName, split[1]);
} else if (groupPattern.contains("#") || groupPattern.contains(",")) {
// BandNames Matching
if (groupPattern.contains("#")) {
// Rename the group
final String[] split = StringUtils.split(groupPattern, new char[]{'#'}, true);
final String groupName = split[0];
// comment this out as this is problematic, although it does work, the Band 'Properties' editor reads it as only the name and not the full expression
// this.groups[i] = groupName;
entries[i] = new BandNamesEntry(groupName, split[1]);
} else {
// Maintain the original group expression as the group name
entries[i] = new BandNamesEntry(groupPattern, groupPattern);
}
} else if (groupPattern.startsWith("^") && groupPattern.endsWith("$")) {
// Exact Matching
String groupTrimmed = groupPattern.substring(1, groupPattern.length() -1);
entries[i] = new ExactEntry(groupTrimmed);
} else if (groupPattern.startsWith("^")) {
// StartsWith Matching
String groupTrimmed = groupPattern.substring(1);
entries[i] = new StartsWithEntry(groupTrimmed);
} else if (groupPattern.endsWith("$")) {
// EndsWith Matching
String groupTrimmed = groupPattern.substring(0, groupPattern.length() - 1);
entries[i] = new EndsWithEntry(groupTrimmed);
} else {
entries[i] = new EntryImpl(groupPattern);
// Default Matching
if (useStartsWithInsteadOfContains) {
// StartsWith Matching
entries[i] = new StartsWithEntry(groupPattern);
} else {
// Contains Matching
entries[i] = new EntryImpl(groupPattern);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eu.esa.snap.core.datamodel.group;

class EndsWithEntry implements Entry {

private final String group;

protected EndsWithEntry(String group) {
this.group = group;
}

@Override
public boolean matches(String name) {
return name.endsWith(group);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eu.esa.snap.core.datamodel.group;

class ExactEntry implements Entry {

private final String group;

protected ExactEntry(String group) {
this.group = group;
}

@Override
public boolean matches(String name) {
return name.equals(group);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eu.esa.snap.core.datamodel.group;

class StartsWithEntry implements Entry {

private final String group;

protected StartsWithEntry(String group) {
this.group = group;
}

@Override
public boolean matches(String name) {
return name.startsWith(group);
}
}
50 changes: 50 additions & 0 deletions snap-core/src/main/java/org/esa/snap/core/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,4 +1073,54 @@ static String toProperCase(String s) {

return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
}


/**
* Creates a more user friendly folder name for the band group with the match criteria being removed.
* For example: if the band grouping was "^a_" (which would match a_442, a_460, etc.) then the returned
* displayName would be "a"
*
* @param displayName current display name of the particular group
* @return a modified display name which has removed characters intended for the match criteria
*/
static public String cleanUpGroupName(String displayName) {

if (displayName == null) {
return null;
}

if (displayName.contains("#")) {
final String[] split = StringUtils.split(displayName, new char[]{'#'}, true);
final String groupName = split[0];
if (groupName.length() > 0) {
displayName = groupName;
}
} else {
if (displayName.startsWith("^")) {
displayName = displayName.substring(1);
}

if (displayName.endsWith("$")) {
displayName = displayName.substring(0, displayName.length() - 1);
}

if (displayName.startsWith("*")) {
displayName = displayName.substring(1);
}

if (displayName.endsWith("*")) {
displayName = displayName.substring(0, displayName.length() - 1);
}

if (displayName.startsWith("_")) {
displayName = displayName.substring(1);
}

if (displayName.endsWith("_")) {
displayName = displayName.substring(0, displayName.length() - 1);
}
}

return displayName;
}
}