Example usage for com.google.common.collect ClassToInstanceMap getInstance

List of usage examples for com.google.common.collect ClassToInstanceMap getInstance

Introduction

In this page you can find the example usage for com.google.common.collect ClassToInstanceMap getInstance.

Prototype

<T extends B> T getInstance(Class<T> type);

Source Link

Document

Returns the value the specified class is mapped to, or null if no entry for this class is present.

Usage

From source file:org.immutables.generator.StaticEnvironment.java

static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) {
    ClassToInstanceMap<Completable> components = state().components;
    @Nullable/*w ww  . j  a  v a  2 s  .co  m*/
    T instance = components.getInstance(type);
    if (instance == null) {
        instance = supplier.get();
        components.putInstance(type, instance);
    }
    return instance;
}

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  2s.  c o  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:com.linecorp.armeria.client.thrift.THttpClientFactoryProvider.java

@Override
public ClientFactory newFactory(SessionOptions options, ClassToInstanceMap<ClientFactory> dependencies) {
    return new THttpClientFactory(dependencies.getInstance(HttpClientFactory.class));
}

From source file:see.evaluation.evaluators.LazyContextEvaluator.java

@Override
public <T> T evaluate(Node<T> tree, Context context) {
    ClassToInstanceMap<Object> services = context.getServices();
    ValueProcessor valueProcessor = services.getInstance(ValueProcessor.class);
    ChainResolver chainResolver = services.getInstance(ChainResolver.class);

    Context actualContext = addService(context, ContextEvaluator.class, this);

    return tree.accept(new LazyVisitor(actualContext, valueProcessor, chainResolver));
}

From source file:neon.client.ui.DescriptionLabel.java

/**
 * Updates the description of a creature.
 * // w ww  . j a  v  a2s. co m
 * @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./*from  w  w  w  . j  av  a  2s .  c  o  m*/
 * 
 * @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());
}

From source file:org.opendaylight.didm.mininet.DidmMininetProviderImpl.java

/***
  * Registers all drivers for a devicetype
  * @param deviceType The devicetype//  w  w  w. j a  v  a2s  . c o  m
  * @param path The node the drivers apply to
  * @return List of successful routed RPC registrations
  */
private List<BindingAwareBroker.RoutedRpcRegistration<RpcService>> registerDrivers(String deviceType,
        InstanceIdentifier<Node> path) {
    LOG.info("onNodeIdentified!");

    List<BindingAwareBroker.RoutedRpcRegistration<RpcService>> list = new ArrayList<>();

    // get all the drivers to be registered as routed RPCs
    ClassToInstanceMap<RpcService> map = getDrivers(deviceType);

    Set<Class<? extends RpcService>> driverTypes = map.keySet();

    for (Class<? extends RpcService> clazz : driverTypes) {
        BindingAwareBroker.RoutedRpcRegistration<RpcService> registration = registerRpcService(clazz,
                map.getInstance(clazz), path);
        if (registration != null) {
            list.add(registration);
        } else {
            // TODO: do we need a onRegistrationFailed() extension?
        }
    }
    return list;
}