View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2022, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.model.conditional;
15  
16  import java.util.Objects;
17  
18  import ch.qos.logback.core.model.Model;
19  
20  public class IfModel extends Model {
21  
22      private static final long serialVersionUID = 1516046821762377019L;
23  
24      public enum BranchState {IN_ERROR, IF_BRANCH, ELSE_BRANCH; }
25      
26      String condition;
27      BranchState branchState = null;
28      
29      @Override
30      protected IfModel makeNewInstance() {
31          return new IfModel();
32      }
33      
34      @Override
35      protected void mirror(Model that) {
36          IfModel actual = (IfModel) that;
37          super.mirror(actual);
38          this.condition = actual.condition;
39          this.branchState = actual.branchState;
40      }
41      
42      public String getCondition() {
43          return condition;
44      }
45  
46      public void setCondition(String condition) {
47          this.condition = condition;
48      }
49      
50      public BranchState getBranchState() {
51          return branchState;
52      }
53      
54      public void setBranchState(BranchState state) {
55          this.branchState = state;
56      }
57      
58  
59      public void setBranchState(boolean booleanProxy) {
60          if(booleanProxy)
61              setBranchState(BranchState.IF_BRANCH);
62          else 
63              setBranchState(BranchState.ELSE_BRANCH);
64      }
65      
66      public void resetBranchState() {
67          setBranchState(null);
68      }
69      
70      @Override
71      public String toString() {
72          return this.getClass().getSimpleName() + " [condition=\""+condition+"\"]";
73      }
74  
75      @Override
76      public int hashCode() {
77          final int prime = 31;
78          int result = super.hashCode();
79          result = prime * result + Objects.hash(branchState, condition);
80          return result;
81      }
82  
83      @Override
84      public boolean equals(Object obj) {
85          if (this == obj)
86              return true;
87          if (!super.equals(obj))
88              return false;
89          if (getClass() != obj.getClass())
90              return false;
91          IfModel other = (IfModel) obj;
92          return branchState == other.branchState && Objects.equals(condition, other.condition);
93      }
94          
95  
96  }