org.javabits.yar.guice.CollectionsRegistryAnnotatedBindingBuilderImpl Maven / Gradle / Ivy
/*
* Copyright 2013 Romain Gilles
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.javabits.yar.guice;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.binder.AnnotatedBindingBuilder;
import com.google.inject.binder.LinkedBindingBuilder;
import org.javabits.yar.Ids;
import org.javabits.yar.Registry;
import org.javabits.yar.Supplier;
import javax.annotation.Nullable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import static java.util.Objects.requireNonNull;
/**
* TODO comment
* Date: 3/12/13
* Time: 9:25 AM
*
* @author Romain Gilles
*/
public class CollectionsRegistryAnnotatedBindingBuilderImpl extends RegistryAnnotatedBindingBuilderImpl {
public CollectionsRegistryAnnotatedBindingBuilderImpl(Binder binder, Key key, LinkedBindingBuilder bindingBuilder) {
super(binder, key, bindingBuilder);
}
public CollectionsRegistryAnnotatedBindingBuilderImpl(Binder binder, TypeLiteral typeLiteral, AnnotatedBindingBuilder bindingBuilder) {
super(binder, typeLiteral, bindingBuilder);
}
@Override
Iterable> doToRegistry() {
RegistryProvider registryProvider = newRegistryProvider();
linkedBindingBuilder().toProvider(registryProvider);
return Collections.>singleton(registryProvider);
}
RegistryProvider newRegistryProvider() {
return new CollectionsRegistryProvider<>(key(), isLaxTypeBinding());
}
private static class CollectionsRegistryProvider implements RegistryProvider {
private final boolean laxTypeBinding;
private final Key key;
private Registry registry;
private CollectionsRegistryProvider(Key key, boolean laxTypeBinding) {
this.key = key;
this.laxTypeBinding = laxTypeBinding;
}
@Override
@SuppressWarnings("unchecked")
public T get() {
return (T) Lists.transform(getAll(), new Function, Object>() {
@Nullable
@Override
public Object apply(@Nullable Supplier
© 2015 - 2025 Weber Informatics LLC | Privacy Policy