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.thoughtworks.go.util.Csv.java

private Set<String> fields() {
    Set<String> fields = new LinkedHashSet<>();
    for (CsvRow row : data) {
        fields.addAll(row.fields());/*www .j  a  v a 2s. c  o m*/
    }
    return fields;
}

From source file:cc.recommenders.utils.dictionary.Dictionary.java

public Set<T> getAllEntries() {
    Set<T> allEntries = new LinkedHashSet<T>();
    allEntries.addAll(entries);
    return allEntries;
}

From source file:org.jhk.pulsing.pulse.TrendingPulseSubTest.java

@Test
public void testReadConversion() {

    Set<String> testData = new LinkedHashSet<>();

    try {/*from w w  w .j a v  a 2s  . c o m*/

        testData.add(_objectMapper.writeValueAsString(createTempMap()));

        Map<Long, String> tpSubscriptions = PulseServiceUtil.processTrendingPulseSubscribe(testData,
                _objectMapper);

        assertTrue("Size equal?", tpSubscriptions.size() == _validResult.size());

        Iterator<Entry<Long, String>> validIterator = _validResult.entrySet().iterator();
        Iterator<Entry<Long, String>> tpProcessedIterator = tpSubscriptions.entrySet().iterator();

        int loop = 0;
        while (validIterator.hasNext() && tpProcessedIterator.hasNext()) {
            Entry<Long, String> vEntry = validIterator.next();
            Entry<Long, String> tpEntry = tpProcessedIterator.next();

            assertTrue("For loop " + loop + " check " + vEntry + "-" + tpEntry, vEntry.equals(tpEntry));
            loop++;
        }

    } catch (JsonProcessingException jpException) {
        assertTrue("Error while writing to string " + jpException.getMessage(), false);
    }

}

From source file:io.milton.http.webdav.DefaultPropFindRequestFieldParser.java

@Override
public PropertiesRequest getRequestedFields(InputStream in) {
    final Set<QName> set = new LinkedHashSet<QName>();
    try {//from   ww w .  j  a v  a  2s.  c  o m
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        StreamUtils.readTo(in, bout, false, true);
        byte[] arr = bout.toByteArray();
        if (arr.length > 1) {
            ByteArrayInputStream bin = new ByteArrayInputStream(arr);
            XMLReader reader = XMLReaderFactory.createXMLReader();
            reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            PropFindSaxHandler handler = new PropFindSaxHandler();
            reader.setContentHandler(handler);
            try {
                reader.parse(new InputSource(bin));
                if (handler.isAllProp()) {
                    return new PropertiesRequest();
                } else {
                    set.addAll(handler.getAttributes().keySet());
                }
            } catch (IOException e) {
                log.warn("exception parsing request body", e);
                // ignore
            } catch (SAXException e) {
                log.warn("exception parsing request body", e);
                // ignore
            }
        }
    } catch (Exception ex) {
        // There's a report of an exception being thrown here by IT Hit Webdav client
        // Perhaps we can just log the error and return an empty set. Usually this
        // class is wrapped by the MsPropFindRequestFieldParser which will use a default
        // set of properties if this returns an empty set
        log.warn("Exception parsing PROPFIND request fields. Returning empty property set", ex);
        //throw new RuntimeException( ex );
    }
    return PropertiesRequest.toProperties(set);
}

From source file:mobile.service.UserService.java

/**
 * ?/*www .  j  a v a2s .c om*/
 *
 * @param size ??
 * @return
 */
public static List<TopUser> getTopUserList(int size) {
    Set<TopExpert> tops = new LinkedHashSet<>();
    List<TopCate> cates = SkillTag.getTopCateWithCache();
    boolean isContinue = false;
    int counter = 0;
    do {
        isContinue = false;
        for (TopCate topCate : cates) {
            List<TopExpert> topExperts = topCate.getTopExperts();
            if (counter < topExperts.size()) {
                tops.add(topExperts.get(counter));
                if (tops.size() >= size) {
                    isContinue = false;
                    break;
                } else {
                    isContinue = true;
                }
            }
        }
        counter++;
    } while (isContinue);

    List<TopUser> list = new ArrayList<>();
    for (TopExpert expert : tops) {
        list.add(TopUser.create(expert));
    }

    return list;
}

From source file:de.jcup.egradle.codeassist.dsl.PluginMerger.java

public void merge(Set<Plugin> plugins) {
    Set<Type> set = new LinkedHashSet<>();

    /* collect all target types */
    for (Plugin plugin : plugins) {
        for (TypeExtension extension : plugin.getExtensions()) {
            String targetTypeAsString = extension.getTargetTypeAsString();
            Type targetType = provider.getType(targetTypeAsString);
            set.add(targetType);/*w w w.j  av a2  s  .c  om*/
        }
    }

    /* now for each type we do the merge */
    for (Type type : set) {
        merge(type, plugins);
    }
}

From source file:com.mapr.drill.maprdb.tests.index.LargeTableGenBase.java

protected void initDictionaryWithRand() {
    {//  w w  w . j  a  v a 2  s.co  m
        firstnames = new ArrayList<>();
        lastnames = new ArrayList<>();
        cities = new ArrayList<>();
        List<String> states = new ArrayList<>();

        int fnNum = 2000; // 2k
        int lnNum = 200000; // 200k
        int cityNum = 10000; // 10k
        int stateNum = 50;
        Random rand = new Random(2017);
        int i;
        try {
            Set<String> strSet = new LinkedHashSet<>();
            while (strSet.size() < stateNum) {
                strSet.add(RandomStringUtils.random(2, 0, 0, true, false, null, rand));
            }
            states.addAll(strSet);

            strSet = new LinkedHashSet<>();
            while (strSet.size() < cityNum) {
                int len = 3 + strSet.size() % 6;
                strSet.add(RandomStringUtils.random(len, 0, 0, true, false, null, rand));
            }

            Iterator<String> it = strSet.iterator();
            for (i = 0; i < cityNum; ++i) {
                cities.add(new String[] { "10000", states.get(i % stateNum), it.next() });
            }

            strSet = new LinkedHashSet<>();
            while (strSet.size() < fnNum) {
                int len = 3 + strSet.size() % 6;
                strSet.add(RandomStringUtils.random(len, 0, 0, true, false, null, rand));
            }
            firstnames.addAll(strSet);

            strSet = new LinkedHashSet<>();
            while (strSet.size() < lnNum) {
                int len = 3 + strSet.size() % 6;
                strSet.add(RandomStringUtils.random(len, 0, 0, true, false, null, rand));
            }
            lastnames.addAll(strSet);
        } catch (Exception e) {
            System.out.println("init data got exception");
            e.printStackTrace();
        }
        dict_ready = true;
    }
}

From source file:edu.uci.ics.jung.algorithms.cluster.BicomponentClusterer.java

/**
* Extracts the bicomponents from the graph.
* @param theGraph the graph whose bicomponents are to be extracted
* @return the <code>ClusterSet</code> of bicomponents
*//* w  w w  .  j  a v a 2  s .  co m*/
public Set<Set<V>> transform(UndirectedGraph<V, E> theGraph) {
    Set<Set<V>> bicomponents = new LinkedHashSet<Set<V>>();

    if (theGraph.getVertices().isEmpty())
        return bicomponents;

    // initialize DFS number for each vertex to 0
    dfs_num = new HashMap<V, Number>();
    for (V v : theGraph.getVertices()) {
        dfs_num.put(v, 0);
    }

    for (V v : theGraph.getVertices()) {
        if (dfs_num.get(v).intValue() == 0) // if we haven't hit this vertex yet...
        {
            high = new HashMap<V, Number>();
            stack = new Stack<E>();
            parents = new HashMap<V, V>();
            converse_depth = theGraph.getVertexCount();
            // find the biconnected components for this subgraph, starting from v
            findBiconnectedComponents(theGraph, v, bicomponents);

            // if we only visited one vertex, this method won't have
            // ID'd it as a biconnected component, so mark it as one
            if (theGraph.getVertexCount() - converse_depth == 1) {
                Set<V> s = new HashSet<V>();
                s.add(v);
                bicomponents.add(s);
            }
        }
    }

    return bicomponents;
}

From source file:de.vandermeer.skb.interfaces.messagesets.IsErrorSetFT.java

/**
 * Creates a new error set./*from w w  w. j a  v  a  2  s .  c  o  m*/
 * @return new error set
 */
static IsErrorSetFT create() {
    return new IsErrorSetFT() {
        final Set<FormattingTuple> errorSet = new LinkedHashSet<>();

        @Override
        public Set<FormattingTuple> getErrorMessages() {
            return this.errorSet;
        }
    };
}

From source file:fredboat.command.music.control.SelectCommand.java

static void select(CommandContext context) {
    Member invoker = context.invoker;
    GuildPlayer player = PlayerRegistry.getOrCreate(context.guild);
    VideoSelection selection = VideoSelection.get(invoker);
    if (selection == null) {
        context.reply(context.i18n("selectSelectionNotGiven"));
        return;/*from   w w w. j  av  a 2s .com*/
    }

    try {
        //Step 1: Parse the issued command for numbers

        // LinkedHashSet to handle order of choices + duplicates
        LinkedHashSet<Integer> requestChoices = new LinkedHashSet<>();

        // Combine all args and the command trigger. if the trigger is not a number it will be sanitized away
        String commandOptions = (context.trigger + " " + context.rawArgs).trim();
        String sanitizedQuery = sanitizeQueryForMultiSelect(commandOptions).trim();

        if (StringUtils.isNumeric(commandOptions)) {
            requestChoices.add(Integer.valueOf(commandOptions));
        } else if (TextUtils.isSplitSelect(sanitizedQuery)) {
            // Remove all non comma or number characters
            String[] querySplit = sanitizedQuery.split(",|\\s");

            for (String value : querySplit) {
                if (StringUtils.isNumeric(value)) {
                    requestChoices.add(Integer.valueOf(value));
                }
            }
        }

        //Step 2: Use only valid numbers (usually 1-5)

        ArrayList<Integer> validChoices = new ArrayList<>();
        // Only include valid values which are 1 to <size> of the offered selection
        for (Integer value : requestChoices) {
            if (1 <= value && value <= selection.choices.size()) {
                validChoices.add(value);
            }
        }

        //Step 3: Make a selection based on the order of the valid numbers

        // any valid choices at all?
        if (validChoices.isEmpty()) {
            throw new NumberFormatException();
        } else {
            AudioTrack[] selectedTracks = new AudioTrack[validChoices.size()];
            StringBuilder outputMsgBuilder = new StringBuilder();

            for (int i = 0; i < validChoices.size(); i++) {
                selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1);

                String msg = context.i18nFormat("selectSuccess", validChoices.get(i),
                        selectedTracks[i].getInfo().title,
                        TextUtils.formatTime(selectedTracks[0].getInfo().length));
                if (i < validChoices.size()) {
                    outputMsgBuilder.append("\n");
                }
                outputMsgBuilder.append(msg);

                player.queue(new AudioTrackContext(selectedTracks[i], invoker));
            }

            VideoSelection.remove(invoker);
            TextChannel tc = FredBoat.getTextChannelById(selection.channelId);
            if (tc != null) {
                CentralMessaging.editMessage(tc, selection.outMsgId,
                        CentralMessaging.from(outputMsgBuilder.toString()));
            }

            player.setPause(false);
            context.deleteMessage();
        }
    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        context.reply(context.i18nFormat("selectInterval", selection.choices.size()));
    }
}