01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.ws.rm;
19:
20: import java.math.BigInteger;
21:
22: import org.apache.cxf.ws.rm.SequenceAcknowledgement.AcknowledgementRange;
23:
24: public abstract class AbstractSequence {
25:
26: protected final Identifier id;
27: protected SequenceAcknowledgement acknowledgement;
28:
29: protected AbstractSequence(Identifier i) {
30: id = i;
31: }
32:
33: /**
34: * @return the sequence identifier
35: */
36: public Identifier getIdentifier() {
37: return id;
38: }
39:
40: public String toString() {
41: return id.getValue();
42: }
43:
44: public boolean equals(Object other) {
45: if (other == this ) {
46: return true;
47: }
48: if (other instanceof AbstractSequence) {
49: AbstractSequence otherSeq = (AbstractSequence) other;
50: return otherSeq.getIdentifier().getValue().equals(
51: getIdentifier().getValue());
52: }
53: return false;
54: }
55:
56: public int hashCode() {
57: return getIdentifier().getValue().hashCode();
58: }
59:
60: public static boolean identifierEquals(Identifier id1,
61: Identifier id2) {
62: if (null == id1) {
63: return null == id2;
64: } else {
65: return null != id2 && id1.getValue().equals(id2.getValue());
66: }
67: }
68:
69: public synchronized boolean isAcknowledged(BigInteger m) {
70: for (AcknowledgementRange r : acknowledgement
71: .getAcknowledgementRange()) {
72: if (m.subtract(r.getLower()).signum() >= 0
73: && r.getUpper().subtract(m).signum() >= 0) {
74: return true;
75: }
76: }
77: return false;
78: }
79:
80: }
|