List of usage examples for com.google.common.collect ClassToInstanceMap containsKey
boolean containsKey(Object key);
From source file:com.google.errorprone.refaster.PlaceholderMethod.java
static PlaceholderMethod create(CharSequence name, UType returnType, ImmutableMap<UVariableDecl, ImmutableClassToInstanceMap<Annotation>> parameters, ClassToInstanceMap<Annotation> annotations) { final boolean allowsIdentity = annotations.getInstance(Placeholder.class).allowsIdentity(); final Class<? extends Matcher<? super ExpressionTree>> matchesClass = annotations.containsKey(Matches.class) ? UTemplater.getValue(annotations.getInstance(Matches.class)) : null;/*ww w. j av a 2 s. co m*/ final Class<? extends Matcher<? super ExpressionTree>> notMatchesClass = annotations.containsKey( NotMatches.class) ? UTemplater.getValue(annotations.getInstance(NotMatches.class)) : null; final Predicate<Tree.Kind> allowedKinds = annotations.containsKey(OfKind.class) ? Predicates.<Tree.Kind>in(Arrays.asList(annotations.getInstance(OfKind.class).value())) : Predicates.<Tree.Kind>alwaysTrue(); class PlaceholderMatcher implements Serializable, Matcher<ExpressionTree> { @Override public boolean matches(ExpressionTree t, VisitorState state) { try { return (allowsIdentity || !(t instanceof PlaceholderParamIdent)) && (matchesClass == null || matchesClass.newInstance().matches(t, state)) && (notMatchesClass == null || !notMatchesClass.newInstance().matches(t, state)) && allowedKinds.apply(t.getKind()); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } } return new AutoValue_PlaceholderMethod(StringName.of(name), returnType, parameters, new PlaceholderMatcher(), ImmutableClassToInstanceMap.<Annotation, Annotation>copyOf(annotations)); }
From source file:neon.client.ui.DescriptionLabel.java
/** * Updates the description of a creature. * /* w ww . ja v a 2 s .com*/ * @param components all the components that make a creature */ public void updateCreature(ClassToInstanceMap<Component> components) { if (components.containsKey(Graphics.class)) { // create the image like it would show in-game Graphics graphics = components.getInstance(Graphics.class); Image image = TextureFactory.getImage(fontSize, graphics.getColor(), graphics.getGlyph()); setGraphic(new ImageView(image)); } else { setGraphic(null); } StringBuilder builder = new StringBuilder(); if (components.containsKey(CreatureInfo.class)) { CreatureInfo info = components.getInstance(CreatureInfo.class); builder.append(info.getName()); builder.append("\n"); } setText(builder.toString()); }
From source file:neon.client.ui.DescriptionLabel.java
/** * Updates the description of an item./*w w w .java 2 s.com*/ * * @param components all the components that make an item */ public void updateItem(ClassToInstanceMap<Component> components) { if (components.containsKey(Graphics.class)) { // create the image like it would show in-game on the ground Graphics graphics = components.getInstance(Graphics.class); Image image = TextureFactory.getImage(fontSize, graphics.getColor(), graphics.getGlyph()); setGraphic(new ImageView(image)); } else { setGraphic(null); } StringBuilder builder = new StringBuilder(); if (components.containsKey(ItemInfo.class)) { ItemInfo info = components.getInstance(ItemInfo.class); builder.append(info.name); builder.append("\n"); builder.append("Weight: " + (float) info.weight / 100 + " stone"); builder.append("\n"); builder.append("Price: " + info.price + " cp"); builder.append("\n"); } if (components.containsKey(Clothing.class)) { Clothing clothing = components.getInstance(Clothing.class); builder.append("\n"); builder.append("Slot: " + clothing.getSlot().toString().toLowerCase()); builder.append("\n"); } if (components.containsKey(Armor.class)) { Armor armor = components.getInstance(Armor.class); builder.append("Type: " + armor.getType().toString().toLowerCase()); builder.append("\n"); builder.append("Rating: " + armor.getRating()); builder.append("\n"); } if (components.containsKey(Weapon.class)) { Weapon weapon = components.getInstance(Weapon.class); builder.append("\n"); builder.append("Damage: " + weapon.getDamage()); builder.append("\n"); } if (components.containsKey(Enchantment.class)) { Enchantment enchantment = components.getInstance(Enchantment.class); builder.append("\n"); builder.append("Effect: " + enchantment.getEffect()); builder.append("\n"); builder.append("Magnitude: " + enchantment.getMagnitude()); builder.append("\n"); } setText(builder.toString()); }