001 /* 002 * Copyright 2001-2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.apache.commons.cache.adt; 017 018 /** 019 * A simple {@link Listable} supporting singly-linked 020 * lists of arbitrary {@link Object}s. 021 * 022 * @version $Id: ListableObject.java 155435 2005-02-26 13:17:27Z dirkv $ 023 * @author Rodney Waldhoff 024 */ 025 public class ListableObject extends ListableBase implements Listable, Cloneable { 026 /** 027 * Equivalent to {@link #ListableObject(java.lang.Object,Listable) <tt>ListableObject(val,null)</tt>}. 028 */ 029 public ListableObject(Object val) { 030 this(val,null); 031 } 032 033 /** 034 * @param val my value 035 * @param next the next Listable. 036 */ 037 public ListableObject(Object val, Listable next) { 038 super(next); 039 _val = val; 040 } 041 042 /** My value. */ 043 protected Object _val = null; 044 045 /** 046 * Return the {@link Object} I'm wrapping. 047 * @return the {@link Object} I'm wrapping. 048 */ 049 public Object getValue() { 050 return _val; 051 } 052 053 /** 054 * Set the {@link Object} I'm wrapping. 055 * @param the {@link Object} to wrap. 056 */ 057 public void setValue(Object obj) { 058 _val = obj; 059 } 060 061 /* 062 private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { 063 out.defaultWriteObject(); 064 ListableObject cur = _next; 065 while(cur != null) { 066 out.writeObject(cur.getValue()); 067 cur = cur.getNext(); 068 } 069 out.writeObject(null); 070 } 071 072 private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { 073 in.defaultReadObject(); 074 Listable current = this; 075 for(;;) { 076 Object obj = in.readObject(); 077 if(null == obj) { 078 break; 079 } else if(obj instanceof Listable) { 080 try { 081 current.setNext((Listable)obj); 082 } catch(UnsupportedOperationException e) { 083 // ignored 084 } 085 try { 086 ((Listable)obj).setPrev(current); 087 } catch(UnsupportedOperationException e) { 088 // ignored 089 } 090 current = (Listable)obj; 091 } else { 092 throw new java.io.IOException("Unexpected object while deserializing ListableBase: " + obj.getClass().getName()); 093 } 094 } 095 } 096 */ 097 098 }