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; 020 021import org.apache.reef.tang.ClassHierarchy; 022import org.apache.reef.tang.Configuration; 023import org.apache.reef.tang.ConfigurationBuilder; 024import org.apache.reef.tang.ExternalConstructor; 025import org.apache.reef.tang.types.ClassNode; 026import org.apache.reef.tang.types.ConstructorDef; 027import org.apache.reef.tang.types.NamedParameterNode; 028 029import java.util.List; 030import java.util.Set; 031 032public class ConfigurationImpl implements Configuration { 033 private final ConfigurationBuilderImpl builder; 034 035 protected ConfigurationImpl(final ConfigurationBuilderImpl builder) { 036 this.builder = builder; 037 } 038 039 @Override 040 public String getNamedParameter(final NamedParameterNode<?> np) { 041 return builder.namedParameters.get(np); 042 } 043 044 @Override 045 @SuppressWarnings("unchecked") 046 public <T> ClassNode<ExternalConstructor<T>> getBoundConstructor( 047 final ClassNode<T> cn) { 048 return (ClassNode<ExternalConstructor<T>>) builder.boundConstructors.get(cn); 049 } 050 051 @Override 052 public Set<ClassNode<?>> getBoundImplementations() { 053 return builder.boundImpls.keySet(); 054 } 055 056 @Override 057 public Set<ClassNode<?>> getBoundConstructors() { 058 return builder.boundConstructors.keySet(); 059 } 060 061 @Override 062 public Set<NamedParameterNode<?>> getNamedParameters() { 063 return builder.namedParameters.keySet(); 064 } 065 066 @Override 067 public Set<ClassNode<?>> getLegacyConstructors() { 068 return builder.legacyConstructors.keySet(); 069 } 070 071 @Override 072 @SuppressWarnings("unchecked") 073 public <T> ClassNode<T> getBoundImplementation(final ClassNode<T> cn) { 074 return (ClassNode<T>) builder.boundImpls.get(cn); 075 } 076 077 @Override 078 @SuppressWarnings("unchecked") 079 public <T> ConstructorDef<T> getLegacyConstructor(final ClassNode<T> cn) { 080 return (ConstructorDef<T>) builder.legacyConstructors.get(cn); 081 } 082 083 @Override 084 public ConfigurationBuilder newBuilder() { 085 return builder.build().builder; 086 } 087 088 @Override 089 public ClassHierarchy getClassHierarchy() { 090 return builder.getClassHierarchy(); 091 } 092 093 @Override 094 public Set<Object> getBoundSet(final NamedParameterNode<Set<?>> np) { 095 return this.builder.boundSetEntries.getValuesForKey(np); 096 } 097 098 @Override 099 public List<Object> getBoundList(final NamedParameterNode<List<?>> np) { 100 return this.builder.boundLists.get(np); 101 } 102 103 @Override 104 public Set<NamedParameterNode<Set<?>>> getBoundSets() { 105 return builder.boundSetEntries.keySet(); 106 } 107 108 @Override 109 public Set<NamedParameterNode<List<?>>> getBoundLists() { 110 return builder.boundLists.keySet(); 111 } 112 113 @Override 114 public boolean equals(final Object o) { 115 if (this == o) { 116 return true; 117 } 118 if (o == null || getClass() != o.getClass()) { 119 return false; 120 } 121 122 final ConfigurationImpl that = (ConfigurationImpl) o; 123 124 if (builder != null ? !builder.equals(that.builder) : that.builder != null) { 125 return false; 126 } 127 128 return true; 129 } 130 131 @Override 132 public int hashCode() { 133 return builder != null ? builder.hashCode() : 0; 134 } 135 136 public ConfigurationBuilderImpl getBuilder() { 137 return builder; 138 } 139}