Example usage for java.util LinkedList toString

List of usage examples for java.util LinkedList toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java

/**
 * Filters all pages in the Wikipedia XML2DB dump from the given file and
 * creates a list of page names belonging to certain categories.
 * //from   w w w . j  av  a  2 s.  c om
 * @param filename
 * @param args
 * 
 * @throws RuntimeException
 * @throws IOException
 * @throws SAXException
 * @throws FileNotFoundException
 */
private static void doDumpdbFilter(String filename, String[] args)
        throws RuntimeException, IOException, SAXException, FileNotFoundException {
    int i = 0;
    int recursionLvl = 1;
    if (args.length > i) {
        try {
            recursionLvl = Integer.parseInt(args[i]);
        } catch (NumberFormatException e) {
            System.err.println("no number: " + args[i]);
            System.exit(-1);
        }
    }
    ++i;

    String pageListFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        pageListFileName = args[i];
    } else {
        System.err.println("need a pagelist file name for filter; arguments given: " + Arrays.toString(args));
        System.exit(-1);
    }
    ++i;

    Set<String> allowedPages0 = new HashSet<String>();
    allowedPages0.add("Main Page");
    String allowedPagesFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        allowedPagesFileName = args[i];
        addFromFile(allowedPages0, allowedPagesFileName);
    }
    ++i;

    LinkedList<String> rootCategories = new LinkedList<String>();
    if (args.length > i) {
        for (String rCat : Arrays.asList(args).subList(i, args.length)) {
            if (!rCat.isEmpty()) {
                rootCategories.add(rCat);
            }
        }
    }
    WikiDumpHandler.println(System.out, "filtering by categories " + rootCategories.toString() + " ...");
    WikiDumpHandler.println(System.out, " wiki dump     : " + filename);
    WikiDumpHandler.println(System.out, " allowed pages : " + allowedPagesFileName);
    WikiDumpHandler.println(System.out, " recursion lvl : " + recursionLvl);

    WikiDumpHandler.println(System.out,
            "creating list of pages to import (recursion level: " + recursionLvl + ") ...");
    Set<String> allowedCats0 = new HashSet<String>(rootCategories);

    WikiDumpSQLiteLinkTables handler = new WikiDumpSQLiteLinkTables(filename);
    handler.setUp();
    SortedSet<String> pages = handler.getPagesInCategories(allowedCats0, allowedPages0, recursionLvl, false);
    handler.tearDown();

    do {
        FileWriter outFile = new FileWriter(pageListFileName);
        PrintWriter out = new PrintWriter(outFile);
        for (String page : pages) {
            out.println(page);
        }
        out.close();
    } while (false);
    exitCheckHandler(handler);
}

From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java

/**
 * Filters all pages in the Wikipedia XML dump from the given file and
 * creates a list of page names belonging to certain categories.
 * //www  .  j a v  a2s .  c o m
 * @param filename
 * @param args
 * 
 * @throws RuntimeException
 * @throws IOException
 * @throws SAXException
 * @throws FileNotFoundException
 */
private static void doFilter(String filename, String[] args)
        throws RuntimeException, IOException, SAXException, FileNotFoundException {
    int i = 0;
    int recursionLvl = 1;
    if (args.length > i) {
        try {
            recursionLvl = Integer.parseInt(args[i]);
        } catch (NumberFormatException e) {
            System.err.println("no number: " + args[i]);
            System.exit(-1);
        }
    }
    ++i;

    // a timestamp in ISO8601 format
    Calendar maxTime = null;
    if (args.length > i && !args[i].isEmpty()) {
        try {
            maxTime = Revision.stringToCalendar(args[i]);
        } catch (IllegalArgumentException e) {
            System.err.println("no date in ISO8601: " + args[i]);
            System.exit(-1);
        }
    }
    ++i;

    String pageListFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        pageListFileName = args[i];
    } else {
        System.err.println("need a pagelist file name for filter; arguments given: " + Arrays.toString(args));
        System.exit(-1);
    }
    ++i;

    Set<String> allowedPages = new HashSet<String>();
    allowedPages.add("Main Page");
    String allowedPagesFileName = "";
    if (args.length > i && !args[i].isEmpty()) {
        allowedPagesFileName = args[i];
        addFromFile(allowedPages, allowedPagesFileName);
    }
    ++i;

    LinkedList<String> rootCategories = new LinkedList<String>();
    if (args.length > i) {
        for (String rCat : Arrays.asList(args).subList(i, args.length)) {
            if (!rCat.isEmpty()) {
                rootCategories.add(rCat);
            }
        }
    }
    WikiDumpHandler.println(System.out, "filtering by categories " + rootCategories.toString() + " ...");
    WikiDumpHandler.println(System.out, " wiki dump     : " + filename);
    WikiDumpHandler.println(System.out, " max time      : " + maxTime);
    WikiDumpHandler.println(System.out, " allowed pages : " + allowedPagesFileName);
    WikiDumpHandler.println(System.out, " recursion lvl : " + recursionLvl);
    SortedSet<String> pages = getPageList(filename, maxTime, allowedPages, rootCategories, recursionLvl);

    do {
        FileWriter outFile = new FileWriter(pageListFileName);
        PrintWriter out = new PrintWriter(outFile);
        for (String page : pages) {
            out.println(page);
        }
        out.close();
    } while (false);
}

From source file:net.iubris.ipc_d3.cap.CamelizeSomeFieldsAndExtractInformazioniStoricheDates.java

private JSONArray adjustTimeAndTipiSpecifici(String dataAsCSV) throws ParseException {
    JSONArray jsonArray = CDL.toJSONArray(dataAsCSV);
    int length = jsonArray.length();
    JSONArray jsonArrayNew = new JSONArray();
    for (int i = 0; i < length; i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);

        JSONObject jsonObjectNew = new JSONObject();

        jsonObjectNew.put("nome", jsonObject.getString("nome"));
        jsonObjectNew.put("indirizzo", jsonObject.getString("indirizzo"));
        jsonObjectNew.put("numeroCivico", jsonObject.getString("numero-civico"));
        jsonObjectNew.put("cap", jsonObject.getString("cap"));
        jsonObjectNew.put("quartiere", jsonObject.getString("quartiere"));
        jsonObjectNew.put("citta", jsonObject.getString("citta"));
        jsonObjectNew.put("geolocazione", jsonObject.getString("geolocazione"));
        jsonObjectNew.put("telefono", jsonObject.getString("telefono"));
        jsonObjectNew.put("mobile", jsonObject.getString("mobile"));
        jsonObjectNew.put("email", jsonObject.getString("email"));
        jsonObjectNew.put("web", jsonObject.getString("web"));
        jsonObjectNew.put("tipi", jsonObject.getString("tipi"));
        jsonObjectNew.put("tipiSpecifici", jsonObject.getString("tipi-specifici"));

        //         jsonObjectNew.put("tipiSpecificiReduced", getTipiReduced(jsonObject));
        //         jsonObjectNew.put("times", getTimes(jsonObject));

        LinkedList<String> date = findNumbers(jsonObject.getString("luogo-da-visitare.informazioni_storiche"));
        String dateString = date.toString().replace("[", "").replace("]", "");
        jsonObjectNew.put("luoghiDaVisitare.informazioniStoriche.date", dateString);

        jsonArrayNew.put(jsonObjectNew);
    }/*from www.j av a2  s.  c o m*/
    return jsonArrayNew;
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenLastItemIsMissing() {
    final ArrayList<String> listA = Lists.newArrayList("AA", "BB", "CC");
    final ArrayList<String> listB = Lists.newArrayList("AA", "BB");

    final DataDiffUtil<String> util = new DataDiffUtil<String>();
    final LinkedList<DataDiffUtil.Diff<String>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(), equalTo("[Diff(EQUAL,\"[AA, BB]\"), Diff(DELETE,\"[CC]\")]"));
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenFirstItemIsExtra() {
    final ArrayList<Double> listA = Lists.newArrayList(1.1, 2.2, 3.3);
    final ArrayList<Double> listB = Lists.newArrayList(2.2, 3.3);

    final DataDiffUtil<Double> util = new DataDiffUtil<Double>();
    final LinkedList<DataDiffUtil.Diff<Double>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(), equalTo("[Diff(DELETE,\"[1.1]\"), Diff(EQUAL,\"[2.2, 3.3]\")]"));
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenFirstItemIsMissing() {
    final ArrayList<Double> listA = Lists.newArrayList(2.2, 3.3);
    final ArrayList<Double> listB = Lists.newArrayList(1.1, 2.2, 3.3);

    final DataDiffUtil<Double> util = new DataDiffUtil<Double>();
    final LinkedList<DataDiffUtil.Diff<Double>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(), equalTo("[Diff(INSERT,\"[1.1]\"), Diff(EQUAL,\"[2.2, 3.3]\")]"));
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenLastItemIsExtra() {
    final ArrayList<Integer> listA = Lists.newArrayList(1, 2, 3);
    final ArrayList<Integer> listB = Lists.newArrayList(1, 2, 3, 4);

    final DataDiffUtil<Integer> util = new DataDiffUtil<Integer>();
    final LinkedList<DataDiffUtil.Diff<Integer>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(), equalTo("[Diff(EQUAL,\"[1, 2, 3]\"), Diff(INSERT,\"[4]\")]"));
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenFirstItemIsDifferent() {
    final ArrayList<Double> listA = Lists.newArrayList(1.1, 2.2, 3.3);
    final ArrayList<Double> listB = Lists.newArrayList(0.0, 2.2, 3.3);

    final DataDiffUtil<Double> util = new DataDiffUtil<Double>();
    final LinkedList<DataDiffUtil.Diff<Double>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(),
            equalTo("[Diff(DELETE,\"[1.1]\"), Diff(INSERT,\"[0.0]\"), Diff(EQUAL,\"[2.2, 3.3]\")]"));
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenMiddleItemIsExtra() {
    final ArrayList<Character> listA = Lists.newArrayList('a', 'b', 'c');
    final ArrayList<Character> listB = Lists.newArrayList('a', 'c');

    final DataDiffUtil<Character> util = new DataDiffUtil<Character>();
    final LinkedList<DataDiffUtil.Diff<Character>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(), equalTo("[Diff(EQUAL,\"[a]\"), Diff(DELETE,\"[b]\"), Diff(EQUAL,\"[c]\")]"));
}

From source file:org.trnltk.experiment.morphology.ambiguity.DataDiffUtilTest.java

@Test
public void shouldComputeDiff_whenMiddleItemIsMissing() {
    final ArrayList<Character> listA = Lists.newArrayList('a', 'c');
    final ArrayList<Character> listB = Lists.newArrayList('a', 'x', 'c');

    final DataDiffUtil<Character> util = new DataDiffUtil<Character>();
    final LinkedList<DataDiffUtil.Diff<Character>> diffs = util.diff_main(listA, listB);

    assertThat(diffs.toString(), equalTo("[Diff(EQUAL,\"[a]\"), Diff(INSERT,\"[x]\"), Diff(EQUAL,\"[c]\")]"));
}