cleaning this up but balking at refactoring

This commit is contained in:
Ben Fry
2016-08-16 15:15:31 -04:00
parent 0d8e26bb11
commit 94b141442c
2 changed files with 26 additions and 28 deletions
@@ -316,6 +316,27 @@ abstract public class Contribution {
}
/**
* Helper function that creates a StringList of the compatible Modes
* for this Contribution.
*/
static StringList parseModeList(StringDict properties) {
String unparsedModes = properties.get(MODES_PROPERTY);
// Workaround for 3.0 alpha/beta bug for 3.0b2
if ("null".equals(unparsedModes)) {
properties.remove(MODES_PROPERTY);
unparsedModes = null;
}
StringList outgoing = new StringList();
if (unparsedModes != null) {
outgoing.append(PApplet.trim(PApplet.split(unparsedModes, ',')));
}
return outgoing;
}
static private String translateCategory(String cat) {
// Converts Other to other, I/O to i_o, Video & Vision to video_vision
String cleaned = cat.replaceAll("[\\W]+", "_").toLowerCase();
@@ -7,7 +7,6 @@ import java.util.Map;
import processing.app.Base;
import processing.app.Mode;
import processing.core.PApplet;
import processing.data.StringDict;
import processing.data.StringList;
import static processing.app.contrib.ContributionType.EXAMPLES;
@@ -31,34 +30,17 @@ public class ExamplesContribution extends LocalContribution {
}
static private StringList parseModeList(StringDict properties) {
String unparsedModes = properties.get(MODES_PROPERTY);
// Workaround for 3.0 alpha/beta bug for 3.0b2
if ("null".equals(unparsedModes)) {
properties.remove(MODES_PROPERTY);
unparsedModes = null;
}
StringList outgoing = new StringList();
if (unparsedModes != null) {
outgoing.append(PApplet.trim(PApplet.split(unparsedModes, ',')));
}
return outgoing;
static public boolean isCompatible(Base base, StringDict props) {
return isCompatible(base.getActiveEditor().getMode(), props);
}
/**
* Function to determine whether or not the example present in the
* exampleLocation directory is compatible with the current mode.
*
* @param base
* @param props
* @return true if the example is compatible with the mode of the currently
* active editor
* @return true if compatible with the Mode of the currently active editor
*/
static public boolean isCompatible(Base base, StringDict props) {
Mode mode = base.getActiveEditor().getMode();
static public boolean isCompatible(Mode mode, StringDict props) {
String currentIdentifier = mode.getIdentifier();
StringList compatibleList = parseModeList(props);
if (compatibleList.size() == 0) {
@@ -69,12 +51,7 @@ public class ExamplesContribution extends LocalContribution {
// if no Mode specified, assume compatible everywhere
return true;
}
for (String c : compatibleList) {
if (c.equals(currentIdentifier)) {
return true;
}
}
return false;
return compatibleList.hasValue(currentIdentifier);
}