com.google.common.collect.ClassToInstanceMap Java Examples
The following examples show how to use
com.google.common.collect.ClassToInstanceMap.
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: JaxrsParameterExtension.java From swagger-maven-plugin with Apache License 2.0 | 6 votes |
@Override public List<Parameter> extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Iterator<SwaggerExtension> chain) { if (this.shouldIgnoreType(type, typesToSkip)) { return new ArrayList<Parameter>(); } ClassToInstanceMap<Annotation> annotationMap = toMap(annotations); List<Parameter> parameters = new ArrayList<Parameter>(); parameters.addAll(extractParametersFromAnnotation(type, annotationMap)); if (!parameters.isEmpty()) { return parameters; } return super.extractParameters(annotations, type, typesToSkip, chain); }
Example #3
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 #4
Source File: VirtualChestActionDispatcher.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
private static ClassToInstanceMap<Context> getContextMap(UUID actionUUID, Player player, VirtualChestHandheldItem itemTemplate) { ImmutableClassToInstanceMap.Builder<Context> contextBuilder = ImmutableClassToInstanceMap.builder(); contextBuilder.put(Context.HANDHELD_ITEM, new HandheldItemContext(itemTemplate::matchItem)); contextBuilder.put(Context.ACTION_UUID, new ActionUUIDContext(actionUUID)); contextBuilder.put(Context.PLAYER, new PlayerContext(player)); return contextBuilder.build(); }
Example #5
Source File: StaticEnvironment.java From immutables with Apache License 2.0 | 5 votes |
static <T extends Completable> T getInstance(Class<T> type, Supplier<T> supplier) { ClassToInstanceMap<Completable> components = state().components; @Nullable T instance = components.getInstance(type); if (instance == null) { instance = supplier.get(); components.putInstance(type, instance); } return instance; }
Example #6
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 #7
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 #8
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenClassToInstanceMap_whenGetCalled_returnUpperBoundElement() { ClassToInstanceMap<Action> map = ImmutableClassToInstanceMap.of(Save.class, new Save()); Action action = map.get(Save.class); assertTrue(action instanceof Save); // Use getInstance to avoid casting Save save = map.getInstance(Save.class); }
Example #9
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenBuilderUser_thenCreateMap() { ClassToInstanceMap<Action> map = ImmutableClassToInstanceMap.<Action>builder() .put(Save.class, new Save()) .put(Open.class, new Open()) .build(); assertEquals(2, map.size()); }
Example #10
Source File: FakeSpawnExecutionContext.java From bazel with Apache License 2.0 | 5 votes |
public FakeSpawnExecutionContext( Spawn spawn, MetadataProvider metadataProvider, Path execRoot, FileOutErr outErr, ClassToInstanceMap<ActionContext> actionContextRegistry) { this.spawn = spawn; this.metadataProvider = metadataProvider; this.execRoot = execRoot; this.outErr = outErr; this.actionContextRegistry = actionContextRegistry; }
Example #11
Source File: RemoteSpawnRunnerTest.java From bazel with Apache License 2.0 | 5 votes |
private FakeSpawnExecutionContext getSpawnContext(Spawn spawn) { AbstractSpawnStrategy fakeLocalStrategy = new AbstractSpawnStrategy(execRoot, localRunner) {}; ClassToInstanceMap<ActionContext> actionContextRegistry = ImmutableClassToInstanceMap.of(RemoteLocalFallbackRegistry.class, () -> fakeLocalStrategy); return new FakeSpawnExecutionContext( spawn, fakeFileCache, execRoot, outErr, actionContextRegistry); }
Example #12
Source File: BuildModelContext.java From ok-gradle with Apache License 2.0 | 5 votes |
@NotNull public <T extends BuildModelNotification> T getNotificationForType(@NotNull GradleDslFile file, @NotNull NotificationTypeReference<T> type) { ClassToInstanceMap<BuildModelNotification> notificationMap = myNotifications.computeIfAbsent(file, (f) -> MutableClassToInstanceMap.create()); if (notificationMap.containsKey(type.getClazz())) { return notificationMap.getInstance(type.getClazz()); } else { T notification = type.getConstructor().produce(); notificationMap.putInstance(type.getClazz(), notification); return notification; } }
Example #13
Source File: XMLStreamNormalizedNodeStreamWriter.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override public final ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() { return ImmutableClassToInstanceMap.of(StreamWriterMetadataExtension.class, this); }
Example #14
Source File: ImmutableMountPointNormalizedNodeStreamWriter.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override public final ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() { return ImmutableClassToInstanceMap.of(StreamWriterMountPointExtension.class, this); }
Example #15
Source File: TemplateManager.java From ldp4j with Apache License 2.0 | 4 votes |
private HandlerMapBuilder(Builder<HandlerId, ResourceHandler> builder, ClassToInstanceMap<ResourceHandler> handlers) { this.builder = builder; this.handlers = handlers; }
Example #16
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenOfCalled_thenCreateEmptyImmutableMap() { ClassToInstanceMap<Action> map = ImmutableClassToInstanceMap.of(); assertTrue(map.isEmpty()); }
Example #17
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenCreateCalled_thenCreateEmptyMutableMap() { ClassToInstanceMap<Action> map = MutableClassToInstanceMap.create(); assertTrue(map.isEmpty()); }
Example #18
Source File: ClassToInstanceMapUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void whenOfWithParameterCalled_thenCreateSingleEntryMap() { ClassToInstanceMap<Action> map = ImmutableClassToInstanceMap.of(Save.class, new Save()); assertEquals(1, map.size()); }
Example #19
Source File: ImmutableMetadataNormalizedNodeStreamWriter.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override public final ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() { return ImmutableClassToInstanceMap.of(StreamWriterMetadataExtension.class, this); }
Example #20
Source File: ForwardingNormalizedNodeStreamWriter.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override public ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() { return delegate().getExtensions(); }
Example #21
Source File: JSONNormalizedNodeStreamWriter.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Override public ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() { return ImmutableClassToInstanceMap.of(StreamWriterMountPointExtension.class, this); }
Example #22
Source File: FallbackInstanceStorage.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
protected FallbackInstanceStorage(ClassToInstanceMap<B> instances, InstanceStorage<B> defaults) { super(instances); this.defaults = Preconditions.checkNotNull(defaults, "defaults"); }
Example #23
Source File: ClassToInstanceStorage.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
protected ClassToInstanceStorage(ClassToInstanceMap<B> instances) { this.instances = Preconditions.checkNotNull(instances, "instances"); }
Example #24
Source File: ClassToInstanceStorage.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
public static <T> ClassToInstanceStorage<T> create(ClassToInstanceMap<T> instances) { return new ClassToInstanceStorage<>(instances); }
Example #25
Source File: ObjectExtensions.java From yangtools with Eclipse Public License 1.0 | 4 votes |
public @NonNull ClassToInstanceMap<E> newInstance(final T object) { return new ObjectExtensions<>(extensions, object); }
Example #26
Source File: ExtensibleObject.java From yangtools with Eclipse Public License 1.0 | 2 votes |
/** * Return a map of currently-supported extensions, along with accessor objects which provide access to the specific * functionality bound to this object. * * @return A map of supported functionality. */ default @NonNull ClassToInstanceMap<E> getExtensions() { return ImmutableClassToInstanceMap.of(); }
Example #27
Source File: VirtualChestActionExecutor.java From VirtualChest with GNU Lesser General Public License v3.0 | 2 votes |
/** * Execute the submitted action and return a result. Asynchronous execution is allowed. * * @param parent parent result * @param command command suffix * @param context immutable context map * @return a completable future which will provide a {@link CommandResult} */ CompletableFuture<CommandResult> execute(CommandResult parent, String command, ClassToInstanceMap<Context> context);