This project has retired. For details please refer to its Attic page.
Source code
001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.tang.implementation.java;
020
021import org.apache.reef.tang.implementation.InjectionPlan;
022import org.apache.reef.tang.types.Node;
023
024final public class JavaInstance<T> extends InjectionPlan<T> {
025  final T instance;
026
027  public JavaInstance(Node name, T instance) {
028    super(name);
029    this.instance = instance;
030  }
031
032  @Override
033  public int getNumAlternatives() {
034    return instance == null ? 0 : 1;
035  }
036
037  @Override
038  public String toString() {
039    return getNode() + " = " + instance;
040  }
041
042  @Override
043  public boolean isAmbiguous() {
044    return false;
045  }
046
047  @Override
048  public boolean isInjectable() {
049    return instance != null;
050  }
051
052  public String getInstanceAsString() {
053    return instance.toString();
054  }
055
056  @Override
057  protected String toAmbiguousInjectString() {
058    throw new IllegalArgumentException("toAmbiguousInjectString called on JavaInstance!" + this.toString());
059  }
060
061  @Override
062  protected String toInfeasibleInjectString() {
063    return getNode() + " is not bound.";
064  }
065
066  @Override
067  protected boolean isInfeasibleLeaf() {
068    return true;
069  }
070
071  @Override
072  public String toShallowString() {
073    return toString();
074  }
075}