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.types;
020
021import org.apache.reef.tang.types.ConstructorArg;
022
023public class ConstructorArgImpl implements ConstructorArg {
024  private final String type;
025  private final String name;
026  private final boolean isInjectionFuture;
027
028  public ConstructorArgImpl(final String type, final String namedParameterName, final boolean isInjectionFuture) {
029    this.type = type;
030    this.name = namedParameterName;
031    this.isInjectionFuture = isInjectionFuture;
032  }
033
034  @Override
035  public String getName() {
036    return name == null ? type : name;
037  }
038
039  @Override
040  public String getNamedParameterName() {
041    return name;
042  }
043
044  @Override
045  public String getType() {
046    return type;
047  }
048
049  @Override
050  public String toString() {
051    return name == null ? type : type + " " + name;
052  }
053
054  @Override
055  public boolean equals(final Object o) {
056    if (this == o) {
057      return true;
058    }
059    if (o == null || getClass() != o.getClass()) {
060      return false;
061    }
062    final ConstructorArgImpl arg = (ConstructorArgImpl) o;
063    if (!type.equals(arg.type)) {
064      return false;
065    }
066    if (name == null && arg.name == null) {
067      return true;
068    }
069    if (name == null || arg.name == null) {
070      return false;
071    }
072    return name.equals(arg.name);
073
074  }
075
076  @Override
077  public int hashCode() {
078    int result = type.hashCode();
079    result = 31 * result + (name != null ? name.hashCode() : 0);
080    return result;
081  }
082
083  @Override
084  public boolean isInjectionFuture() {
085    return isInjectionFuture;
086  }
087}