mylyn-gitea/io.gitea.mylyn.core/src/io/gitea/model/IssueAction.java

49 lines
1.5 KiB
Java

// Copyright (c) 2021, Fr.Terrot. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package io.gitea.model;
public enum IssueAction {
CLOSE("close"),
LEAVE("leave"),
REOPEN("reopen");
IssueAction(String label) {
this.label = label;
}
public final String label;
public static IssueAction getEnum(String other) {
if ((other == null)||(other.isBlank()) || (other.isEmpty()))
return LEAVE;
for (IssueAction a : IssueAction.values())
if (a.equals(other)) return a;
throw new IllegalArgumentException(other + " is not a IssueAction value");
}
/**Compute targeted state when apply action as transition to a state.
*
* [from State: OPENED] --> Action: CLOSE --> [to State:CLOSED]
* [from State: CLOSED] --> Action: REOPEN --> [to State: OPENDED]
* All other cases have no impact on State.
*
* @param fromState
* @return Targeted state as IssueState.
*/
public IssueState toState(IssueState fromState) {
if ((this == CLOSE) && (fromState == IssueState.STATE_OPENED)) return IssueState.STATE_CLOSED;
if ((this == REOPEN) && (fromState == IssueState.STATE_CLOSED)) return IssueState.STATE_OPENED;
return fromState;
}
static public IssueState toState(IssueState from, IssueAction onAction) {
return onAction.toState(from);
}
public boolean equals(IssueAction arg0) {
return this.label.equals(arg0.toString());
}
public boolean equals(String arg0) {
return this.label.equals(arg0);
}
}