// 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; import io.gitea.model.Issue; /** Gitea Issue State * * Note: Constructor is private to limit IssueState to predefined ones. */ public enum IssueState { STATE_ANY("all"),STATE_OPENED("open"),STATE_CLOSED("closed"); private String value; private IssueState(String value) { this.value = value; } public static IssueState getEnum(String value) { for(IssueState s: IssueState.values()) { if (s.equals(value)) return s; } throw new IllegalArgumentException(value + " is not a IssueState value"); } public String toString() { return this.value; } public boolean equals(IssueState arg0) { return this.value.equals(arg0.toString()); } public boolean equals(String arg0) { return this.value.equals(arg0); } /**Check if an issue is "open" * * @param issue Gitea Issue * @return True if the state is "open". * * @apiNote isOpen() is not the opposite of isClose() * "isOpen() == false" doesn't means that "isClose() == true" * */ public static boolean isOpen(Issue issue) { return IssueState.isOpen(issue.getState()); } /**Check if a status value is "open". * * @param status Status value as String */ public static boolean isOpen(String value) { return STATE_OPENED.equals(value); } /**Check if the issue is "closed". * * @param issue GItea Issue * @return True if the issue state is "closed" */ public static boolean isClosed(Issue issue) { return IssueState.isClosed(issue.getState()); } /**Check if a status value is "closed". * * @param status Status value as String */ public static boolean isClosed(String value) { return STATE_CLOSED.equals(value); } }