| 1 |
package org.apache.qpid.proton.engine.impl; |
| 2 |
/* |
| 3 |
* |
| 4 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 5 |
* or more contributor license agreements. See the NOTICE file |
| 6 |
* distributed with this work for additional information |
| 7 |
* regarding copyright ownership. The ASF licenses this file |
| 8 |
* to you under the Apache License, Version 2.0 (the |
| 9 |
* "License"); you may not use this file except in compliance |
| 10 |
* with the License. You may obtain a copy of the License at |
| 11 |
* |
| 12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
* |
| 14 |
* Unless required by applicable law or agreed to in writing, |
| 15 |
* software distributed under the License is distributed on an |
| 16 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 |
* KIND, either express or implied. See the License for the |
| 18 |
* specific language governing permissions and limitations |
| 19 |
* under the License. |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
|
| 24 |
class LinkNode<E> |
| 25 |
{ |
| 26 |
public interface Query<T> |
| 27 |
{ |
| 28 |
public boolean matches(LinkNode<T> node); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
private E _value; |
| 33 |
private LinkNode<E> _prev; |
| 34 |
private LinkNode<E> _next; |
| 35 |
|
| 36 |
private LinkNode(E value) |
| 37 |
{ |
| 38 |
_value = value; |
| 39 |
} |
| 40 |
|
| 41 |
public E getValue() |
| 42 |
{ |
| 43 |
return _value; |
| 44 |
} |
| 45 |
|
| 46 |
public LinkNode<E> getPrev() |
| 47 |
{ |
| 48 |
return _prev; |
| 49 |
} |
| 50 |
|
| 51 |
public LinkNode<E> getNext() |
| 52 |
{ |
| 53 |
return _next; |
| 54 |
} |
| 55 |
|
| 56 |
public LinkNode<E> next(Query<E> query) |
| 57 |
{ |
| 58 |
LinkNode<E> next = _next; |
| 59 |
while(next != null && !query.matches(next)) |
| 60 |
{ |
| 61 |
next = next.getNext(); |
| 62 |
} |
| 63 |
return next; |
| 64 |
} |
| 65 |
|
| 66 |
public LinkNode<E> remove() |
| 67 |
{ |
| 68 |
LinkNode<E> prev = _prev; |
| 69 |
LinkNode<E> next = _next; |
| 70 |
if(prev != null) |
| 71 |
{ |
| 72 |
prev._next = next; |
| 73 |
} |
| 74 |
if(next != null) |
| 75 |
{ |
| 76 |
next._prev = prev; |
| 77 |
} |
| 78 |
_next = _prev = null; |
| 79 |
return next; |
| 80 |
} |
| 81 |
|
| 82 |
public LinkNode<E> addAtTail(E value) |
| 83 |
{ |
| 84 |
if(_next == null) |
| 85 |
{ |
| 86 |
_next = new LinkNode<E>(value); |
| 87 |
_next._prev = this; |
| 88 |
return _next; |
| 89 |
} |
| 90 |
else |
| 91 |
{ |
| 92 |
return _next.addAtTail(value); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
public static <T> LinkNode<T> newList(T value) |
| 97 |
{ |
| 98 |
return new LinkNode<T>(value); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
} |