package test2; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class indexof2 { public static void main(String[] args) throws IOException { // File Reading File file = new File("D:\\workspace\\test2\\src\\test2\\usecase.txt"); File filecreate = new File("D:\\workspace\\test2\\src\\test2\\sequence.txt"); FileWriter myWriter = new FileWriter("D:\\workspace\\test2\\src\\test2\\sequence.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String st,result, textFrom, textTo,left,right; left=""; right=""; String usecaseno=""; List interations= new ArrayList(); myWriter.write("@startuml"+"\n"); System.out.println("@startuml"); while ((st = br.readLine()) != null) { // For Extaction of Use case result = ""; textFrom = "usecase"; textTo= "as"; // Cut the beginning of the text to not occasionally meet a // 'textTo' value in it: try { result = st.substring(st.indexOf(textFrom) + textFrom.length(), st.length()); result = result.substring( 1, result.indexOf(textTo)-1); // Cut the excessive ending of the text: //System.out.println(result); //interations.add(result); usecaseno="UC"; } catch (Exception e) {} // For Extaction of Use case // For Extaction of Interactions starts result = ""; textFrom = ""; textTo= ""; // Cut the beginning of the text to not occasionally meet a // 'textTo' value in it: try { result = st.substring(st.indexOf(textFrom) + textFrom.length(), st.length()); result = result.substring( 0, result.indexOf(textTo)); // Cut the excessive ending of the text: //System.out.println(result); interations.add(result);// Add between Insert Card Insert Card } catch (Exception e) {} // For Extaction of Interactions ends // For Extaction of Actos with Interactions starts String stringcontain1 = "-->"; // CharSequence stringcontain2 = "<--"; // Cut the beginning of the text to not occasionally meet a // 'textTo' value in it: try { if (st.contains(stringcontain1)) { left= st.substring(0,st.indexOf(stringcontain1)); // add left side actor of Customer from Customer-->UC1 interations.add(left); // System.out.println(left); } } catch (Exception e) {} String stringcontain2 = "<--"; // CharSequence stringcontain2 = "<--"; // Cut the beginning of the text to not occasionally meet a // 'textTo' value in it: try { if (st.contains(stringcontain2)) { right= st.substring(st.indexOf(stringcontain2)+3, st.length()); // add right side actor of UC1 from Customer-->UC1 interations.add(right); interations.add(usecaseno); // System.out.println(usecaseno); } } catch (Exception e) {} // For Extaction of Actors with Interactions send } ////////////////Transformation start/////////////// int intcounter=1; while (interations.contains("UC")) { int indexof=interations.indexOf("UC"); //System.out.println(interations.get(indexof)); //left=interations.get(indexof-2); //right=interations.get(indexof-1); // System.out.println(left); // System.out.println(right); //System.out.println("Loop print"); int i=0; while (i!=indexof-2) { if(i%2==0) { //System.out.println(left+"->"+right+":"+interations.get(i)); myWriter.write(left+"->"+right+":"+intcounter+++"."+interations.get(i)+"\n"); // Customer -> ATM: 1. Insert card } else { // System.out.println(right+"->"+left+":"+interations.get(i)); myWriter.write(right+"->"+left+":"+intcounter+++"."+interations.get(i)+"\n"); } i++; } i=0; while (i<=indexof) { // System.out.println("Remove this" + interations.get(0)); interations.remove(0); i++; } } System.out.println("@enduml"); myWriter.write("@enduml"); myWriter.close(); ////////////////Transformation end/////////////// } } // https://docs.oracle.com/javase/7/docs/api/java/lang/String.html