📄 storeditemcollection.java
字号:
/* * @(#)$Id: StoredItemCollection.java,v 1.7 2004/07/02 23:59:20 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704. Attention: Intel License Inquiry. */package overlay.provider.basic;import java.util.ArrayList;import java.util.Iterator;import services.network.Payload;import util.network.serialization.GenericByteBuffer;import util.network.serialization.SerializationManager;import util.network.serialization.SerializeList;/** * Class StoredItemCollection * */public class StoredItemCollection implements Payload { public static long serialVersionUID = SerializationManager.getSerialUID( "overlay.provider.basic.StoredItemCollection"); private ArrayList items; private int size; /** * DeSerialize the object from the provided GenericByteBuffer. * * @param inputBuffer */ public StoredItemCollection(GenericByteBuffer inputBuffer) { this.items = SerializeList.deSerializeHomogenousArrayList(inputBuffer); Iterator theItems = iterator(); this.size = 0; while (theItems.hasNext()) { this.size += SerializationManager.getPayloadSize( ((StoredItem) theItems.next())); } } /** * Serialize the object into the provided GenericByteBuffer. * * @param outputBuffer * @return */ public long serialize(GenericByteBuffer outputBuffer) { SerializeList.serializeHomogenous(outputBuffer, items); return serialVersionUID; } /** Default Constructor, creates an empty collection */ public StoredItemCollection() { items = new ArrayList(); size = 0; } /** * Appends another item to this collection * @param item the item to be appended */ public void addItem(StoredItem item) { size += SerializationManager.getPayloadSize(item); items.add(item); } /** * Appends another collection to this collection * @param collection the collection to be appended */ public void addCollection(StoredItemCollection collection) { for (int i = 0; i < collection.size(); i++) { addItem(collection.getItem(i)); } } /** * Retrieve stored items from collection * @param index the index of the iteme requested * @return the requested item from the collection */ public StoredItem getItem(int index) { return (StoredItem) items.get(index); } /** * Method iterator * @return */ public Iterator iterator() { return items.iterator(); } /** * Retrieve objects embedded in stored items from collection * @return the requested item from the collection */ public Iterator objectIterator() { return new StoredItemIterator(items.iterator()); } /** * Determine the number of items stored in this collection * @return number of items in the collection */ public int size() { return items.size(); } /** * Sums the size of the items in the collection (calls getSize for each item) * @return size in bytes of the collection */ public int getSize() { return size; } /** * Outputs name and value * @return a text string with all the tuples in the collection */ public String toString() { return "<StoredItemCollection: " + items + ">"; }}/** * Class StoredItemIterator * */class StoredItemIterator implements Iterator { private Iterator collectionIterator; /** * Constructor StoredItemIterator * * @param collectionIterator */ protected StoredItemIterator(Iterator collectionIterator) { this.collectionIterator = collectionIterator; } /** * Method hasNext * @return */ public boolean hasNext() { return collectionIterator.hasNext(); } /** * Method next * @return */ public Object next() { return ((StoredItem) collectionIterator.next()).object; } /** * Method remove */ public void remove() { throw new UnsupportedOperationException(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -