001/* $Id: Catalog.java 1102402 2011-05-12 18:03:26Z simonetripodi $ 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.commons.digester3.annotations.catalog; 019 020import java.util.ArrayList; 021import java.util.List; 022 023import org.apache.commons.digester3.annotations.rules.ObjectCreate; 024import org.apache.commons.digester3.annotations.rules.SetNext; 025 026/** 027 * @since 2.1 028 */ 029@ObjectCreate.List( @ObjectCreate( pattern = "catalog" ) ) 030public final class Catalog 031{ 032 033 private final List<Item> items = new ArrayList<Item>(); 034 035 @SetNext( { AudioVisual.class, Book.class } ) 036 public void addItem( Item item ) 037 { 038 this.items.add( item ); 039 } 040 041 public List<Item> getItems() 042 { 043 return this.items; 044 } 045 046 @Override 047 public boolean equals( Object obj ) 048 { 049 if ( this == obj ) 050 return true; 051 if ( obj == null ) 052 return false; 053 if ( getClass() != obj.getClass() ) 054 return false; 055 Catalog other = (Catalog) obj; 056 if ( this.items == null ) 057 { 058 if ( other.getItems() != null ) 059 return false; 060 } 061 else if ( !this.items.equals( other.getItems() ) ) 062 return false; 063 return true; 064 } 065 066 @Override 067 public String toString() 068 { 069 return "Catalog [items=" + items + "]"; 070 } 071 072 public void print() 073 { 074 System.out.println( "This catalog has " + this.items.size() + " items" ); 075 076 for ( Item item : this.items ) 077 { 078 item.print(); 079 } 080 } 081 082}