import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.jsoup.Jsoup;

import java.io.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by eri on 1/14/16.
 */
public class Test {


    public static void main(String[] args) throws ParseException, IOException {


        File fs = new File("C:\\Users\\eri_k\\Downloads\\relation_proj");

        StringBuilder sb = new StringBuilder();

        try (BufferedReader br = new BufferedReader(new FileReader(fs))) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] split = line.split("!");
                sb.append(split[0] + "!" + split[1] + "!" + split[4] + "!" + split[3] + "!" + split[2] + "\n");
//                resultProject!result!corda__h2020::c0210cb8b2256f4ca08d18391ae137c0!project!od______1108::18ddc87d7409554b58d0a230b533e516!

            }
        }

        System.out.println(sb.toString());


        File fs2 = new File("C:\\Users\\eri_k\\Downloads\\relations_fixed");
        FileWriter fw = new FileWriter(fs2);

        fw.write(sb.toString());
        fw.close();



    /*    String date = "2015-05-26";

        DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
        System.out.println(formatter.parseDateTime(date));
        DateFormat df = new SimpleDateFormat("yyyy-mm-dd");
        System.out.println(df.parse(date));


        String value = " \"lala\" /lo {}li?   la ";

        value = "i";

        System.out.println("value " + value);
        value = value.replace(" ", "");
        System.out.println("value " + value);
        value = value.replace(" ", "");

        value="Gary  Richard,Lewin ,Lewin % Gary > Richard>";
        value = value.replaceAll("[\"\\r\\\\;]", "");

        value = value.replaceAll("[^a-zA-Z0-9 .-_:/&!@+=]+", " ");
        System.out.println("VALUE IS" + value);


        value="http://dx.doi.org/10.17014/ijog.vol1no2.20063-Papandayan-is-an-A-type-active-strato-volcano-located-at-some-20-km-SW-of-Garut-or-about-70-km-SE-of-Bandung-the-capital-city-of-West-Java-Province.-Geographically-the-summit-of-this-volcano-lies-at-the-intersection-between-07--19--42--S-and-107--44--E.-The-2002-Papandayan-eruption-was-preceded-by-two-felt-earthquakes-8-times-of-A-type-volcanic-earthquakes-and-150-times-of-B--type-volcanic-earthquake.-These-events-were-followed-by-a-phreatic-eruption-that-took-place-on-11-November-at-16.02-local-time.-Field-observation-shows-that-the-summit-region-mainly-around-the-craters-consists-of-rocks-that-have-hydrothermally-altered-to-yield-clay-rich-material.-This-clay-rich-material-covers-most-of-the-crater-fl-oors-and-the-crater-rim.-Mount-Nangklak-that-forms-part-of-the-rim-also-contains-a-lava-plug-from-the-Old-Papandayan-volcano.-This-mountain-is-covered-by-fi-ne-grained-unconsolidated-material-and-altered-rocks.-Much-of-this-altered-rocks-coincides-with-solfataric-and-fumarolic-activities-of-80-to->-300-C.-The-summit-area-also-contains-high-discharge-of-water-either-originating-from-the-springs-or-surface-water.-The-increase-in-seismicity-the-fi-ne-grained-hydrothermal-altered-rocks-and-the-existence-of-some-faults-that-pass-through-the-summit-region-might-have-weaken-the-stability-of-the-summit-area.-As-the-result-a-landslide-occurred-on-the-north-fl-ank-of-Mount-Nangklak-where-the-landslide-material-blocked-the-upper-course-of-Cibeureum-Gede-River.-This-landslide-material-had-formed-big-mudfl-ows-that-caused-several-houses-of-fi-ve-villages-were-partly-burried-some-bridges-were-devastated-and-several-hectares-of-cultivated-land-were-damaged.\n" +
                "\tat java.net.URI$Parser.fail(URI.java:2829)";
        System.out.println("char is " +value.charAt(1057) + value.charAt(1058));


        value="http://dx.doi.org/10.5902/1984686X5486-O-objetivo-deste-estudo-foi-descrever-o-processo-de-valida-o-de-conte-do-de-um-instrumento-de-avalia-o-do-esquema-corporal-para-crian-as-comcegueira-cong-nita-com-idade-entre-6-e-9-anos.-A-popula-o-foi-constitu-dapor-sete-professores-universit-rios-os-quais-receberam-uma-primeiravers-o-do-instrumento-eles-analisaram-cada-item-nos-quesitos-clareza-delinguagem-pertin-ncia-te-rica-viabilidade-de-aplica-o-e-adequa-o-aoconstructo.-A-prova-1--obteve-80%-de-concord-ncia-a-Prova-2-recebeu-70%-a-prova-3---60%-e-a-prova-4--75%.-Adotou-se-como-crit-rio-de-perman-nciada-prova-o-m-nimo-de-80%-de-concord-ncia.-A-prova-1-permaneceu-como-naprimeira-vers-o-a-prova-2-foi-exclu-da-e-as-provas-3-e-4-foram-modificadas.-Com-base-nas-sugest-es-dos-ju-zes-e-no--ndice-de-concord-ncia-elaborou-se-uma-segunda-vers-o-do-instrumento-composta-por-tr-s-itens.-Com-isso-foi-poss-vel-considerar-que-as-adapta-es-sugeridas-pelos-ju-zes-foram-importantes-para-garantir-a-validade-de-conte-do-do-instrumento.-Palavras-chave:-Educa-o-Especial-Educa-o-F-sica-adaptada-Cegueira-Avalia-o-Esquema-corporal.\n" +
                "java.net.URISyntaxException: Malformed escape pair at index 489: http://dx.doi.org/10.5902/1984686X5486-O-objetivo-deste-estudo-foi-descrever-o-processo-de-valida-o-de-conte-do-de-um-instrumento-de-avalia-o-do-esquema-corporal-para-crian-as-comcegueira-cong-nita-com-idade-entre-6-e-9-anos.-A-popula-o-foi-constitu-dapor-sete-professores-universit-rios-os-quais-receberam-uma-primeiravers-o-do-instrumento-eles-analisaram-cada-item-nos-quesitos-clareza-delinguagem-pertin-ncia-te-rica-viabilidade-de-aplica-o-e-adequa-o-aoconstructo.-A-prova-1--obteve-80%-de-concord-ncia-a-Prova-2-recebeu-70%-a-prova-3---60%-e-a-prova-4--75%.-Adotou-se-como-crit-rio-de-perman-nciada-prova-o-m-nimo-de-80%-de-concord-ncia.-A-prova-1-permaneceu-como-naprimeira-vers-o-a-prova-2-foi-exclu-da-e-as-provas-3-e-4-foram-modificadas.-Com-base-nas-sugest-es-dos-ju-zes-e-no--ndice-de-concord-ncia-elaborou-se-uma-segunda-vers-o-do-instrumento-composta-por-tr-s-itens.-Com-isso-foi-poss-vel-considerar-que-as-adapta-es-sugeridas-pelos-ju-zes-foram-importantes-para-garantir-a-validade-de-conte-do-do-instrumento.-Palavras-chave:-Educa-o-Especial-Educa-o-F-sica-adaptada-Cegueira-Avalia-o-Esquema-corporal.\n" +
                "\tat java.net.URI$Parser.fail(URI.java:2829)";


        System.out.println("malformed escaped pair char is " +value.charAt(489) +value.charAt(490) );


        *//*value = value.replace("\\r", " ");
        value = value.replace("\\", "");
		*//*

		 *//*value = value.replace("\\r", " ");
         value = value.replace("\\", "");
*//*


        value = "http://dx.doi.org/10.5902/198050985739<br /><br />O presente trabalho objetivou avaliar a capacidade de adesão da madeira serrada de eucalipto proveniente de três sistemas de manejo, empregando-se os adesivos: resorcina formaldeído, e dois adesivos em emulsão aquosa à base de poliacetato de vinila. Os sistemas de manejo foram caracterizados por três estratos, sendo o estrato um (E1) caracterizado por madeira proveniente de talhadia e idade de 70 meses; o estrato dois (E2) caracterizado por madeira de reforma e idade de 166 meses e o estrato três (E3) caracterizado também por reforma aos 70 meses de idade.";


        System.out.println(Jsoup.parse(value).text());


        List<String> s = new ArrayList<String>();
        s.add("A");
        s.add("B");
        s.add("C");
        s.add("D");
        int listSize= s.size();
        List<String> newList= new ArrayList<String>();
String DELIM=";";
        String valueEntity="result";

        for(int i=0; i< s.size()-1;i++)
        {
            System.out.println(i);
            for(int j=i+1; j<s.size();j++)
            {System.out.println("j is " +j);
                newList.add("dedup" + DELIM +
                        valueEntity + DELIM +
                        s.get(i) + DELIM +
                        valueEntity+ DELIM+
                        s.get(j) + DELIM);


            }
        }


        System.out.println(newList);

*/

        //  MyString.formStrings("");
    }

    public static List<List<String>> generatePerm(List<String> original) {
        if (original.size() == 0) {
            List<List<String>> result = new ArrayList<List<String>>();
            result.add(new ArrayList<String>());
            return result;
        }
        String firstElement = original.remove(0);
        List<List<String>> returnValue = new ArrayList<List<String>>();

        List<List<String>> permutations = generatePerm(original);

        for (List<String> smallerPermutated : permutations) {
            for (int index = 0; index <= smallerPermutated.size(); index++) {
                List<String> temp = new ArrayList<String>(smallerPermutated);
                temp.add(index, firstElement);
                returnValue.add(temp);
            }
        }
        return returnValue;
    }

    public static class MyString {

        static final String[] chars = {"a", "b", "c"};
        static final int reqLen = 2;

        public static void formStrings(String crtStr) {

            if (crtStr.length() == reqLen) {
                System.out.println(crtStr);
                return;
            } else
                for (int i = 1; i < chars.length; i++) {
                    if (!crtStr.contains(chars[i] + crtStr))
                        formStrings(crtStr + chars[i]);
                    else {
                        formStrings(crtStr);

                    }

                }
        }
    }


    static void fillList(ArrayList list) {
        list.add("lala");

    }

}