1 /* 2 * Copyright 2008 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.openehealth.ipf.platform.camel.core.process.splitter; 17 18 19 /** 20 * Immutable class specifying an index of a split performed by {@link Splitter}. 21 * This class contains all necessary information about the an index of an 22 * exchange that was split off. This includes the actual index as well as a 23 * flag indicating that the index is the last in the collection of sub exchanges. 24 * 25 * - Immutable 26 * - fully thread-safe 27 * - not for subclassing 28 * - uses static factory methods 29 * 30 * @author Jens Riemschneider 31 */ 32 public final class SplitIndex { 33 private final int index; 34 private final boolean last; 35 36 /** 37 * Static factory method to return a split index 38 * 39 * @param index 40 * actual Index of an exchange in the corresponding collection of 41 * sub exchanges 42 * @param last 43 * {@code true} if this index is the last in the corresponding 44 * collection of sub exchanges 45 * 46 * @return A {@link SplitIndex} corresponding to the index information 47 */ 48 public static SplitIndex valueOf(int index, boolean last) { 49 return new SplitIndex(index, last); 50 } 51 52 /** @return the index in the corresponding collection of sub exchanges 53 */ 54 public int getIndex() { 55 return index; 56 } 57 58 /** @return {@code true} if this index is the last in the corresponding 59 * collection of sub exchanges 60 */ 61 public boolean isLast() { 62 return last; 63 } 64 65 /* (non-Javadoc) 66 * @see java.lang.Object#hashCode() 67 */ 68 @Override 69 public int hashCode() { 70 final int prime = 31; 71 int result = 1; 72 result = prime * result + index; 73 result = prime * result + (last ? 1231 : 1237); 74 return result; 75 } 76 77 /* (non-Javadoc) 78 * @see java.lang.Object#equals(java.lang.Object) 79 */ 80 @Override 81 public boolean equals(Object obj) { 82 if (this == obj) 83 return true; 84 if (obj == null) 85 return false; 86 if (getClass() != obj.getClass()) 87 return false; 88 SplitIndex other = (SplitIndex) obj; 89 if (index != other.index) 90 return false; 91 return last == other.last; 92 } 93 94 /* (non-Javadoc) 95 * @see java.lang.Object#toString() 96 */ 97 @Override 98 public String toString() { 99 return "(" + Splitter.class.getName() + ": index=" + index + ", last=" + last + ")"; 100 } 101 102 // Please use factory methods instead of constructor {@link #valueOf} 103 private SplitIndex(int index, boolean last) { 104 this.index = index; 105 this.last = last; 106 } 107 }