1 17 18 package org.apache.avalon.logging.data; 19 20 import java.io.Serializable ; 21 22 23 30 public class CategoriesDirective extends CategoryDirective implements Serializable 31 { 32 35 private CategoryDirective[] m_categories; 36 37 40 public CategoriesDirective() 41 { 42 this( "" ); 43 } 44 45 50 public CategoriesDirective( final String name ) 51 { 52 this( name, null, null, new CategoryDirective[0] ); 53 } 54 55 60 public CategoriesDirective( CategoryDirective[] categories ) 61 { 62 this( "", null, null, categories ); 63 } 64 65 66 74 public CategoriesDirective( final String name, 75 final String priority, 76 final String target, 77 final CategoryDirective[] categories ) 78 { 79 super( name, priority, target ); 80 if( categories == null ) 81 { 82 m_categories = new CategoryDirective[ 0 ]; 83 } 84 else 85 { 86 m_categories = categories; 87 } 88 } 89 90 95 public CategoryDirective[] getCategories() 96 { 97 return m_categories; 98 } 99 100 106 public CategoryDirective getCategoryDirective( String name ) 107 { 108 for( int i = 0; i < m_categories.length; i++ ) 109 { 110 final CategoryDirective category = m_categories[ i ]; 111 if( category.getName().equalsIgnoreCase( name ) ) 112 { 113 return category; 114 } 115 } 116 return null; 117 } 118 119 125 public boolean equals( Object other ) 126 { 127 boolean isEqual = other instanceof CategoriesDirective; 128 if ( isEqual ) isEqual = super.equals( other ); 129 130 if ( isEqual ) 131 { 132 CategoriesDirective cat = (CategoriesDirective) other; 133 if ( isEqual ) isEqual = m_categories.length == cat.m_categories.length; 134 if ( isEqual ) 135 { 136 for ( int i = 0; i < m_categories.length && isEqual; i++ ) 137 { 138 isEqual = m_categories[i].equals( cat.m_categories[i] ); 139 } 140 } 141 } 142 return isEqual; 143 } 144 145 149 public int hashCode() 150 { 151 int hash = super.hashCode(); 152 for ( int i = 0; i < m_categories.length; i++ ) 153 { 154 hash >>>= 1; 155 hash ^= m_categories[i].hashCode(); 156 } 157 return hash; 158 } 159 160 161 } 162 | Popular Tags |