1 8 package org.codehaus.loom.components.util.info; 9 10 28 public final class DependencyDescriptor 29 { 30 31 public static final DependencyDescriptor[] EMPTY_SET = new DependencyDescriptor[ 0 ]; 32 33 34 public static final String ARRAY_POSTFIX = "[]"; 35 36 37 public static final String MAP_POSTFIX = "{}"; 38 39 40 private final String m_key; 41 42 43 private final String m_type; 44 45 46 private final boolean m_optional; 47 48 51 public DependencyDescriptor( final String key, 52 final String type, 53 final boolean optional ) 54 { 55 if( null == key ) 56 { 57 throw new NullPointerException ( "key" ); 58 } 59 if( null == type ) 60 { 61 throw new NullPointerException ( "type" ); 62 } 63 64 m_key = key; 65 m_type = type; 66 m_optional = optional; 67 } 68 69 74 public String getKey() 75 { 76 return m_key; 77 } 78 79 86 public String getType() 87 { 88 return m_type; 89 } 90 91 96 public boolean isOptional() 97 { 98 return m_optional; 99 } 100 101 106 public boolean isArray() 107 { 108 return getType().endsWith( ARRAY_POSTFIX ); 109 } 110 111 116 public boolean isMap() 117 { 118 return getType().endsWith( MAP_POSTFIX ); 119 } 120 121 127 public String getComponentType() 128 { 129 final String fullname = getType(); 130 if( isArray() ) 131 { 132 final int end = fullname.length() - ARRAY_POSTFIX.length(); 133 return fullname.substring( 0, end ); 134 } 135 else if( isMap() ) 136 { 137 final int end = fullname.length() - MAP_POSTFIX.length(); 138 return fullname.substring( 0, end ); 139 } 140 else 141 { 142 return fullname; 143 } 144 } 145 146 151 public String toString() 152 { 153 final StringBuffer sb = new StringBuffer (); 154 sb.append( m_key ); 155 sb.append( '/' ); 156 sb.append( m_type ); 157 if( m_optional ) 158 { 159 sb.append( "(Optional)" ); 160 } 161 return sb.toString(); 162 } 163 } 164 | Popular Tags |