1 package org.robolectric.res; 2 3 import java.util.List; 4 5 public class AttrData { 6 private final String name; 7 private final String format; 8 private final List<Pair> pairs; 9 AttrData(String name, String format, List<Pair> pairs)10 public AttrData(String name, String format, List<Pair> pairs) { 11 this.name = name; 12 this.format = format; 13 this.pairs = pairs; 14 } 15 getFormat()16 public String getFormat() { 17 return format; 18 } 19 getName()20 public String getName() { 21 return name; 22 } 23 getValueFor(String key)24 public String getValueFor(String key) { 25 if (pairs == null) return null; 26 for (Pair pair : pairs) { 27 if (pair.name.equals(key)) { 28 return pair.value; 29 } 30 } 31 return null; 32 } 33 isValue(String value)34 public boolean isValue(String value) { 35 if (pairs == null) { 36 return false; 37 } else { 38 for (Pair pair : pairs) { 39 if (pair.value.equals(value)) { 40 return true; 41 } 42 } 43 } 44 return false; 45 } 46 toString()47 @Override public String toString() { 48 StringBuilder builder = new StringBuilder("AttrData{name='") 49 .append(name) 50 .append("', format='") 51 .append(format) 52 .append('\''); 53 if (pairs != null) { 54 for (Pair p : pairs) { 55 builder.append(' ') 56 .append(p.name) 57 .append("='") 58 .append(p.value) 59 .append('\''); 60 } 61 } 62 builder.append('}'); 63 return builder.toString(); 64 } 65 66 public static class Pair { 67 private final String name; 68 private final String value; 69 Pair(String name, String value)70 public Pair(String name, String value) { 71 this.name = name; 72 this.value = value; 73 } 74 } 75 } 76