Example usage for java.util Collections singleton

List of usage examples for java.util Collections singleton

Introduction

In this page you can find the example usage for java.util Collections singleton.

Prototype

public static <T> Set<T> singleton(T o) 

Source Link

Document

Returns an immutable set containing only the specified object.

Usage

From source file:org.cloudfoundry.identity.uaa.login.ProfileControllerTests.java

public void testPostForDelete() {
    controller.setLinks(Collections.singletonMap("foo", "http://example.com"));
    Mockito.when(restTemplate.getForObject(approvalsUri, Set.class))
            .thenReturn(Collections.singleton(Collections.singletonMap("clientId", "foo")));
    Model model = new ExtendedModelMap();
    controller.post(Collections.singleton("read"), null, "", "foo", model);
    assertTrue(model.containsAttribute("links"));
    assertTrue(model.containsAttribute("approvals"));
}

From source file:ch.cyberduck.core.hubic.HubicAuthenticationResponseHandler.java

@Override
public AuthenticationResponse handleResponse(final HttpResponse response) throws IOException {
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        Charset charset = HTTP.DEF_CONTENT_CHARSET;
        ContentType contentType = ContentType.get(response.getEntity());
        if (contentType != null) {
            if (contentType.getCharset() != null) {
                charset = contentType.getCharset();
            }/*from  w ww.j a  v a 2  s.c om*/
        }
        try {
            final JsonParser parser = new JsonParser();
            final JsonObject json = parser
                    .parse(new InputStreamReader(response.getEntity().getContent(), charset)).getAsJsonObject();
            final String token = json.getAsJsonPrimitive("token").getAsString();
            final String endpoint = json.getAsJsonPrimitive("endpoint").getAsString();
            return new AuthenticationResponse(response, token,
                    Collections.singleton(new Region(null, URI.create(endpoint), null, true)));
        } catch (JsonParseException e) {
            throw new IOException(e.getMessage(), e);
        }
    } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED
            || response.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN) {
        throw new AuthorizationException(new Response(response));
    }
    throw new GenericException(new Response(response));
}

From source file:com.orange.ngsi2.model.ErrorTest.java

@Test
public void checkToString() {
    Error parseError = new Error("400", Optional.of("The incoming JSON payload cannot be parsed"),
            Optional.empty());//from   ww w.  ja va  2  s . c om
    assertEquals("error: 400 | description: The incoming JSON payload cannot be parsed | affectedItems: []",
            parseError.toString());
    parseError.setAffectedItems(Optional.of(Collections.singleton("entities")));
    assertEquals(
            "error: 400 | description: The incoming JSON payload cannot be parsed | affectedItems: [entities]",
            parseError.toString());
}

From source file:eu.fusepool.p3.transformer.sample.SimpleAsyncTransformer.java

@Override
public Set<MimeType> getSupportedInputFormats() {
    try {/*from  w  ww  . j a va 2 s .c o m*/
        MimeType mimeType = new MimeType("text/plain");
        return Collections.singleton(mimeType);
    } catch (MimeTypeParseException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.openmrs.module.kenyaemr.page.controller.MedicalChartViewPatientPageController.java

public void controller(@RequestParam("patientId") Patient patient,
        @RequestParam(required = false, value = "visitId") Visit visit,
        @RequestParam(required = false, value = "formUuid") String formUuid,
        @RequestParam(required = false, value = "patientProgramId") PatientProgram pp,
        @RequestParam(required = false, value = "section") String section, PageModel model, UiUtils ui,
        Session session, @SpringBean KenyaEmr emr) {

    if ("".equals(formUuid)) {
        formUuid = null;//from  w w w.  j a v a  2s . co m
    }

    AppUiUtil.startApp("kenyaemr.medicalChart", session);

    recentlyViewed(patient, session);

    model.addAttribute("patient", patient);
    model.addAttribute("person", patient);

    List<FormDescriptor> oneTimeFormDescriptors = emr.getFormManager().getFormsForPatient(
            "kenyaemr.medicalChart", patient, Collections.singleton(FormDescriptor.Frequency.ONCE_EVER));
    List<SimpleObject> oneTimeForms = new ArrayList<SimpleObject>();
    for (FormDescriptor formDescriptor : oneTimeFormDescriptors) {
        Form form = Context.getFormService().getFormByUuid(formDescriptor.getFormUuid());
        oneTimeForms.add(SimpleObject.create("formUuid", form.getUuid(), "label", form.getName(),
                "iconProvider", formDescriptor.getIconProvider(), "icon", formDescriptor.getIcon()));
    }
    model.addAttribute("oneTimeForms", oneTimeForms);

    model.addAttribute("programs", Context.getProgramWorkflowService().getPatientPrograms(patient, null, null,
            null, null, null, false));
    model.addAttribute("visits", Context.getVisitService().getVisitsByPatient(patient));

    Form form = null;
    String selection = null;

    if (visit != null) {
        selection = "visit-" + visit.getVisitId();
    } else if (formUuid != null) {
        selection = "form-" + formUuid;

        form = Context.getFormService().getFormByUuid(formUuid);
        List<Encounter> encounters = Context.getEncounterService().getEncounters(patient, null, null, null,
                Collections.singleton(form), null, null, null, null, false);
        Encounter encounter = encounters.size() > 0 ? encounters.get(0) : null;
        model.addAttribute("encounter", encounter);
    } else if (pp != null) {
        selection = "program-" + pp.getPatientProgramId();
    } else {
        if (StringUtils.isEmpty(section)) {
            section = "overview";
        }
        selection = "section-" + section;
    }

    model.addAttribute("form", form);
    model.addAttribute("visit", visit);
    model.addAttribute("program", pp);
    model.addAttribute("section", section);
    model.addAttribute("selection", selection);
}

From source file:no.ssb.jsonstat.v2.deser.DatasetDeserializerTest.java

@DataProvider(name = "dates")
public Object[][] getValidDates() {

    List<String> time = asList("T00:00", "T00:00:00");
    List<String> offset = asList("", "Z", "+00:00", "-00:00");
    List<String> dateTime = Lists.newArrayList(concat(asList(""), join(cartesianProduct(time, offset))));

    List<String> formats = join(
            cartesianProduct(asList("2000", "2000-01", "2000-01-01"), Lists.newArrayList(dateTime)));

    return Lists.transform(formats, input -> Collections.singleton(input).toArray()).toArray(new Object[0][]);
}

From source file:com.frequencymarketing.citi.saml.PartnerSaml.java

private SAMLResponse getSAMLResponse(TySamlProfileData memberData, String a_clientIp) throws Exception {
    String memberId = memberData.getMemberId();
    SAMLIdentifier idgen = SAMLIdentifierFactory.getInstance();

    SAMLResponse samlResponse = new SAMLResponse();
    SAMLAssertion samlAssertion = new SAMLAssertion();
    SAMLAuthenticationStatement samlAuthenticationStatement = new SAMLAuthenticationStatement();
    SAMLSubject samlSubject = new SAMLSubject(new SAMLNameIdentifier(memberId, null, null),
            Collections.singleton(SAMLSubject.CONF_BEARER), null, null);

    samlResponse.setRecipient(getSamlProps().getRecipientURL());
    samlAuthenticationStatement.setSubjectIP(a_clientIp);
    samlAuthenticationStatement.setSubject(samlSubject);
    samlAuthenticationStatement.setAuthInstant(new Date());
    samlAuthenticationStatement.setAuthMethod(SAMLAuthenticationStatement.AuthenticationMethod_Password);
    samlAssertion.addStatement(samlAuthenticationStatement);
    samlAssertion.setId(idgen.getIdentifier());
    samlAssertion.setIssuer(getSamlProps().getIssuer());
    samlAssertion.setNotBefore(new Date(System.currentTimeMillis() - 30000));
    samlAssertion.setNotOnOrAfter(new Date(System.currentTimeMillis() + 90000));//2 minutes
    samlAssertion.addCondition(new SAMLAudienceRestrictionCondition(
            Collections.singleton(getSamlProps().getAudienceRestriction())));

    //NameIdentifier is the Member id.
    SAMLAttributeStatement samlsaStatement = new SAMLAttributeStatement();
    SAMLSubject l_subject2 = new SAMLSubject(new SAMLNameIdentifier(memberId, null, null),
            Collections.singleton(SAMLSubject.CONF_BEARER), null, null);

    samlsaStatement.setSubject(l_subject2);
    samlsaStatement = addToAttributeStatement(samlsaStatement, "member_id", memberId, null, XML.SAML_NS);

    samlsaStatement = addToAttributeStatement(samlsaStatement, "agent_id", memberData.getAgentId(), null,
            XML.SAML_NS);/*from   ww  w .ja v a  2  s .  c  o  m*/

    samlsaStatement = addToAttributeStatement(samlsaStatement, "mbr_name_first", memberData.getFirstName(),
            null, XML.SAML_NS);
    samlsaStatement = addToAttributeStatement(samlsaStatement, "mbr_name_last", memberData.getLastName(), null,
            XML.SAML_NS);

    samlsaStatement = addToAttributeStatement(samlsaStatement, "point_balance", memberData.getPointBalance(),
            null, XML.SAML_NS);

    samlsaStatement = addToAttributeStatement(samlsaStatement, "email_address", memberData.getEmailAddress(),
            null, XML.SAML_NS);

    samlAssertion.addStatement(samlsaStatement);
    samlResponse.addAssertion(samlAssertion);
    samlResponse.setId(idgen.getIdentifier());

    //Load the KeyStore
    KeyStore keystore = CryptoKeystoreUtil.getKeyStore(getSamlProps().getKeystore(),
            getSamlProps().getKeystorePass().toCharArray());

    KeyPair keyPair = CryptoKeystoreUtil.getKeyPair(keystore, getSamlProps().getKeystoreAlias(),
            getSamlProps().getKeystorePass().toCharArray());

    samlResponse.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, keyPair.getPrivate(), null);

    s_logger.debug(samlResponse.toString());
    return samlResponse;
}

From source file:com.device.storefront.controllers.pages.ConfigureController.java

@RequestMapping(method = RequestMethod.GET)
public String productDetail(@PathVariable("productCode") final String productCode, final Model model,
        final HttpServletRequest request, final HttpServletResponse response)
        throws CMSItemNotFoundException, UnsupportedEncodingException {
    String redirectTo = "";
    final ProductData productData = productFacade.getProductForCodeAndOptions(productCode,
            Collections.singleton(ProductOption.GALLERY));

    if (productData.getConfigurable()) {
        final List<ConfigurationInfoData> configurations = productFacade
                .getConfiguratorSettingsForCode(productData.getCode());
        if (!configurations.isEmpty()) {
            redirectTo = configurations.get(0).getConfiguratorType().toString();
        }/*from  w w w  . ja  va2  s  .  c o m*/
    }

    final String redirection = checkRequestUrl(request, response, productDataUrlResolver.resolve(productData));
    if (StringUtils.isNotEmpty(redirection)) {
        return redirection + "/configure/" + redirectTo;
    }
    return FORWARD_PREFIX + "/404";
}

From source file:ca.uhn.fhir.rest.method.CreateMethodBinding.java

@Override
protected Set<RequestTypeEnum> provideAllowableRequestTypes() {
    return Collections.singleton(RequestTypeEnum.POST);
}

From source file:de.thomasvolk.genexample.algorithmus.KonventionellAlgorithmus.java

@Override
public WagonBelegung berechneWagon(AlgorithmusBericht algorithmusBericht) {
    algorithmusBericht.start(getWagonBelegung());
    List<Integer> passagierReihenfolge = new ArrayList<>();
    Set<SitzplatzVergabe> vergebenePlaetze = new HashSet<>();
    for (Passagier p : getPassagierListe()) {
        SitzplatzVergabe besterPlatz = null;
        int index = 0;
        int ausgewaehlterPassagierIndex = 0;
        for (Sitzplatz sp : getSitzplatzListe()) {
            SitzplatzVergabe sitzplatzVergabe = new SitzplatzVergabe(sp, p);
            if (!vergebenePlaetze.contains(sitzplatzVergabe) && !passagierReihenfolge.contains(index)) {
                if (besterPlatz == null
                        || sitzplatzVergabe.getZufriedenheit() > besterPlatz.getZufriedenheit()) {
                    besterPlatz = sitzplatzVergabe;
                    ausgewaehlterPassagierIndex = index;
                }/* www  .  jav a 2  s  .  c  o  m*/
            }
            index++;
        }
        vergebenePlaetze.add(besterPlatz);
        passagierReihenfolge.add(ausgewaehlterPassagierIndex);
    }
    WagonBelegung wagonBelegung = new WagonBelegung(getWagonBelegung().getWagon(), getPassagierListe(),
            ArrayUtils.toPrimitive(passagierReihenfolge.toArray(new Integer[getPassagierListe().length])));
    algorithmusBericht.ende(new Generation(0, Collections.singleton(wagonBelegung),
            wagonBelegung.getZufriedenheit(), wagonBelegung));
    return wagonBelegung;
}