List of usage examples for java.util Collections singletonList
public static <T> List<T> singletonList(T o)
From source file:com.github.robozonky.integrations.zonkoid.UtilTest.java
@Test void responseContent() { final Collection<NameValuePair> nvp = Collections.singletonList(new BasicNameValuePair("key", "value")); final HttpEntity e = new UrlEncodedFormEntity(nvp); assertThat(Util.readEntity(e)).isNotEmpty(); }
From source file:com.photon.phresco.service.admin.actions.admin.GlobalUrlList.java
public String save() { S_LOGGER.debug("Entering Method GlobalUrlList.list()"); try {//from w w w .j a v a 2 s. co m if (validateForm()) { setErrorFound(true); return SUCCESS; } addActionMessage(getText(URL_ADDED, Collections.singletonList(name))); } catch (Exception e) { addActionError(getText(URL_NOT_ADDED, Collections.singletonList(name))); } return ADMIN_GLOBALURL_LIST; }
From source file:com.lexicalintelligence.admin.add.AddRequest.java
public AddResponse execute() { List<BasicNameValuePair> params = Collections .singletonList(new BasicNameValuePair(getName(), StringUtils.join(items, ","))); AddResponse addResponse;//from w w w. j ava 2 s .c o m Reader reader = null; try { HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath() + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); addResponse = new AddResponse(Boolean.valueOf(IOUtils.toString(reader))); } catch (Exception e) { addResponse = new AddResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { log.error(e); } } return addResponse; }
From source file:com.hp.autonomy.aci.content.identifier.stateid.StateIdsBuilder.java
/** * Creates a {@code StateIdsBuilder} containing the specified state token and zero-based document index range. * * @param stateToken The state token/*w w w.j a v a 2 s .c o m*/ * @param start The start index of the range * @param end The end index of the range */ public StateIdsBuilder(final String stateToken, final int start, final int end) { doAppend(Collections.singletonList(new StateId(stateToken, start, end))); }
From source file:com.emc.ecs.sync.util.TimingUtilTest.java
@Test public void testTimings() { int threadCount = Runtime.getRuntime().availableProcessors() * 8; // 8 threads per core for stress int window = threadCount * 100; // should dump stats every 100 "objects" per thread int total = window * 5; // ~500 "objects" per thread total DummyFilter filter = new DummyFilter(); EcsSync sync = new EcsSync(); sync.setSource(new DummySource(total)); sync.setFilters(Collections.singletonList((SyncFilter) filter)); sync.setTarget(new DummyTarget()); sync.setTimingsEnabled(true);/*from w w w . j a v a2 s.co m*/ sync.setTimingWindow(window); sync.setSyncThreadCount(threadCount); sync.run(); System.out.println("---Timing enabled---"); System.out.println( "Per-thread overhead is " + (filter.getOverhead() / threadCount / 1000000) + "ms over 500 calls"); System.out.println("Per-call overhead is " + ((filter.getOverhead()) / (total) / 1000) + "s"); filter = new DummyFilter(); // this one won't be registered sync.setFilters(Collections.singletonList((SyncFilter) filter)); sync.setTimingsEnabled(false); sync.run(); System.out.println("---Timing disabled---"); System.out.println( "Per-thread overhead is " + (filter.getOverhead() / threadCount / 1000000) + "ms over 500 calls"); System.out.println("Per-call overhead is " + ((filter.getOverhead()) / (total) / 1000) + "s"); }
From source file:com.stormpath.shiro.spring.boot.autoconfigure.StormpathShiroWebAutoConfigurationTestApplication.java
/** * Override the default to block outbound requests. * @return a mock client/* w ww .j a v a 2 s. c o m*/ */ @Bean @SuppressWarnings("Duplicates") public Client stormpathClient() { String appHref = "http://test-app-href"; Application application = EasyMock.createMock(Application.class); Collection<Application> applications = Collections.singletonList(application); ApplicationList applicationList = EasyMock.createMock(ApplicationList.class); Client client = EasyMock.createNiceMock(Client.class); AccountStore accountStore = EasyMock.createNiceMock(AccountStore.class); expect(applicationList.iterator()).andReturn(applications.iterator()); expect(application.getName()).andReturn("test-app"); expect(application.getHref()).andReturn(appHref); expect(application.getDefaultAccountStore()).andReturn(accountStore); expect(client.getApplications()).andReturn(applicationList); expect(client.getResource(anyString(), eq(Application.class))).andReturn(application).anyTimes(); expect(client.getCacheManager()).andReturn(new DisabledCacheManager()); expect(client.getApiKey()).andReturn(new ClientApiKey("id", "secret")); replay(application, applicationList, client, accountStore); return client; }
From source file:com.anhth12.lambda.ml.param.HyperParams.java
public static HyperParamValues<?> fromConfig(Config config, String key) { switch (config.getValue(key).valueType()) { case LIST://from w ww . ja v a 2 s. c o m List<String> stringValues = config.getStringList(key); try { return range(Integer.parseInt(stringValues.get(0)), Integer.parseInt(stringValues.get(1))); } catch (NumberFormatException nfe) { // continue } try { return range(Double.parseDouble(stringValues.get(0)), Double.parseDouble(stringValues.get(1))); } catch (NumberFormatException nfe) { // continue } return unorderedFromValues(stringValues); case STRING: case NUMBER: String stringValue = config.getString(key); try { return fixed(Integer.parseInt(stringValue)); } catch (NumberFormatException nfe) { } try { return fixed(Double.parseDouble(stringValue)); } catch (NumberFormatException nfe) { // continue } return unorderedFromValues(Collections.singletonList(stringValue)); default: throw new AssertionError(config.getValue(key).valueType().name()); } }
From source file:com.lexicalintelligence.admin.remove.RemoveRequest.java
public RemoveResponse execute() { List<BasicNameValuePair> params = Collections .singletonList(new BasicNameValuePair(getName(), StringUtils.join(items, ","))); RemoveResponse removeResponse;/*from w ww.jav a 2s .c o m*/ Reader reader = null; try { HttpResponse response = client.getHttpClient().execute(new HttpGet(client.getUrl() + PATH + getPath() + "?" + URLEncodedUtils.format(params, StandardCharsets.UTF_8))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); removeResponse = new RemoveResponse(Boolean.valueOf(IOUtils.toString(reader))); } catch (Exception e) { removeResponse = new RemoveResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { log.error(e); } } return removeResponse; }
From source file:com.cloudera.cdk.morphline.tika.decompress.DecompressBuilder.java
@Override public Collection<String> getNames() { return Collections.singletonList("decompress"); }
From source file:ninja.template.TemplateEngineJsonPTest.java
@Before public void setUp() throws IOException { logger = mock(Logger.class); properties = mock(NinjaProperties.class); context = mock(Context.class); responseStreams = mock(ResponseStreams.class); result = Results.jsonp().render(Collections.singletonList(123)); objectMapper = new ObjectMapper(); outputStream = new ByteArrayOutputStream(); when(properties.getWithDefault("ninja.jsonp.callbackParameter", TemplateEngineJsonP.DEFAULT_CALLBACK_PARAMETER_NAME)).thenReturn("callback"); when(context.finalizeHeaders(result)).thenReturn(responseStreams); when(responseStreams.getOutputStream()).thenReturn(outputStream); }