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(Collection<? extends E> c) 

Source Link

Document

Constructs a new linked hash set with the same elements as the specified collection.

Usage

From source file:Main.java

/**
 * Creates a {@link Set} from incoming {@literal "varargs"}. Currently uses
 * {@link LinkedHashSet} as the {@code Set} implementation (to preserve 
 * ordering).//w  w w . j  av a2 s . c om
 * 
 * <p>Used like so:<pre>
 * for (String s : set("beep", "boop", "blorp")) { ... }</pre>
 * 
 * @param elements Items that will appear within the returned {@code Set}.
 * Cannot be {@code null}, and (for now) the items should be of the 
 * <i>same</i> type.
 * 
 * @return A {@code Set} containing the items in {@code elements}. Remember
 * that {@code Set}s only contain <i>unique</i> elements!
 */
public static <E> Set<E> set(E... elements) {
    Set<E> newSet = new LinkedHashSet<>(elements.length);
    Collections.addAll(newSet, elements);
    return newSet;
}

From source file:com.enonic.cms.core.structure.page.PageEntity.java

public PageEntity(final PageEntity page) {
    this();//from w  ww  . j av a  2s  . c  o m
    this.key = page.getKey();
    this.xmlData = page.getXmlData();
    this.template = page.getTemplate();
    this.pageWindows = new LinkedHashSet<PageWindowEntity>(page.getPageWindows());
}

From source file:eionet.cr.util.FormatUtils.java

/**
 * Returns object values for the given predicate in given langauges.
 *
 * @param predicateUri predicate URI/* w w  w.jav  a 2  s .c  o  m*/
 * @param subjectDTO SubjectDTO data object for subject
 * @param languages Set<String> language codes
 * @return String
 */
public static String getObjectValuesForPredicate(String predicateUri, SubjectDTO subjectDTO,
        List<String> languages) {
    String result = "";

    if (subjectDTO.getPredicateCount() > 0) {

        Collection<ObjectDTO> objects = subjectDTO.getObjects(predicateUri);
        if (objects != null && !objects.isEmpty()) {

            LinkedHashSet<ObjectDTO> distinctObjects = new LinkedHashSet<ObjectDTO>(objects);
            StringBuffer bufLiterals = new StringBuffer();
            StringBuffer bufNonLiterals = new StringBuffer();

            String resultFromHitSource = null;
            for (ObjectDTO objectDTO : distinctObjects) {

                String objectString = objectDTO.getValue().trim();

                // if the source of the object matches the search-hit source of the subject then
                // remember the object value and break
                if (subjectDTO.getHitSource() > 0 && objectDTO.getSourceHashSmart() == subjectDTO.getHitSource()
                        && !StringUtils.isBlank(objectString) && objectDTO.isLiteral()) {

                    resultFromHitSource = objectString;
                    break;
                }

                if (objectString.length() > 0) {

                    if (objectDTO.isLiteral()) {
                        if (languages.isEmpty() || languages.contains(objectDTO.getLanguage())) {
                            bufLiterals.append(bufLiterals.length() > 0 ? ", " : "").append(objectString);
                        }
                    } else {
                        bufNonLiterals.append(bufNonLiterals.length() > 0 ? ", " : "").append(objectString);
                    }
                }
            }

            // if there was a value found that came from search-hit source then prefer that one as the result
            if (!StringUtils.isBlank(resultFromHitSource)) {
                result = resultFromHitSource;
            } else {
                result = bufLiterals.length() > 0 ? bufLiterals.toString() : bufNonLiterals.toString();
            }
        }
    }
    return result;
}

From source file:Main.java

/**
 * Creates an empty {@link LinkedHashSet} with a given initial capacity.
 *
 * @param initialCapacity Initial capacity of the {@code LinkedHashSet}.
 * Cannot be negative.//from   w w  w.j a va  2  s.c  o m
 *
 * @return A new, empty {@code LinkedHashSet} with the given initial
 * capacity.
 */
public static <E> Set<E> newLinkedHashSet(int initialCapacity) {
    return new LinkedHashSet<>(initialCapacity);
}

From source file:enmasse.controller.flavor.FlavorManager.java

@Override
public Set<Flavor> getFlavors() {
    return new LinkedHashSet<>(flavorMap.values());
}

From source file:com.trigonic.utils.spring.beans.ImportHelper.java

public static Set<Resource> importResource(XmlBeanDefinitionReader reader, Resource sourceResource,
        String location) {//w  w w .  ja  v a2s . co  m
    location = SystemPropertyUtils.resolvePlaceholders(location); // resolve system properties: e.g. "${user.dir}"
    Set<Resource> actualResources = new LinkedHashSet<Resource>(4);

    if (isAbsoluteLocation(location)) {
        importAbsoluteResource(reader, location, actualResources);
    } else {
        importRelativeResource(reader, sourceResource, location, actualResources);
    }

    return actualResources;
}

From source file:com.yahoo.bard.webservice.util.Utils.java

/**
 * Easily turn a few instances of an object into a LinkedHashSet.
 *
 * <pre>/*from   w  w w.  j  a  v a 2 s  .c  o m*/
 * LinkedHashSet&lt;String&gt; stooges = Utils.asLinkedHashSet("Larry", "Moe", "Curly");
 * </pre>
 *
 * @param <E>  The element type for the linked hash set
 * @param e  the array from which the LinkedHashSet will be built
 *
 * @return a LinkedHashSet view of the specified array
 */
@SafeVarargs
public static <E> LinkedHashSet<E> asLinkedHashSet(E... e) {
    return new LinkedHashSet<>(Arrays.asList(e));
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.BratAttributeDecl.java

public BratAttributeDecl(String aName, Collection<String> aTargetTypes) {
    name = aName;/*from   w ww  .ja v  a2 s .  c  o  m*/
    targetTypes = aTargetTypes == null ? Collections.emptySet() : new LinkedHashSet<>(aTargetTypes);
}

From source file:com.fengduo.bee.commons.core.lang.CollectionUtils.java

/**
 * Collection c ???? Collection ??//ww w  .  ja v  a 2  s  .  c o  m
 * 
 * @param c
 * @return
 */
public static <E> Set<E> removeDups(Collection<E> c) {
    return new LinkedHashSet<E>(c);
}

From source file:brut.androlib.res.data.ResResSpec.java

public Set<ResResource> listResources() {
    return new LinkedHashSet<ResResource>(mResources.values());
}