001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2022, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.model.conditional; 015 016import java.util.Objects; 017 018import ch.qos.logback.core.model.Model; 019 020public class IfModel extends Model { 021 022 private static final long serialVersionUID = 1516046821762377019L; 023 024 public enum BranchState {IN_ERROR, IF_BRANCH, ELSE_BRANCH; } 025 026 String condition; 027 BranchState branchState = null; 028 029 @Override 030 protected IfModel makeNewInstance() { 031 return new IfModel(); 032 } 033 034 @Override 035 protected void mirror(Model that) { 036 IfModel actual = (IfModel) that; 037 super.mirror(actual); 038 this.condition = actual.condition; 039 this.branchState = actual.branchState; 040 } 041 042 public String getCondition() { 043 return condition; 044 } 045 046 public void setCondition(String condition) { 047 this.condition = condition; 048 } 049 050 public BranchState getBranchState() { 051 return branchState; 052 } 053 054 public void setBranchState(BranchState state) { 055 this.branchState = state; 056 } 057 058 059 public void setBranchState(boolean booleanProxy) { 060 if(booleanProxy) 061 setBranchState(BranchState.IF_BRANCH); 062 else 063 setBranchState(BranchState.ELSE_BRANCH); 064 } 065 066 public void resetBranchState() { 067 setBranchState(null); 068 } 069 070 @Override 071 public String toString() { 072 return this.getClass().getSimpleName() + " [condition=\""+condition+"\"]"; 073 } 074 075 @Override 076 public int hashCode() { 077 final int prime = 31; 078 int result = super.hashCode(); 079 result = prime * result + Objects.hash(branchState, condition); 080 return result; 081 } 082 083 @Override 084 public boolean equals(Object obj) { 085 if (this == obj) 086 return true; 087 if (!super.equals(obj)) 088 return false; 089 if (getClass() != obj.getClass()) 090 return false; 091 IfModel other = (IfModel) obj; 092 return branchState == other.branchState && Objects.equals(condition, other.condition); 093 } 094 095 096}