< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/classfile/Attributes.java

Print this page




  52             try {
  53                 map.put(attr.getName(cr.getConstantPool()), attr);
  54             } catch (ConstantPoolException e) {
  55                 // don't enter invalid names in map
  56             }
  57         }
  58     }
  59 
  60     public Attributes(ConstantPool constant_pool, Attribute[] attrs) {
  61         this.attrs = attrs;
  62         map = new HashMap<>();
  63         for (Attribute attr : attrs) {
  64             try {
  65                 map.put(attr.getName(constant_pool), attr);
  66             } catch (ConstantPoolException e) {
  67                 // don't enter invalid names in map
  68             }
  69         }
  70     }
  71 





  72     public Iterator<Attribute> iterator() {
  73         return Arrays.asList(attrs).iterator();
  74     }
  75 
  76     public Attribute get(int index) {
  77         return attrs[index];
  78     }
  79 
  80     public Attribute get(String name) {
  81         return map.get(name);
  82     }
  83 
  84     public int getIndex(ConstantPool constant_pool, String name) {
  85         for (int i = 0; i < attrs.length; i++) {
  86             Attribute attr = attrs[i];
  87             try {
  88                 if (attr != null && attr.getName(constant_pool).equals(name))
  89                     return i;
  90             } catch (ConstantPoolException e) {
  91                 // ignore invalid entries


  52             try {
  53                 map.put(attr.getName(cr.getConstantPool()), attr);
  54             } catch (ConstantPoolException e) {
  55                 // don't enter invalid names in map
  56             }
  57         }
  58     }
  59 
  60     public Attributes(ConstantPool constant_pool, Attribute[] attrs) {
  61         this.attrs = attrs;
  62         map = new HashMap<>();
  63         for (Attribute attr : attrs) {
  64             try {
  65                 map.put(attr.getName(constant_pool), attr);
  66             } catch (ConstantPoolException e) {
  67                 // don't enter invalid names in map
  68             }
  69         }
  70     }
  71 
  72     public Attributes(Map<String, Attribute> attributes) {
  73         this.attrs = attributes.values().toArray(new Attribute[attributes.size()]);
  74         map = attributes;
  75     }
  76 
  77     public Iterator<Attribute> iterator() {
  78         return Arrays.asList(attrs).iterator();
  79     }
  80 
  81     public Attribute get(int index) {
  82         return attrs[index];
  83     }
  84 
  85     public Attribute get(String name) {
  86         return map.get(name);
  87     }
  88 
  89     public int getIndex(ConstantPool constant_pool, String name) {
  90         for (int i = 0; i < attrs.length; i++) {
  91             Attribute attr = attrs[i];
  92             try {
  93                 if (attr != null && attr.getName(constant_pool).equals(name))
  94                     return i;
  95             } catch (ConstantPoolException e) {
  96                 // ignore invalid entries
< prev index next >