001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/portal/standard/csw/model/ShoppingCart.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 ---------------------------------------------------------------------------*/ 043 044 package org.deegree.portal.standard.csw.model; 045 046 import java.util.ArrayList; 047 import java.util.List; 048 049 /** 050 * A <code>${type_name}</code> class.<br/> TODO class description 051 * 052 * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a> 053 * @author last edited by: $Author: apoth $ 054 * 055 * @version $Revision: 9346 $, $Date: 2007-12-27 17:39:07 +0100 (Do, 27 Dez 2007) $ 056 */ 057 public class ShoppingCart { 058 059 /** 060 * A List of SessionRecord elements. 061 */ 062 private List<SessionRecord> contents; 063 064 /** 065 * 066 * 067 */ 068 public ShoppingCart() { 069 this.contents = new ArrayList<SessionRecord>( 10 ); 070 } 071 072 /** 073 * @param contents 074 * A List of SessionRecord elements. 075 */ 076 public ShoppingCart( List contents ) { 077 this(); 078 setContents( contents ); 079 } 080 081 /** 082 * @param sr 083 * A SessionRecord to add to the ShoppingCart contents. Cannot be null. 084 */ 085 public void add( SessionRecord sr ) { 086 if ( sr == null ) { 087 throw new NullPointerException( "Session record cannot be null" ); 088 } 089 if ( !this.contents.contains( sr ) ) { 090 this.contents.add( sr ); 091 } 092 } 093 094 /** 095 * @param sr 096 */ 097 public void remove( SessionRecord sr ) { 098 this.contents.remove( sr ); 099 } 100 101 /** 102 * @param sessionRecords 103 */ 104 public void removeAll( List sessionRecords ) { 105 this.contents.removeAll( sessionRecords ); 106 } 107 108 /** 109 * 110 */ 111 public void clear() { 112 this.contents.clear(); 113 } 114 115 /** 116 * @return Returns the contents of the ShoppingCart. 117 */ 118 public List getContents() { 119 return contents; 120 } 121 122 /** 123 * @param contents 124 * The contents to set. 125 * @throws RuntimeException 126 * if the passed List contains elements other than SessionRecord. 127 */ 128 public void setContents( List contents ) { 129 130 for ( int i = 0; i < contents.size(); i++ ) { 131 if ( contents.get( i ) instanceof SessionRecord ) { 132 add( (SessionRecord) contents.get( i ) ); 133 } else { 134 throw new RuntimeException( "The list passed to the constructor contains elements " 135 + "that are not of the type SessionRecord." ); 136 } 137 } 138 139 } 140 141 }