Java Code Examples for com.google.common.collect.MutableClassToInstanceMap#create()
The following examples show how to use
com.google.common.collect.MutableClassToInstanceMap#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassToInstanceMapExample.java From levelup-java-examples with Apache License 2.0 | 8 votes |
@Test public void classToINstanceMap_example () { Person person = new Person("Jackson"); Jobs jobs = new Jobs("IT person"); Address address = new Address("505 Williams Street"); ClassToInstanceMap<Object> classToInstanceMap = MutableClassToInstanceMap.create(); classToInstanceMap.put(Person.class, person); classToInstanceMap.put(Jobs.class, jobs); classToInstanceMap.put(Address.class, address); logger.info(classToInstanceMap); assertEquals("IT person", classToInstanceMap.getInstance(Jobs.class).getJobName()); }
Example 2
Source File: BuildConfiguration.java From bazel with Apache License 2.0 | 6 votes |
/** * Returns a copy of this configuration only including the given fragments (which the current * configuration is assumed to have). */ public BuildConfiguration clone( FragmentClassSet fragmentClasses, RuleClassProvider ruleClassProvider, BuildOptions defaultBuildOptions) { ClassToInstanceMap<Fragment> fragmentsMap = MutableClassToInstanceMap.create(); for (Fragment fragment : fragments.values()) { if (fragmentClasses.fragmentClasses().contains(fragment.getClass())) { fragmentsMap.put(fragment.getClass(), fragment); } } BuildOptions options = buildOptions.trim(getOptionsClasses(fragmentsMap.keySet(), ruleClassProvider)); BuildConfiguration newConfig = new BuildConfiguration( getDirectories(), fragmentsMap, options, BuildOptions.diffForReconstruction(defaultBuildOptions, options), reservedActionMnemonics, actionEnv, mainRepositoryName.strippedName()); return newConfig; }
Example 3
Source File: ModuleActionContextRegistry.java From bazel with Apache License 2.0 | 5 votes |
/** Constructs the registry configured by this builder. */ public ModuleActionContextRegistry build() throws AbruptExitException { HashSet<Class<?>> usedTypes = new HashSet<>(); MutableClassToInstanceMap<ActionContext> contextToInstance = MutableClassToInstanceMap.create(); for (ActionContextInformation<?> actionContextInformation : actionContexts) { Class<? extends ActionContext> identifyingType = actionContextInformation.identifyingType(); if (typeToRestriction.containsKey(identifyingType)) { String restriction = typeToRestriction.get(identifyingType); if (!actionContextInformation.commandLineIdentifiers().contains(restriction) && !restriction.isEmpty()) { continue; } } usedTypes.add(identifyingType); actionContextInformation.addToMap(contextToInstance); } Sets.SetView<Class<?>> unusedRestrictions = Sets.difference(typeToRestriction.keySet(), usedTypes); if (!unusedRestrictions.isEmpty()) { throw new AbruptExitException( DetailedExitCode.of( FailureDetail.newBuilder() .setMessage(getMissingIdentifierErrorMessage(unusedRestrictions).toString()) .setExecutionOptions( FailureDetails.ExecutionOptions.newBuilder() .setCode(Code.RESTRICTION_UNMATCHED_TO_ACTION_CONTEXT)) .build())); } return new ModuleActionContextRegistry(ImmutableClassToInstanceMap.copyOf(contextToInstance)); }
Example 4
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenClassToInstanceMap_whenPutCalled_returnPreviousElementUpperBound() { ClassToInstanceMap<Action> map = MutableClassToInstanceMap.create(); map.put(Save.class, new Save()); // Put again to get previous value returned Action action = map.put(Save.class, new Save()); assertTrue(action instanceof Save); // Use putInstance to avoid casting Save save = map.putInstance(Save.class, new Save()); }
Example 5
Source File: JaxrsParameterExtension.java From swagger-maven-plugin with Apache License 2.0 | 5 votes |
private ClassToInstanceMap<Annotation> toMap(Collection<? extends Annotation> annotations) { ClassToInstanceMap<Annotation> annotationMap = MutableClassToInstanceMap.create(); for (Annotation annotation : annotations) { if (annotation == null) { continue; } annotationMap.put(annotation.annotationType(), annotation); } return annotationMap; }
Example 6
Source File: StaticEnvironment.java From immutables with Apache License 2.0 | 5 votes |
void init(Set<? extends TypeElement> annotations, RoundEnvironment round, ProcessingEnvironment processing) { this.components = MutableClassToInstanceMap.create(); this.processing = processing; this.round = round; this.annotations = ImmutableSet.copyOf(annotations); this.initialized = true; }
Example 7
Source File: ServiceRegistry.java From ldp4j with Apache License 2.0 | 4 votes |
public ServiceRegistry() { this.services=MutableClassToInstanceMap.<Service>create(); this.builders=new LinkedHashMap<Class<?>, ServiceBuilder<?>>(); this.delegate=RuntimeDelegate.getInstance(); }
Example 8
Source File: TemplateManager.java From ldp4j with Apache License 2.0 | 4 votes |
private TemplateManagerBuilder() { this.handlerClasses=Lists.newArrayList(); this.handlers=MutableClassToInstanceMap.<ResourceHandler>create(); }
Example 9
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenCreateCalled_thenCreateEmptyMutableMap() { ClassToInstanceMap<Action> map = MutableClassToInstanceMap.create(); assertTrue(map.isEmpty()); }