View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2011 Michael Mimo Moratti.
3    *
4    * Michael Mimo Moratti licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at:
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
11   * License for the specific language governing permissions and limitations
12   * under the License.
13   *******************************************************************************/
14  package ch.mimo.netty.handler.codec.icap;
15  
16  /**
17   * Return value encapsulation used in all message decoder states.
18   * 
19   * @author Michael Mimo Moratti (mimo@mimo.ch)
20   *
21   * @see IcapMessageDecoder
22   * @see State
23   */
24  public class StateReturnValue {
25  	
26  	private boolean relevance;
27  	private Object value;
28  	private Object decisionInformation;
29  	
30  	public StateReturnValue(boolean relevance, Object value, Object decisionInformation) {
31  		this.relevance = relevance;
32  		this.value = value;
33  		this.decisionInformation = decisionInformation;
34  	}
35  	
36  	public static StateReturnValue createIrrelevantResult() {
37  		return new StateReturnValue(false,null,null);
38  	}
39  	
40  	public static StateReturnValue createIrrelevantResultWithDecisionInformation(Object decisionInformation) {
41  		return new StateReturnValue(false,null,decisionInformation);
42  	}
43  	
44  	public static StateReturnValue createRelevantResult(Object result) {
45  		return new StateReturnValue(true,result,null);
46  	}
47  	
48  	public static StateReturnValue createRelevantResultWithDecisionInformation(Object result, Object decisionInformation) {
49  		return new StateReturnValue(true,result,decisionInformation);
50  	}
51  	
52  	public boolean isRelevant() {
53  		return relevance;
54  	}
55  	
56  	public Object getValue() {
57  		return value;
58  	}
59  	
60  	public Object getDecisionInformation() {
61  		return decisionInformation;
62  	}
63  	
64  	public String toString() {
65  		String printValue = "null";
66  		if(value != null) {
67  			printValue = value.getClass().getCanonicalName();
68  		}
69  		return "StateReturnValue: [relevance=" + relevance + 
70  				"] [value=" + printValue + "] [decision information=" + decisionInformation + "]";
71  	}
72  }