1 9 package com.vladium.jcd.cls; 10 11 import java.io.IOException ; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 import com.vladium.jcd.lib.UDataOutputStream; 16 import com.vladium.util.IntVector; 17 18 22 final class FieldCollection implements IFieldCollection 23 { 24 26 28 public Field_info get (final int offset) 29 { 30 return (Field_info) m_fields.get (offset); 31 } 32 33 public int [] get (final ClassDef cls, final String name) 34 { 35 if (cls == null) throw new IllegalArgumentException ("null input: cls"); 36 37 39 final int count = m_fields.size (); final IntVector result = new IntVector (count); 41 42 for (int f = 0; f < count; ++ f) 43 { 44 final Field_info field = (Field_info) m_fields.get (f); 45 46 if (field.getName (cls).equals (name)) 47 result.add (f); 48 } 49 50 return result.values (); } 52 53 public int size () 54 { 55 return m_fields.size (); 56 } 57 58 60 63 public Object clone () 64 { 65 try 66 { 67 final FieldCollection _clone = (FieldCollection) super.clone (); 68 69 final int fields_count = m_fields.size (); _clone.m_fields = new ArrayList (fields_count); 72 for (int f = 0; f < fields_count; ++ f) 73 { 74 _clone.m_fields.add (((Field_info) m_fields.get (f)).clone ()); 75 } 76 77 return _clone; 78 } 79 catch (CloneNotSupportedException e) 80 { 81 throw new InternalError (e.toString ()); 82 } 83 } 84 85 87 public void writeInClassFormat (final UDataOutputStream out) throws IOException 88 { 89 final int fields_count = m_fields.size (); out.writeU2 (fields_count); 91 92 for (int i = 0; i < fields_count; i++) 93 { 94 get (i).writeInClassFormat (out); 95 } 96 } 97 98 100 public void accept (final IClassDefVisitor visitor, final Object ctx) 101 { 102 visitor.visit (this, ctx); 103 } 104 105 106 108 public int add (final Field_info field) 109 { 110 final int newoffset = m_fields.size (); m_fields.add (field); 112 113 return newoffset; 114 } 115 116 public Field_info set (final int offset, final Field_info field) 117 { 118 return (Field_info) m_fields.set (offset, field); 119 } 120 121 123 125 126 FieldCollection (final int capacity) 127 { 128 m_fields = capacity < 0 ? new ArrayList () : new ArrayList (capacity); 129 } 130 131 133 134 private List m_fields; 136 } | Popular Tags |