001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/site/tags/sakai_2-4-1/site-impl/impl/src/java/org/sakaiproject/site/impl/ResourceVector.java $
003: * $Id: ResourceVector.java 18633 2006-12-05 02:13:45Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.site.impl;
021:
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.Vector;
025:
026: /**
027: * <p>
028: * ResourceVector is a Vector of Identifiables....
029: * </p>
030: */
031: public class ResourceVector extends Vector {
032: /** A fixed class serian number. */
033: private static final long serialVersionUID = 1L;
034:
035: /**
036: * Constructor.
037: */
038: public ResourceVector(int initialCapacity, int capacityIncrement) {
039: super (initialCapacity, capacityIncrement);
040: }
041:
042: /**
043: * Constructor.
044: */
045: public ResourceVector(int initialCapacity) {
046: super (initialCapacity);
047: }
048:
049: /**
050: * Constructor.
051: */
052: public ResourceVector(Collection c) {
053: super (c);
054: }
055:
056: /**
057: * Constructor.
058: */
059: public ResourceVector() {
060: super ();
061: }
062:
063: /**
064: * Find the first item with this Resource id.
065: *
066: * @param id
067: * The resource id.
068: * @return the Resource that has this id, first in the list.
069: */
070: public Identifiable getById(String id) {
071: for (Iterator i = iterator(); i.hasNext();) {
072: Identifiable r = (Identifiable) i.next();
073: if (r.getId().equals(id))
074: return r;
075: }
076:
077: return null;
078: }
079:
080: /**
081: * Move an entry one up towards the start of the list.
082: *
083: * @param entry
084: * The resource to move.
085: */
086: public void moveUp(Identifiable entry) {
087: int pos = indexOf(entry);
088: if (pos == -1)
089: return;
090: if (pos == 0)
091: return;
092: remove(entry);
093: add(pos - 1, entry);
094: }
095:
096: /**
097: * Move an entry one down towards the end of the list.
098: *
099: * @param entry
100: * The resource to move.
101: */
102: public void moveDown(Identifiable entry) {
103: int pos = indexOf(entry);
104: if (pos == -1)
105: return;
106: if (pos == size() - 1)
107: return;
108: remove(entry);
109: add(pos + 1, entry);
110: }
111:
112: /**
113: * Move an entry to a specific (0 based) index.
114: *
115: * @param entry
116: * The resource to move.
117: */
118: public void moveTo(Identifiable entry, int newPos) {
119: remove(entry);
120: add(newPos, entry);
121: }
122: }
|