Tabnine Logo
Collections.singletonMap
Code IndexAdd Tabnine to your IDE (free)

How to use
singletonMap
method
in
java.util.Collections

Best Java code snippets using java.util.Collections.singletonMap (Showing top 20 results out of 27,324)

Refine searchRefine arrow

  • Test.<init>
  • Map.put
  • Assert.assertEquals
  • Collections.emptyMap
  • Map.get
origin: spring-projects/spring-framework

/**
 * Merge a single hint into a map of hints, possibly creating and copying
 * all hints into a new map, or otherwise if the map of hints is empty,
 * creating a new single entry map.
 * @param hints a map of hints to be merge
 * @param hintName the hint name to merge
 * @param hintValue the hint value to merge
 * @return a single map with all hints
 */
public static Map<String, Object> merge(Map<String, Object> hints, String hintName, Object hintValue) {
  if (hints.isEmpty()) {
    return Collections.singletonMap(hintName, hintValue);
  }
  else {
    Map<String, Object> result = new HashMap<>(hints.size() + 1);
    result.putAll(hints);
    result.put(hintName, hintValue);
    return result;
  }
}
origin: codecentric/spring-boot-admin

@SuppressWarnings("unchecked")
private static Map<String, Object> convertLiquibase(List<Map<String, Object>> reports) {
  Map<String, Object> liquibaseBeans = reports.stream()
                        .sequential()
                        .collect(toMap(r -> (String) r.get("name"),
                          r -> singletonMap("changeSets",
                            LegacyEndpointConverters.convertLiquibaseChangesets(
                              (List<Map<String, Object>>) r.get("changeLogs")))));
  return singletonMap("contexts", singletonMap("application", singletonMap("liquibaseBeans", liquibaseBeans)));
}
origin: spring-projects/spring-framework

@Test
public void resolveExtensions() {
  Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
  MappingMediaTypeFileExtensionResolver resolver = new MappingMediaTypeFileExtensionResolver(mapping);
  List<String> extensions = resolver.resolveFileExtensions(MediaType.APPLICATION_JSON);
  assertEquals(1, extensions.size());
  assertEquals("json", extensions.get(0));
}
origin: spring-projects/spring-framework

@Test
@SuppressWarnings("unchecked")
public void headerArgumentResolution() {
  Map<String, Object> headers = Collections.singletonMap("foo", "bar");
  Message<?> message = createMessage("/pre/headers", headers);
  this.messageHandler.registerHandler(this.testController);
  this.messageHandler.handleMessage(message);
  assertEquals("headers", this.testController.method);
  assertEquals("bar", this.testController.arguments.get("foo"));
  assertEquals("bar", ((Map<String, Object>) this.testController.arguments.get("headers")).get("foo"));
}
origin: spring-projects/spring-framework

@Test
public void defaultUriVarsSpr14147() {
  Map<String, String> defaultUriVars = new HashMap<>(2);
  defaultUriVars.put("host", "api.example.com");
  defaultUriVars.put("port", "443");
  DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory();
  factory.setDefaultUriVariables(defaultUriVars);
  URI uri = factory.expand("https://{host}:{port}/v42/customers/{id}", singletonMap("id", 123L));
  assertEquals("https://api.example.com:443/v42/customers/123", uri.toString());
}
origin: apache/kafka

@Test
public void testNullConfigValue() throws Exception {
  ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, null));
  Map<String, String> data = result.data();
  Map<String, Long> ttls = result.ttls();
  assertNull(data.get(MY_KEY));
  assertTrue(ttls.isEmpty());
}
origin: spring-projects/spring-framework

@Test
public void resolveKeyFromRegistrations() {
  ServerWebExchange exchange = createExchange("html");
  Map<String, MediaType> mapping = Collections.emptyMap();
  RequestedContentTypeResolver resolver = new ParameterContentTypeResolver(mapping);
  List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
  assertEquals(Collections.singletonList(new MediaType("text", "html")), mediaTypes);
  mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML);
  resolver = new ParameterContentTypeResolver(mapping);
  mediaTypes = resolver.resolveMediaTypes(exchange);
  assertEquals(Collections.singletonList(new MediaType("application", "xhtml+xml")), mediaTypes);
}
origin: apache/storm

@Test
public void testAddWhenOtherHasMoreResourcesThanThis() {
  NormalizedResources resources = new NormalizedResources(normalize(Collections.emptyMap()));
  NormalizedResources addedResources = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1)));
  
  resources.add(addedResources);
  
  Map<String, Double> normalizedMap = resources.toNormalizedMap();
  assertThat(normalizedMap.get(gpuResourceName), is(1.0));
}

origin: apache/incubator-shardingsphere

/**
 * Renew to add new schema.
 *
 * @param schemaAddedEvent schema add changed event
 */
@Subscribe
public synchronized void renew(final SchemaAddedEvent schemaAddedEvent) {
  logicSchemas.put(schemaAddedEvent.getShardingSchemaName(), createLogicSchema(schemaAddedEvent.getShardingSchemaName(), 
      Collections.singletonMap(schemaAddedEvent.getShardingSchemaName(), DataSourceConverter.getDataSourceParameterMap(schemaAddedEvent.getDataSourceConfigurations())), 
      schemaAddedEvent.getRuleConfiguration(), true));
}

origin: redisson/redisson

@Override
protected Map<Integer, TypeDefinition> resolveInitializationTypes(ArgumentHandler argumentHandler) {
  return adviceMethod.getReturnType().represents(void.class)
      ? Collections.<Integer, TypeDefinition>emptyMap()
      : Collections.<Integer, TypeDefinition>singletonMap(argumentHandler.exit(), adviceMethod.getReturnType());
}
origin: apache/storm

@Test
public void testCouldHoldWithMissingResource() {
  NormalizedResources resources = new NormalizedResources(normalize(Collections.emptyMap()));
  NormalizedResources resourcesToCheck = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1)));
  
  boolean couldHold = resources.couldHoldIgnoringSharedMemory(resourcesToCheck, 100, 1);
  
  assertThat(couldHold, is(false));
}

origin: spring-projects/spring-framework

@Test
public void optionalHeaderArgumentResolutionWhenPresent() {
  Map<String, Object> headers = Collections.singletonMap("foo", "bar");
  Message<?> message = createMessage("/pre/optionalHeaders", headers);
  this.messageHandler.registerHandler(this.testController);
  this.messageHandler.handleMessage(message);
  assertEquals("optionalHeaders", this.testController.method);
  assertEquals("bar", this.testController.arguments.get("foo1"));
  assertEquals("bar", this.testController.arguments.get("foo2"));
}
origin: spring-projects/spring-framework

@Test
public void singleKey() {
  kh.getKeyList().addAll(singletonList(singletonMap("key", 1)));
  assertEquals("single key should be returned", 1, kh.getKey().intValue());
}
origin: spring-projects/spring-framework

@Test(expected = IllegalArgumentException.class)
public void pathVariableNotFound() {
  MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com"));
  Map<String, String> pathVariables = Collections.singletonMap("foo", "bar");
  exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables);
  DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders);
  request.pathVariable("baz");
}
origin: spring-projects/spring-framework

@Test
public void modelAttributes() {
  Map<String, String> model = Collections.singletonMap("foo", "bar");
  Mono<RenderingResponse> result = RenderingResponse.create("foo")
      .modelAttributes(model).build();
  StepVerifier.create(result)
      .expectNextMatches(response -> "bar".equals(response.model().get("foo")))
      .expectComplete()
      .verify();
}
origin: codecentric/spring-boot-admin

@SuppressWarnings("unchecked")
private static Map<String, Object> convertFlyway(List<Map<String, Object>> reports) {
  Map<String, Object> flywayBeans = reports.stream()
                       .sequential()
                       .collect(toMap(r -> (String) r.get("name"),
                         r -> singletonMap("migrations",
                           LegacyEndpointConverters.convertFlywayMigrations(
                             (List<Map<String, Object>>) r.get("migrations")))));
  return singletonMap("contexts", singletonMap("application", singletonMap("flywayBeans", flywayBeans)));
}
origin: apache/kafka

@Test
public void testEmptyList() {
  AbstractConfig conf;
  ConfigDef configDef = new ConfigDef().define("a", Type.LIST, "", new ConfigDef.NonNullValidator(), Importance.HIGH, "doc");
  conf = new AbstractConfig(configDef, Collections.emptyMap());
  assertEquals(Collections.emptyList(), conf.getList("a"));
  conf = new AbstractConfig(configDef, Collections.singletonMap("a", ""));
  assertEquals(Collections.emptyList(), conf.getList("a"));
  conf = new AbstractConfig(configDef, Collections.singletonMap("a", "b,c,d"));
  assertEquals(Arrays.asList("b", "c", "d"), conf.getList("a"));
}
origin: apache/incubator-shardingsphere

/**
 * Renew to add new schema.
 *
 * @param schemaAddedEvent schema add changed event
 */
@Subscribe
public synchronized void renew(final SchemaAddedEvent schemaAddedEvent) {
  logicSchemas.put(schemaAddedEvent.getShardingSchemaName(), createLogicSchema(schemaAddedEvent.getShardingSchemaName(), 
      Collections.singletonMap(schemaAddedEvent.getShardingSchemaName(), DataSourceConverter.getDataSourceParameterMap(schemaAddedEvent.getDataSourceConfigurations())), 
      schemaAddedEvent.getRuleConfiguration(), true));
}

origin: google/guava

public void testEnumMap() {
 EnumMap<SomeEnum, Integer> map = Maps.newEnumMap(SomeEnum.class);
 assertEquals(Collections.emptyMap(), map);
 map.put(SomeEnum.SOME_INSTANCE, 0);
 assertEquals(Collections.singletonMap(SomeEnum.SOME_INSTANCE, 0), map);
}
origin: apache/kafka

@Test
public void testErrorCountsWithTopLevelError() {
  Map<TopicPartition, Errors> errors = new HashMap<>();
  errors.put(new TopicPartition("foo", 0), Errors.NONE);
  errors.put(new TopicPartition("foo", 1), Errors.NOT_LEADER_FOR_PARTITION);
  StopReplicaResponse response = new StopReplicaResponse(Errors.UNKNOWN_SERVER_ERROR, errors);
  assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 2), response.errorCounts());
}
java.utilCollectionssingletonMap

Javadoc

Returns a Map containing the specified key and value. The map cannot be modified. The map is serializable.

Popular methods of Collections

  • emptyList
    Returns the empty list (immutable). This list is serializable.This example illustrates the type-safe
  • sort
  • singletonList
    Returns an immutable list containing only the specified object. The returned list is serializable.
  • unmodifiableList
    Returns an unmodifiable view of the specified list. This method allows modules to provide users with
  • emptyMap
    Returns the empty map (immutable). This map is serializable.This example illustrates the type-safe w
  • emptySet
    Returns the empty set (immutable). This set is serializable. Unlike the like-named field, this metho
  • unmodifiableMap
    Returns an unmodifiable view of the specified map. This method allows modules to provide users with
  • singleton
    Returns an immutable set containing only the specified object. The returned set is serializable.
  • unmodifiableSet
    Returns an unmodifiable view of the specified set. This method allows modules to provide users with
  • addAll
    Adds all of the specified elements to the specified collection. Elements to be added may be specifie
  • reverse
    Reverses the order of the elements in the specified list. This method runs in linear time.
  • unmodifiableCollection
    Returns an unmodifiable view of the specified collection. This method allows modules to provide user
  • reverse,
  • unmodifiableCollection,
  • shuffle,
  • enumeration,
  • list,
  • synchronizedMap,
  • synchronizedList,
  • reverseOrder,
  • emptyIterator

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onCreateOptionsMenu (Activity)
  • getExternalFilesDir (Context)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now