Java Code Examples for com.google.common.collect.ImmutableClassToInstanceMap#of()

The following examples show how to use com.google.common.collect.ImmutableClassToInstanceMap#of() . 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: RemoteSpawnRunnerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
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 2
Source File: ClassToInstanceMapUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@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 3
Source File: PluginRegistry.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
PluginRegistry() {
    this(ImmutableClassToInstanceMap.of());
}
 
Example 4
Source File: JSONNormalizedNodeStreamWriter.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() {
    return ImmutableClassToInstanceMap.of(StreamWriterMountPointExtension.class, this);
}
 
Example 5
Source File: ImmutableMetadataNormalizedNodeStreamWriter.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() {
    return ImmutableClassToInstanceMap.of(StreamWriterMetadataExtension.class, this);
}
 
Example 6
Source File: ImmutableMountPointNormalizedNodeStreamWriter.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() {
    return ImmutableClassToInstanceMap.of(StreamWriterMountPointExtension.class, this);
}
 
Example 7
Source File: XMLStreamNormalizedNodeStreamWriter.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final ClassToInstanceMap<NormalizedNodeStreamWriterExtension> getExtensions() {
    return ImmutableClassToInstanceMap.of(StreamWriterMetadataExtension.class, this);
}
 
Example 8
Source File: FakeSpawnExecutionContext.java    From bazel with Apache License 2.0 4 votes vote down vote up
public FakeSpawnExecutionContext(
    Spawn spawn, MetadataProvider metadataProvider, Path execRoot, FileOutErr outErr) {
  this(spawn, metadataProvider, execRoot, outErr, ImmutableClassToInstanceMap.of());
}
 
Example 9
Source File: ClassToInstanceMapUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenOfCalled_thenCreateEmptyImmutableMap() {
    ClassToInstanceMap<Action> map = ImmutableClassToInstanceMap.of();
    assertTrue(map.isEmpty());
}
 
Example 10
Source File: ClassToInstanceMapUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void whenOfWithParameterCalled_thenCreateSingleEntryMap() {
    ClassToInstanceMap<Action> map = ImmutableClassToInstanceMap.of(Save.class, new Save());
    assertEquals(1, map.size());
}
 
Example 11
Source File: ExtensibleObject.java    From yangtools with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * 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();
}