Java Code Examples for java.util.Hashtable#putIfAbsent()
The following examples show how to use
java.util.Hashtable#putIfAbsent() .
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: TestHelper.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
protected ServiceRegistration<?> registerExtension( String name, Object... keyValues) { TestFilter testFilter = new TestFilter(); Hashtable<String, Object> properties = new Hashtable<>(); properties.put(JAX_RS_EXTENSION, true); properties.put(JAX_RS_NAME, name); properties.putIfAbsent( JAX_RS_APPLICATION_SELECT, "(osgi.jaxrs.name=*)"); for (int i = 0; i < keyValues.length; i = i + 2) { properties.put(keyValues[i].toString(), keyValues[i + 1]); } ServiceRegistration<ContainerResponseFilter> serviceRegistration = bundleContext.registerService( ContainerResponseFilter.class, testFilter, properties); _registrations.add(serviceRegistration); return serviceRegistration; }
Example 2
Source File: TestHelper.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
protected <T> ServiceRegistration<T> registerExtension( Class<T> clazz, T extension, String name, Object... keyValues) { Hashtable<String, Object> properties = new Hashtable<>(); properties.put(JAX_RS_EXTENSION, true); properties.put(JAX_RS_NAME, name); properties.putIfAbsent( JAX_RS_APPLICATION_SELECT, "(osgi.jaxrs.name=*)"); for (int i = 0; i < keyValues.length; i = i + 2) { properties.put(keyValues[i].toString(), keyValues[i + 1]); } ServiceRegistration<T> serviceRegistration = bundleContext.registerService(clazz, extension, properties); _registrations.add(serviceRegistration); return serviceRegistration; }
Example 3
Source File: TestHelper.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
protected ServiceRegistration<?> registerInvalidExtension( String name, Object... keyValues) { TestFilter testFilter = new TestFilter(); Hashtable<String, Object> properties = new Hashtable<>(); properties.put(JAX_RS_EXTENSION, true); properties.put(JAX_RS_NAME, name); properties.putIfAbsent( JAX_RS_APPLICATION_SELECT, "(osgi.jaxrs.name=*)"); for (int i = 0; i < keyValues.length; i = i + 2) { properties.put(keyValues[i].toString(), keyValues[i + 1]); } ServiceRegistration<Object> serviceRegistration = bundleContext.registerService( Object.class, testFilter, properties); _registrations.add(serviceRegistration); return serviceRegistration; }
Example 4
Source File: TestHelper.java From aries-jax-rs-whiteboard with Apache License 2.0 | 6 votes |
protected ServiceRegistration<?> registerMultiExtension( String name, String... classes) { Hashtable<String, Object> properties = new Hashtable<>(); properties.put(JAX_RS_EXTENSION, true); properties.put(JAX_RS_NAME, name); properties.putIfAbsent( JAX_RS_APPLICATION_SELECT, "(osgi.jaxrs.name=*)"); ServiceRegistration<?> serviceRegistration = bundleContext.registerService( classes, new TestFilterAndExceptionMapper(), properties); _registrations.add(serviceRegistration); return serviceRegistration; }
Example 5
Source File: HashtableUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void whenPutifAbsent_thenNotRewritten() { Hashtable<Word, String> table = new Hashtable<Word, String>(); table.put(new Word("cat"), "a small domesticated carnivorous mammal"); String definition = "an animal"; // old way /* if (!table.containsKey(new Word("cat"))) { table.put(new Word("cat"), definition); }*/ // new way table.putIfAbsent(new Word("cat"), definition); assertThat(table.get(new Word("cat")), is("a small domesticated carnivorous mammal")); }