Java Code Examples for com.google.common.collect.ClassToInstanceMap#put()
The following examples show how to use
com.google.common.collect.ClassToInstanceMap#put() .
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: 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 4
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; }