Example usage for java.util LinkedList LinkedList

List of usage examples for java.util LinkedList LinkedList

Introduction

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

Prototype

public LinkedList(Collection<? extends E> c) 

Source Link

Document

Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    List list = new LinkedList(Collections.nCopies(10, null));
    System.out.println(list);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List stuff = Arrays.asList(new String[] { "a", "b" });

    List list = new ArrayList(stuff);
    List list2 = new LinkedList(list);

    Set set = new HashSet(stuff);
    Set set2 = new TreeSet(set);

    Map map = new HashMap();
    Map map2 = new TreeMap(map);
}

From source file:com.nexmo.client.examples.TestVoiceCall.java

public static void main(String[] argv) throws Exception {
    Options options = new Options().addOption("v", "Verbosity")
            .addOption("f", "from", true, "Phone number to call from")
            .addOption("t", "to", true, "Phone number to call")
            .addOption("h", "webhook", true, "URL to call for instructions");
    CommandLineParser parser = new DefaultParser();

    CommandLine cli;/*w w  w . j ava  2s. c  om*/
    try {
        cli = parser.parse(options, argv);
    } catch (ParseException exc) {
        System.err.println("Parsing failed: " + exc.getMessage());
        System.exit(128);
        return;
    }

    Queue<String> args = new LinkedList<String>(cli.getArgList());
    String from = cli.getOptionValue("f");
    String to = cli.getOptionValue("t");
    System.out.println("From: " + from);
    System.out.println("To: " + to);

    NexmoClient client = new NexmoClient(new JWTAuthMethod("951614e0-eec4-4087-a6b1-3f4c2f169cb0",
            FileSystems.getDefault().getPath("valid_application_key.pem")));
    client.getVoiceClient().createCall(
            new Call(to, from, "https://nexmo-community.github.io/ncco-examples/first_call_talk.json"));
}

From source file:com.buddycloud.channeldirectory.cli.Main.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception {

    JsonElement rootElement = new JsonParser().parse(new FileReader(QUERIES_FILE));
    JsonArray rootArray = rootElement.getAsJsonArray();

    Map<String, Query> queries = new HashMap<String, Query>();

    for (int i = 0; i < rootArray.size(); i++) {
        JsonObject queryElement = rootArray.get(i).getAsJsonObject();
        String queryName = queryElement.get("name").getAsString();
        String type = queryElement.get("type").getAsString();

        Query query = null;// www.j  a  v a 2  s .  c o  m

        if (type.equals("solr")) {
            query = new QueryToSolr(queryElement.get("agg").getAsString(),
                    queryElement.get("core").getAsString(), queryElement.get("q").getAsString());
        } else if (type.equals("dbms")) {
            query = new QueryToDBMS(queryElement.get("q").getAsString());
        }

        queries.put(queryName, query);
    }

    LinkedList<String> queriesNames = new LinkedList<String>(queries.keySet());
    Collections.sort(queriesNames);

    Options options = new Options();
    options.addOption(OptionBuilder.isRequired(true).withLongOpt("query").hasArg(true)
            .withDescription("The name of the query. Possible queries are: " + queriesNames).create('q'));

    options.addOption(OptionBuilder.isRequired(false).withLongOpt("args").hasArg(true)
            .withDescription("Arguments for the query").create('a'));

    options.addOption(new Option("?", "help", false, "Print this message"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        printHelpAndExit(options);
    }

    if (cmd.hasOption("help")) {
        printHelpAndExit(options);
    }

    String queryName = cmd.getOptionValue("q");
    String argsCmd = cmd.getOptionValue("a");

    Properties configuration = ConfigurationUtils.loadConfiguration();

    Query query = queries.get(queryName);
    if (query == null) {
        printHelpAndExit(options);
    }

    System.out.println(query.exec(argsCmd, configuration));

}

From source file:Main.java

public static <T> Collection<T> merge2copy(Collection<T> collection, T obj) {
    Collection<T> newCollection = new LinkedList<T>(collection);
    newCollection.add(obj);//from  w  w  w.  j  av a  2 s.  c om
    return newCollection;
}

From source file:Main.java

public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
    List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            return (o2.getValue()).compareTo(o1.getValue());
        }/*from   www. j av a2  s .c om*/
    });
    Map<K, V> result = new LinkedHashMap<K, V>();
    for (Map.Entry<K, V> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:Main.java

public static <T> Collection<T> not(Collection<T> all, Collection<T> not) {
    Collection<T> remain = new LinkedList<T>(all);
    remain.removeAll(not);//from   www .j  ava2  s.  c  o  m
    return remain;
}

From source file:Main.java

public static Byte[] toBytes(List<Byte> listBytes) {
    return toBytes(new LinkedList<Byte>(listBytes));
}

From source file:Main.java

public static <T extends Comparable<? super T>> List<T> toSortedList(Collection<T> collection) {
    List<T> list = new LinkedList<>(collection);
    Collections.sort(list);// w ww.j  a  v  a 2s . co m

    return list;
}

From source file:Main.java

public static List<Map.Entry<Long, Long>> sortEntrySetToList(Set<Map.Entry<Long, Long>> set) {
    List<Map.Entry<Long, Long>> list = new LinkedList<Map.Entry<Long, Long>>(set);
    Collections.sort(list, new Comparator<Map.Entry<Long, Long>>() {

        @Override//from  w w  w.j  av  a 2  s.  c om
        public int compare(Map.Entry<Long, Long> o1, Map.Entry<Long, Long> o2) {
            if (o1.getValue() > o2.getValue())
                return 1;
            if (o1.getValue() < o2.getValue())
                return -1;
            return 0;
        }
    });
    return list;
}