Browse Source

Modified org.pf4j.PluginState to an enum (#328)

pull/329/head
MacTrophy 5 years ago committed by Decebal Suiu
parent
commit
9ef232d34d
  1. 36
      pf4j/src/main/java/org/pf4j/PluginState.java

36
pf4j/src/main/java/org/pf4j/PluginState.java

@ -18,33 +18,33 @@ package org.pf4j;
/** /**
* @author Decebal Suiu * @author Decebal Suiu
*/ */
public class PluginState { public enum PluginState {
/** /**
* The runtime knows the plugin is there. It knows about the plugin path, the plugin descriptor. * The runtime knows the plugin is there. It knows about the plugin path, the plugin descriptor.
*/ */
public static final PluginState CREATED = new PluginState("CREATED"); CREATED("CREATED"),
/** /**
* The plugin cannot be used. * The plugin cannot be used.
*/ */
public static final PluginState DISABLED = new PluginState("DISABLED"); DISABLED("DISABLED"),
/** /**
* The plugin is created. All the dependencies are created and resolved. * The plugin is created. All the dependencies are created and resolved.
* The plugin is ready to be started. * The plugin is ready to be started.
*/ */
public static final PluginState RESOLVED = new PluginState("RESOLVED"); RESOLVED("RESOLVED"),
/** /**
* The {@link Plugin#start()} has executed. A started plugin may contribute extensions. * The {@link Plugin#start()} has executed. A started plugin may contribute extensions.
*/ */
public static final PluginState STARTED = new PluginState("STARTED"); STARTED("STARTED"),
/** /**
* The {@link Plugin#stop()} has executed. * The {@link Plugin#stop()} has executed.
*/ */
public static final PluginState STOPPED = new PluginState("STOPPED"); STOPPED("STOPPED");
private String status; private String status;
@ -52,19 +52,8 @@ public class PluginState {
this.status = status; this.status = status;
} }
@Override public boolean equals(String status) {
public boolean equals(Object o) { return (status == null ? false : this.status.equalsIgnoreCase(status));
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PluginState that = (PluginState) o;
return status.equals(that.status);
}
@Override
public int hashCode() {
return status.hashCode();
} }
@Override @Override
@ -72,4 +61,13 @@ public class PluginState {
return status; return status;
} }
public static PluginState parse(String string) {
for (PluginState status : values()) {
if (status.equals(string)) {
return status;
}
}
return null;
}
} }

Loading…
Cancel
Save