Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ListableObject |
|
| 1.0;1 |
1 | /* | |
2 | * Copyright 2001-2004 The Apache Software Foundation | |
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.apache.commons.cache.adt; | |
17 | ||
18 | /** | |
19 | * A simple {@link Listable} supporting singly-linked | |
20 | * lists of arbitrary {@link Object}s. | |
21 | * | |
22 | * @version $Id: ListableObject.java 155435 2005-02-26 13:17:27Z dirkv $ | |
23 | * @author Rodney Waldhoff | |
24 | */ | |
25 | public class ListableObject extends ListableBase implements Listable, Cloneable { | |
26 | /** | |
27 | * Equivalent to {@link #ListableObject(java.lang.Object,Listable) <tt>ListableObject(val,null)</tt>}. | |
28 | */ | |
29 | public ListableObject(Object val) { | |
30 | 0 | this(val,null); |
31 | 0 | } |
32 | ||
33 | /** | |
34 | * @param val my value | |
35 | * @param next the next Listable. | |
36 | */ | |
37 | public ListableObject(Object val, Listable next) { | |
38 | 0 | super(next); |
39 | 0 | _val = val; |
40 | 0 | } |
41 | ||
42 | /** My value. */ | |
43 | 0 | protected Object _val = null; |
44 | ||
45 | /** | |
46 | * Return the {@link Object} I'm wrapping. | |
47 | * @return the {@link Object} I'm wrapping. | |
48 | */ | |
49 | public Object getValue() { | |
50 | 0 | return _val; |
51 | } | |
52 | ||
53 | /** | |
54 | * Set the {@link Object} I'm wrapping. | |
55 | * @param the {@link Object} to wrap. | |
56 | */ | |
57 | public void setValue(Object obj) { | |
58 | 0 | _val = obj; |
59 | 0 | } |
60 | ||
61 | /* | |
62 | private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { | |
63 | out.defaultWriteObject(); | |
64 | ListableObject cur = _next; | |
65 | while(cur != null) { | |
66 | out.writeObject(cur.getValue()); | |
67 | cur = cur.getNext(); | |
68 | } | |
69 | out.writeObject(null); | |
70 | } | |
71 | ||
72 | private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { | |
73 | in.defaultReadObject(); | |
74 | Listable current = this; | |
75 | for(;;) { | |
76 | Object obj = in.readObject(); | |
77 | if(null == obj) { | |
78 | break; | |
79 | } else if(obj instanceof Listable) { | |
80 | try { | |
81 | current.setNext((Listable)obj); | |
82 | } catch(UnsupportedOperationException e) { | |
83 | // ignored | |
84 | } | |
85 | try { | |
86 | ((Listable)obj).setPrev(current); | |
87 | } catch(UnsupportedOperationException e) { | |
88 | // ignored | |
89 | } | |
90 | current = (Listable)obj; | |
91 | } else { | |
92 | throw new java.io.IOException("Unexpected object while deserializing ListableBase: " + obj.getClass().getName()); | |
93 | } | |
94 | } | |
95 | } | |
96 | */ | |
97 | ||
98 | } |