KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > WrappingChain


1 /*
2   Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.core;
20
21 import org.aopalliance.intercept.Interceptor;
22 import org.objectweb.jac.util.ExtArrays;
23
24 public class WrappingChain {
25     public Interceptor[] chain;
26
27     public WrappingChain(Interceptor[] chain) {
28         this.chain = chain;
29     }
30     public WrappingChain() {
31         this.chain = ExtArrays.emptyInterceptorArray;
32     }
33     public void add(int rank,Interceptor interceptor) {
34         Interceptor[] newChain = new Interceptor[chain.length+1];
35         System.arraycopy(chain,0,newChain,0,rank);
36         System.arraycopy(chain,rank,newChain,rank+1,chain.length-rank);
37         newChain[rank] = interceptor;
38         chain = newChain;
39     }
40
41     protected void ensureCapacity(int n) {
42     }
43
44     public boolean contains(Interceptor interceptor) {
45         for (int i=chain.length-1; i>=0; i--) {
46             if (chain[i]==interceptor)
47                 return true;
48         }
49         return false;
50     }
51     public void remove(int rank) {
52         Interceptor[] newChain = new Interceptor[chain.length-1];
53         System.arraycopy(chain,0,newChain,0,rank);
54         System.arraycopy(chain,rank+1,newChain,rank,chain.length-rank-1);
55         chain = newChain;
56     }
57     public int size() {
58         return chain.length;
59     }
60     public Interceptor get(int i) {
61         return chain[i];
62     }
63     public String JavaDoc toString() {
64         String JavaDoc result = "[";
65         for (int i=0; i<chain.length;i++) {
66             if (i!=0) {
67                 result += ",";
68             }
69             result += chain[i].toString();
70         }
71       
72         result += "]";
73         return result;
74     }
75 }
76
Popular Tags