Example usage for java.util LinkedHashSet LinkedHashSet

List of usage examples for java.util LinkedHashSet LinkedHashSet

Introduction

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

Prototype

public LinkedHashSet() 

Source Link

Document

Constructs a new, empty linked hash set with the default initial capacity (16) and load factor (0.75).

Usage

From source file:com.github.richardwilly98.esdms.api.SearchTest.java

private Set<Document> getTestDocuments(int number) {

    LinkedHashSet<Document> docs = new LinkedHashSet<Document>();

    for (int i = 0; i < number; i++) {
        String attributeKey = "attribute: " + i;
        String attributeValue = "value: " + i;
        String id = "id-" + i + " @time: " + System.currentTimeMillis();
        String name = "name-" + i + " @time: " + System.currentTimeMillis();
        String html = "<html><body><h1>This is document number: " + i + "</h1></body></html>";
        byte[] content = html.getBytes();
        Map<String, Object> attributes = newHashMap();
        attributes.put(attributeKey, attributeValue);
        // DocumentTest document = new DocumentTest(new DocumentImpl(id,
        // name, new FileImpl(content, "test.html", "text/html"),
        // attributes));
        Set<Version> versions = newHashSet();
        versions.add(new VersionImpl.Builder().documentId(id).file(new FileImpl.Builder().content(content)
                .name("test" + i + ".html").contentType("text/html").build()).current(true).versionId(1)
                .build());//from   w w w.j av a 2 s .c  om
        DocumentTest document = new DocumentTest(new DocumentImpl.Builder().versions(versions).id(id).name(name)
                .attributes(attributes).roles(null));
        // DocumentTest document = new DocumentTest(new
        // DocumentImpl.Builder().file(new
        // FileImpl.Builder().content(content).name("test" + i +
        // ".html").contentType("text/html").build()).id(id).name(name).attributes(attributes).roles(null));
        docs.add(document);
    }
    return docs;
}

From source file:com.haulmont.cuba.core.app.prettytime.CubaPrettyTimeParser.java

@PostConstruct
public void init() {
    StrTokenizer tokenizer = new StrTokenizer(serverConfig.getPrettyTimeProperties());
    try {// w w w  . j ava2s.  co  m
        for (String fileName : tokenizer.getTokenArray()) {
            InputStream stream = null;

            try {
                stream = resources.getResourceAsStream(fileName);
                if (stream == null) {
                    throw new IllegalStateException("Resource is not found: " + fileName);
                }
                InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8.name());
                Properties properties = new Properties() {
                    private Set orderedKeySet = new LinkedHashSet();

                    @Override
                    public Set<String> stringPropertyNames() {
                        return orderedKeySet;
                    }

                    @Override
                    public synchronized Object put(Object key, Object value) {
                        orderedKeySet.add(key);
                        return super.put(key, value);
                    }
                };
                properties.load(reader);
                for (String key : properties.stringPropertyNames()) {
                    String value = properties.getProperty(key);
                    replacements.put(key, value);
                }
            } finally {
                IOUtils.closeQuietly(stream);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.shenit.commons.utils.CollectionUtils.java

/**
  * ?//  w  w  w  .  j a v a  2s . c  om
  * @param vals
  * @return
  */
public static <T> Set<T> loadSortedSet(Collection<T> vals) {
    return ValidationUtils.isEmpty(vals) ? new LinkedHashSet<T>() : new LinkedHashSet<T>(vals);
}

From source file:com.spotify.hamcrest.jackson.IsJsonObject.java

@Override
protected boolean matchesNode(ObjectNode node, Description mismatchDescription) {
    LinkedHashSet<String> mismatchedKeys = new LinkedHashSet<>();
    for (Map.Entry<String, Matcher<? super JsonNode>> entryMatcher : entryMatchers.entrySet()) {
        final String key = entryMatcher.getKey();
        final Matcher<? super JsonNode> valueMatcher = entryMatcher.getValue();

        final JsonNode value = node.path(key);

        if (!valueMatcher.matches(value)) {
            mismatchedKeys.add(key);//from  w  w w  .j  av a 2s  .  c om
        }
    }

    if (!mismatchedKeys.isEmpty()) {
        describeMismatches(node, mismatchDescription, mismatchedKeys);
        return false;
    }
    return true;
}

From source file:edu.uci.ics.jung.graph.OrderedSparseMultigraph.java

@Override
public Collection<V> getPredecessors(V vertex) {
    if (!containsVertex(vertex))
        return null;

    Set<V> preds = new LinkedHashSet<V>();
    for (E edge : getIncoming_internal(vertex)) {
        if (getEdgeType(edge) == EdgeType.DIRECTED) {
            preds.add(this.getSource(edge));
        } else {//from  w w  w .  ja v  a 2 s.  c o  m
            preds.add(getOpposite(vertex, edge));
        }
    }
    return Collections.unmodifiableCollection(preds);
}

From source file:org.apache.calcite.adapter.elasticsearch.ElasticsearchSchemaFactory.java

/**
 * Builds elastic rest client from user configuration
 * @param coordinates list of {@code hostname/port} to connect to
 * @return newly initialized low-level rest http client for ES
 *//*from   w w  w  .j  av a  2s  .  co m*/
private static RestClient connect(Map<String, Integer> coordinates) {
    Objects.requireNonNull(coordinates, "coordinates");
    Preconditions.checkArgument(!coordinates.isEmpty(), "no ES coordinates specified");
    final Set<HttpHost> set = new LinkedHashSet<>();
    for (Map.Entry<String, Integer> entry : coordinates.entrySet()) {
        set.add(new HttpHost(entry.getKey(), entry.getValue()));
    }

    return RestClient.builder(set.toArray(new HttpHost[0])).build();
}

From source file:net.shibboleth.idp.oidc.client.userinfo.authn.SpringSecurityAuthenticationTokenFactory.java

/**
 * Build authentication authentication./*from www  . j  a va2s . c  o  m*/
 *
 * @param profileRequestContext the profile request context
 * @return the authentication
 */
public static Authentication buildAuthentication(final ProfileRequestContext profileRequestContext) {
    final SubjectContext principal = profileRequestContext.getSubcontext(SubjectContext.class);

    if (principal == null || principal.getPrincipalName() == null) {
        throw new OIDCException("No SubjectContext found in the profile request context");
    }

    /**
     * Grab the authentication context class ref and classify it as an authority to be used later
     * by custom token services to generate acr and amr claims.
     *
     * MitreID connect can only work with SimpleGrantedAuthority. So here we are creating specific authority
     * instances first and then converting them to SimpleGrantedAuthority. The role could be parsed later to
     * locate and reconstruct the actual instance.
     */
    final Set<GrantedAuthority> authorities = new LinkedHashSet<>();
    authorities.add(new SimpleGrantedAuthority(OIDCConstants.ROLE_USER));

    final AuthenticationContext authCtx = profileRequestContext.getSubcontext(AuthenticationContext.class);
    if (authCtx != null) {
        LOG.debug("Found an authentication context in the profile request context");

        final RequestedPrincipalContext principalContext = authCtx
                .getSubcontext(RequestedPrincipalContext.class);
        if (principalContext != null && principalContext.getMatchingPrincipal() != null) {
            LOG.debug("Found requested principal context context with matching principal {}",
                    principalContext.getMatchingPrincipal().getName());

            final AuthenticationClassRefAuthority authority = new AuthenticationClassRefAuthority(
                    principalContext.getMatchingPrincipal().getName());

            LOG.debug("Adding authority {}", authority.getAuthority());
            authorities.add(new SimpleGrantedAuthority(authority.toString()));
        }
        if (authCtx.getAuthenticationResult() != null) {
            final AuthenticationMethodRefAuthority authority = new AuthenticationMethodRefAuthority(
                    authCtx.getAuthenticationResult().getAuthenticationFlowId());
            LOG.debug("Adding authority {}", authority.getAuthority());
            authorities.add(new SimpleGrantedAuthority(authority.toString()));
        }
    }

    /**
     * Note that Spring Security loses the details object when it attempts to grab onto the authentication
     * object that is combined, when codes are asking to create access tokens.
     */
    final User user = new User(principal.getPrincipalName(), UUID.randomUUID().toString(),
            Collections.singleton(new SimpleGrantedAuthority(OIDCConstants.ROLE_USER)));

    LOG.debug("Created user details object for {} with authorities {}", user.getUsername(),
            user.getAuthorities());

    final SpringSecurityAuthenticationToken authenticationToken = new SpringSecurityAuthenticationToken(
            profileRequestContext, authorities);
    LOG.debug("Final authentication token authorities are {}", authorities);

    authenticationToken.setAuthenticated(true);
    authenticationToken.setDetails(user);
    return authenticationToken;
}

From source file:hirondelle.situris.main.centrosInteresse.FileUploadWrapper.java

/**
 Return all request parameter names, for both regular controls and file upload 
 controls./*  w  ww.  j  ava 2  s  .  c  om*/
         
 <P>Returning the name of file upload controls allows checking of the returned
 param names versus a 'white list' of expected names. This increases security, 
 which is especially important for file upload forms.
 See {@link hirondelle.web4j.security.ApplicationFirewallImpl} as well.
         
 <P>Does not include query params passed to 
 <tt>request.getRequestDispatcher(String)</tt>.
*/
@Override
public Enumeration getParameterNames() {
    Set<String> allNames = new LinkedHashSet<String>();
    allNames.addAll(fRegularParams.keySet());
    allNames.addAll(fFileParams.keySet());
    return Collections.enumeration(allNames);
}

From source file:facebook4j.TargetingParameter.java

public TargetingParameter cities(Collection<String> cities) {
    if (this.cities == null) {
        this.cities = new LinkedHashSet<String>();
    }/*w  w  w .  j  a  v a2  s . c o  m*/
    this.cities.addAll(cities);
    return this;
}

From source file:net.siegmar.japtproxy.misc.Backend.java

/**
 * @param url The host to add./*from w w  w .  java  2  s.com*/
 */
public void addUrl(final URL url) {
    if (urls == null) {
        urls = new LinkedHashSet<>();
    }

    urls.add(url);
}