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:com.cloudbees.jenkins.support.impl.AdministrativeMonitors.java

@Override
public Set<Permission> getRequiredPermissions() {
    return Collections.singleton(Jenkins.ADMINISTER);
}

From source file:it.geosolutions.geostore.services.rest.auditing.AuditInfoExtractorTest.java

private static HttpServletRequest getHttpServletRequest() {
    HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.1");
    Mockito.when(httpServletRequest.getRemoteHost()).thenReturn("127.0.0.1");
    Mockito.when(httpServletRequest.getRemoteUser())
            .thenReturn("User[id=2, name=admin, group=[UserGroup[id=1, groupName=everyone]], role=ADMIN]");
    Mockito.when(httpServletRequest.getServerName()).thenReturn("localhost");
    UserGroup userGroup = Mockito.mock(UserGroup.class);
    Mockito.when(userGroup.getGroupName()).thenReturn("everyone");
    User user = Mockito.mock(User.class);
    Mockito.when(user.getName()).thenReturn("admin");
    Mockito.when(user.getRole()).thenReturn(Role.ADMIN);
    Mockito.when(user.getGroups()).thenReturn(Collections.singleton(userGroup));
    Authentication authentication = Mockito.mock(Authentication.class);
    Mockito.when(authentication.getPrincipal()).thenReturn(user);
    Mockito.when(httpServletRequest.getUserPrincipal()).thenReturn(authentication);
    return httpServletRequest;
}

From source file:au.edu.anu.portal.portlets.rss.validator.SimpleRSSPreferencesValidator.java

@Override
public void validate(PortletPreferences prefs) throws ValidatorException {

    //get prefs as strings
    String max_items = prefs.getValue("max_items", Integer.toString(Constants.MAX_ITEMS));
    String feed_url = prefs.getValue(PREF_FEED_URL, null);

    //check readonly
    boolean feedUrlIsLocked = prefs.isReadOnly(PREF_FEED_URL);

    /**/*from w w w.j  av  a  2s . com*/
     * max_items
     */
    IntegerValidator integerValidator = IntegerValidator.getInstance();
    Integer maxItems = integerValidator.validate(max_items);

    //check it's a number
    if (maxItems == null) {
        throw new ValidatorException("Invalid value, must be a number", Collections.singleton("max_items"));
    }

    //check greater than or equal to a minimum of 1
    if (!integerValidator.minValue(maxItems, Constants.MIN_ITEMS)) {
        throw new ValidatorException("Invalid number, must be greater than 0",
                Collections.singleton("max_items"));
    }

    /**
     * feed_url
     */
    //only validate if it's not readonly
    if (!feedUrlIsLocked) {
        String[] schemes = { "http", "https" };
        DetailedUrlValidator urlValidator = new DetailedUrlValidator(schemes);

        //check not null
        if (StringUtils.isBlank(feed_url)) {
            throw new ValidatorException("You must specify a URL for the RSS feed",
                    Collections.singleton(PREF_FEED_URL));
        }

        //check valid scheme
        if (!urlValidator.isValidScheme(feed_url)) {
            throw new ValidatorException("Invalid feed scheme. Must be one of: " + Arrays.toString(schemes),
                    Collections.singleton(PREF_FEED_URL));
        }

        //check valid URL
        if (!urlValidator.isValid(feed_url)) {
            throw new ValidatorException("Invalid feed URL", Collections.singleton(PREF_FEED_URL));

        }
    }

    /**
     * portlet_title not validated here as it is reasonable to allow blank entry. We deal with this later
     */

}

From source file:edu.cornell.mannlib.vitro.webapp.utils.http.ContentTypeUtil.java

/**
 * The order of items in the Accept header is not important. We rely on the
 * specificity of the match and the "q" factor, in that order.
 * //from   w w w. j  av a 2 s. c  o  m
 * Since q ranges between 1.0 and 0.001, we add a specificity offset of 2, 3
 * or 4. That way, matches with equal specificity are decided by q factor.
 */
public static Set<AcceptableType> parseAcceptHeader(String acceptHeader) throws AcceptHeaderParsingException {
    if (acceptHeader == null || acceptHeader.trim().isEmpty()) {
        return Collections.singleton(new AcceptableType("*/*", "1.0"));
    }

    HeaderElement[] elements = BasicHeaderValueParser.parseElements(acceptHeader, null);

    Set<AcceptableType> acceptableTypes = new HashSet<>();
    for (HeaderElement he : elements) {
        String name = he.getName();

        NameValuePair qPair = he.getParameterByName("q");
        String qString = (qPair == null) ? "1.0" : qPair.getValue();

        acceptableTypes.add(new AcceptableType(name, qString));
    }

    return acceptableTypes;
}

From source file:com.mirth.connect.server.api.servlets.EngineServlet.java

@Override
@CheckAuthorizedChannelId//from w w w  . j  av a  2s.  c  om
public void deployChannel(String channelId, boolean returnErrors) {
    ErrorTaskHandler handler = new ErrorTaskHandler();
    engineController.deployChannels(Collections.singleton(channelId), context, handler);
    if (returnErrors && handler.isErrored()) {
        throw new MirthApiException(handler.getError());
    }
}

From source file:io.apicurio.hub.core.beans.ApiDesignResourceInfoTest.java

/**
 * Test method for {@link io.apicurio.hub.core.beans.ApiDesignResourceInfo#fromContent(java.lang.String)}.
 *//*from w w w  . j  av a  2 s . c o m*/
@Test
public void testFromContent_30_Json() throws Exception {
    String content = IOUtils.toString(
            ApiDesignResourceInfoTest.class.getResourceAsStream("ApiDesignResourceInfoTest_3.0.json"));
    ApiDesignResourceInfo info = ApiDesignResourceInfo.fromContent(content);
    Assert.assertNotNull(info);
    Assert.assertEquals(FormatType.JSON, info.getFormat());
    Assert.assertEquals("Simple OAI 3.0.0 API", info.getName());
    Assert.assertEquals("A simple API using OpenAPI 3.0.0.", info.getDescription());
    Assert.assertEquals(Collections.singleton("baz"), info.getTags());
}

From source file:it.geosolutions.geostore.rest.security.UserLdapAuthenticationProviderTest.java

@Before
public void setUp() {
    provider = new UserLdapAuthenticationProvider(new MockLdapAuthenticator(),
            new MockLdapAuthoritiesPopulator() {

                @Override/*from   www  . j  av a 2  s .co  m*/
                public Set<GrantedAuthority> getAllGroups() {
                    return Collections.singleton((GrantedAuthority) new GrantedAuthorityImpl(TEST_GROUP));
                }

            });
    userService = new MockedUserService();
    userGroupService = new MockedUserGroupService();
    provider.setUserService(userService);
    provider.setUserGroupService(userGroupService);
}

From source file:nl.surfnet.coin.selfservice.util.SpringSecurity.java

public static void setSwitchedToIdp(Csa csa, final String idpId, final String role) {
    InstitutionIdentityProvider idp = (idpId != null ? validateIdp(getIdpFromId(csa, idpId)) : null);
    CoinUser currentUser = SpringSecurity.getCurrentUser();

    if (idp == null) {
        currentUser.setAuthorities(new HashSet<>(
                Collections.singleton(new CoinAuthority(CoinAuthority.Authority.ROLE_DASHBOARD_SUPER_USER))));
    } else if (!role.isEmpty()) {
        currentUser.addAuthority(new CoinAuthority(CoinAuthority.Authority.valueOf(role)));
    }/*from w  ww.  ja  v a 2  s .com*/

    SpringSecurity.getCurrentUser().setSwitchedToIdp(idp);
}

From source file:org.callimachusproject.client.ProxyClientExecDecorator.java

public boolean removeProxy(ClientExecChain proxy) {
    return proxies.values().removeAll(Collections.singleton(proxy));
}

From source file:com.github.cchacin.JsonSchemaProcessor.java

@Override
public Set<String> getSupportedAnnotationTypes() {
    return Collections.singleton(JsonSchema.class.getCanonicalName());
}