123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package group04;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class nodeOptConsol {
- public static BasicNode current = null;
- private static ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springmvc-config.xml");
- public static ClassPathXmlApplicationContext getContext()
- {
- return context;
- }
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- //nums.add(1);
- String command = "";
- while(true)
- {
- try
- {
- if(current != null) System.out.print(current.getClass() + "#" + current.getId());
- System.out.print(">");
- command = br.readLine();
- }
- catch (Exception e)
- {
- System.out.println("errer : " + e.toString());
- }
- String[] prams = command.split(" ");
- command = prams[0];
- if(prams.length > 1)
- {
- prams = Arrays.copyOfRange(prams, 1, prams.length);
- }
- // System.out.println(command);
- switch(command.toLowerCase())
- {
- //select node from database or loaded node
- case "sel":
- if(prams.length > 0)
- {
- try
- {
- long id = Long.valueOf(prams[0]);
- current = NodeDao.loadNodeTreeById(id);
- }
- catch(NumberFormatException ex)
- {
- System.out.println("can't id press to number");
- }
- }
- break;
- case "log":
- System.out.println(current);
- break;
- //parent node
- case "par":
- if(current != null) current = current.getParentNode();
- break;
- //list node
- case "ls":
- if(current != null) System.out.println(current.getChildLevel());
- else System.out.println("null");
- break;
- //move node to
- case "mov":
- if(prams.length > 0)
- {
- try
- {
- long id = Long.valueOf(prams[0]);
- BasicNode target = NodeDao.loadNodeTreeById(id);
- if(target != null)
- {
- if(prams.length > 1)
- {
- switch(prams[1].toLowerCase())
- {
- //next of target
- case "/n":
- target.insertNext(current);
- break;
- //previous node of target
- case "/p":
- target.insertPerv(current);
- break;
- }
- }
- else
- {
- target.insertNext(current);
- }
- }
- }
- catch(NumberFormatException ex)
- {
- System.out.println("can't id press to number");
- }
- }
- break;
- //replace node
- case "rp":
- if(prams.length > 0)
- {
- try
- {
- long id = Long.valueOf(prams[0]);
- BasicNode target = NodeDao.loadNodeTreeById(id);
- if(target != null)
- {
- if(prams.length > 1)
- {
- switch(prams[1].toLowerCase())
- {
- //replace current
- case "/c":
- current.replaceBy(target);
- current = target;
- break;
- //replace target
- case "/t":
- target.replaceBy(current);
- break;
- case "/e":
- current.exchangeWith(target);
- break;
- }
- }
- else
- {
- current.replaceBy(target);
- current = target;
- }
- }
- }
- catch(NumberFormatException ex)
- {
- System.out.println("can't id press to number");
- }
- }
- break;
- //create node
- case "new":
- if(prams.length > 0)
- {
- try
- {
- long id = Long.valueOf(prams[0]);
- BasicNode newNode = new BasicNode(id);
- if(newNode.defineded()) current = newNode;
- }
- catch(NumberFormatException ex)
- {
- System.out.println("can't id press to number");
- }
- }
- break;
- case "del":
- if(current != null) current.deleteNode();
- current = null;
- break;
- //set level parent node
- case "slp":
- if(prams.length > 0)
- {
- try
- {
- long id = Long.valueOf(prams[0]);
- BasicNode target = NodeDao.loadNodeTreeById(id);
- if(target != null)
- {
- target.setChildLevel(current);
- }
- }
- catch(NumberFormatException ex)
- {
- System.out.println("can't id press to number");
- }
- }
- break;
- //join child level
- case "jcl":
- if(prams.length > 0)
- {
- try
- {
- long id = Long.valueOf(prams[0]);
- BasicNode target = NodeDao.loadNodeTreeById(id);
- if(target != null)
- {
- if(target.getChildLevel() == null)
- {
- if(current != null)
- {
- current.dropFromLevel();
- target.setChildLevel(current);
- }
- }
- else
- {
- target.getChildLevel().endOfNodeLevel().insertNext(current);
- }
- }
- }
- catch(NumberFormatException ex)
- {
- System.out.println("can't id press to number");
- }
- }
- break;
- case "ex":
- BasicNode.checkAndUploadAll();
- return;
- }
- }
- }
-
- }
|