@Test public void shouldCacheResults() throws Exception { TaskModel root = taskModel("text\n"); List<Content> first = root.getChildren(); List<Content> second = root.getChildren(); assertSame(first, second); }
@Test public void shouldResolveAllContainedTasksOfAProject() throws Exception { TaskModel root = taskModel("project:\n" + " note\n" + " - task\n" + "project2:\n" + " note2\n"); EList<Content> contents = root.getContents(); assertThat(contentsOf((Project) contents.get(0)), is(array("note", "task"))); assertThat(contentsOf((Project) contents.get(3)), is(array("note2"))); }
public boolean checkDefault() { if (arguments.length != model.getDefaultArgTypes().length) return false; for (int index = 0; index < model.getDefaultArgTypes().length; index++) { if (arguments[index] != null && !model.getDefaultArgTypes()[index].isAssignableFrom(arguments[index].getClass())) { return false; } } return true; }
public boolean startTaskModel() { if (model == null) return false; if (!checkDefault()) return false; if (this.model.getTaskType().equalsIgnoreCase("delayed")) { this.startTaskDelayed(model.getTimeDiff()); } else if (this.model.getTaskType().equalsIgnoreCase("repeating")) { this.startTaskRepeating(model.getTimeDiff()); } else return false; return true; }
@Override public void dispose() { if (taskModel != null) { taskModel.dispose(); taskModel = null; } super.dispose(); }
@Override public void createPartControl(Composite parent) { taskModel = new TaskModel(); Composite container = new Composite(parent, SWT.NONE); container.setLayout(new FillLayout()); { viewer = new GridTableViewer( container, SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); Grid table = viewer.getGrid(); table.setCellSelectionEnabled(true); table.setHeaderVisible(true); table.addMouseListener(new TaskMouseListener()); table.addKeyListener(new TaskKeyListener()); { GridColumn column = new GridColumn(table, SWT.NONE); column.setText("Summary"); column.setWidth(400); } for (Version version : taskModel.getVersions()) { GridColumn column = new GridColumn(table, SWT.CENTER); column.setText(version.toString()); column.setWidth(90); } viewer.setContentProvider(new TaskContentProvider()); viewer.setLabelProvider(new TaskLabelProvider()); viewer.setInput(taskModel); // ColumnViewerToolTipSupport.enableFor(viewer, ToolTip.RECREATE); getViewSite().setSelectionProvider(viewer); } createActions(); initializeToolBar(); initializeMenu(); viewer.setFilters(new ViewerFilter[] {new TaskViewerFilter()}); }
@Override public void run() { while (runing && ThreadManager.getInstance().isRunning()) { TaskModel r = null; while (taskQueue.isEmpty() && runing && ThreadManager.getInstance().isRunning()) { try { /* 任务队列为空,则等待有新任务加入从而被唤醒 */ synchronized (taskQueue) { taskQueue.wait(500); } } catch (InterruptedException ie) { log.error(ie); } } synchronized (taskQueue) { /* 取出任务执行 */ if (runing && ThreadManager.getInstance().isRunning()) { r = taskQueue.remove(0); } } if (r != null) { /* 执行任务 */ // r.setSubmitTimeL(); long submitTime = System.currentTimeMillis(); try { r.run(); } catch (Exception e) { log.error( "工人<“" + Thread.currentThread().getName() + "”> 执行任务<" + r.getID() + "(“" + r.getName() + "”)> 遇到错误: " + e); e.printStackTrace(); } long timeL1 = System.currentTimeMillis() - submitTime; long timeL2 = System.currentTimeMillis() - r.getSubmitTime(); if (timeL1 <= 100L) { log.info( "工人<“" + Thread.currentThread().getName() + "”> 完成了任务:" + r.toString() + " 执行耗时:" + timeL1 + " 提交耗时:" + timeL2); } else if (timeL1 <= 1000L) { log.info( "工人<“" + Thread.currentThread().getName() + "”> 长时间执行 完成任务:" + r.toString() + " “考虑”任务脚本逻辑 耗时:" + timeL1 + " 提交耗时:" + timeL2); } else if (timeL1 <= 4000L) { log.info( "工人<“" + Thread.currentThread().getName() + "”> 超长时间执行完成 任务:" + r.toString() + " “检查”任务脚本逻辑 耗时:" + timeL1 + " 提交耗时:" + timeL2); } else { log.info( "工人<“" + Thread.currentThread().getName() + "”> 超长时间执行完成 任务:" + r.toString() + " “考虑是否应该删除”任务脚本 耗时:" + timeL1 + " 提交耗时:" + timeL2); } r = null; } } log.error("线程结束, 工人<“" + Thread.currentThread().getName() + "”>退出"); }
public static void main(String[] args) { boolean autoGoBack = false; String str; Scanner sc1 = new Scanner(System.in); Scanner sc2 = new Scanner(System.in); int ch1 = 0; int ch2 = 0; int ch3 = 0; File categoryList[] = new File[100]; String driver = "org.hsqldb.jdbcDriver"; String url = "jdbc:hsqldb:hsql://localhost/"; String uid = "SA"; String pwd = ""; Connection con = null; try { TaskModel model = new TaskModel(); String catName; Class.forName(driver); con = DriverManager.getConnection(url, uid, pwd); Statement stmt = con.createStatement(); while (ch1 < 6) { System.out.println(""); System.out.println("Press 1 to create category"); System.out.println("Press 2 to load category"); System.out.println("Press 3 to list pending tasks"); System.out.println("Press 4 to search a category"); System.out.println("Press 5 to remove a category"); System.out.println("Press 6 to exit"); ch1 = sc1.nextInt(); switch (ch1) { case 1: System.out.println("Enter category name"); catName = sc1.next(); // input validations! while (!validateString(catName)) { System.out.println("No special characters and spaces"); catName = sc1.next(); } if (model.isCatPresent(catName)) { System.out.println("category already present. try loading it instead!!!"); autoGoBack = true; } if (autoGoBack == false) { while (ch2 != 2) { System.out.println("Press 1 to add a task"); System.out.println("Press 2 to go back"); ch2 = sc1.nextInt(); switch (ch2) { case 1: System.out.println("adding task..."); System.out.println("..."); System.out.println("..."); System.out.println("..."); System.out.println("Enter task name"); String tName = sc2.nextLine(); while (!validateString(tName)) { System.out.println("cannot remain blank and cannot contain only spaces"); tName = sc2.nextLine(); } System.out.println("Enter task description"); String tDesc = sc2.nextLine(); System.out.println("Enter task end date"); String endDate = sc2.nextLine(); SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy"); Date dt = sf.parse(endDate); TaskBean obj = new TaskBean(tName, tDesc, dt); model.add(obj); String msg = model.addTask(obj, catName); if (msg.equals("success")) { System.out.println("Task added successfully!"); break; // not sure if this is required } else System.out.println("Message:" + msg); break; // adding task ends here default: System.out.println("enter correct input!"); break; case 2: System.out.println("going back..."); break; } // switch ch2 ends here } // while loop for ch2 ends here } // autoGoBack ends here autoGoBack = false; break; case 4: System.out.println("enter the name of category to search"); catName = sc1.next(); str = model.search(catName); System.out.println(str); break; case 2: System.out.println("list of categories already created"); categoryList = model.loadCat(); for (int i = 0; i < categoryList.length; i++) System.out.println(categoryList[i]); System.out.println(""); System.out.println(""); System.out.println("Enter a name of the category listed above"); catName = sc1.next(); if (!model.isCatPresent(catName)) { System.out.println("category not present"); break; } else { label: while (ch3 <= 7) { System.out.println("Press 1 to add a task"); System.out.println("Press 2 to list tasks"); System.out.println("Press 3 to search"); System.out.println("Press 4 to get details of the task"); System.out.println("Press 5 to update a task"); System.out.println("Press 6 to delete a task"); System.out.println("Press 7 to go back"); int ch4 = sc1.nextInt(); ArrayList<TaskBean> al; int flag; switch (ch4) { case 1: System.out.println("adding task..."); System.out.println("..."); System.out.println("..."); System.out.println("..."); System.out.println("Enter task name"); String tName = sc2.nextLine(); while (!validateString(tName)) { System.out.println("cannot remain blank and cannot contain only spaces"); tName = sc2.nextLine(); } System.out.println("Enter task description"); String tDesc = sc2.nextLine(); System.out.println("Enter task end date"); String endDate = sc2.nextLine(); SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy"); Date dt = sf.parse(endDate); TaskBean obj = new TaskBean(tName, tDesc, dt); model.add(obj); String msg = model.addTask(obj, catName); if (msg.equals("success")) { System.out.println("Task added successfully!"); } else System.out.println("Message:" + msg); break; // adding task ends here case 2: System.out.println(""); System.out.println(""); System.out.println("list of tasks in the category..."); al = model.listTasks(catName); /*for(int i=0;i<al.size();i++) { TaskBean t = al.get(i); System.out.println(t.getName()); }*/ System.out.println( "total number of tasks in the category............" + al.size()); for (TaskBean tt : al) { System.out.println(tt.getName()); } break; // listing of all tasks within the category ends here case 3: System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("enter the name of task to search"); String ch5 = sc2.nextLine(); al = model.listTasks(catName); int flag2 = 0; for (TaskBean tt : al) { if (!ch5.equals(tt.getName())) continue; else flag2 = 1; break; } if (flag2 == 0) System.out.println("task not present"); else System.out.println("task present"); break; // searching a task ends here case 4: System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("enter the name of task"); String ch6 = sc2.nextLine(); al = model.listTasks(catName); flag = 0; TaskBean t = null; for (TaskBean tt : al) { if (!ch6.equals(tt.getName())) continue; else flag = 1; t = tt; break; } if (flag == 0) System.out.println("task not present"); else { System.out.println("task name"); System.out.println(t.getName()); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("task description"); System.out.println(t.getDesc()); System.out.println(""); System.out.println(""); System.out.println(""); System.out.println("end date for the task"); System.out.println(t.getEndDt()); } break; case 5: System.out.println("Enter name of task to be updated"); String ch8 = sc2.nextLine(); al = model.listTasks(catName); int flag1 = 0; for (TaskBean tt : al) { if (!ch8.equals(tt.getName())) continue; else flag1 = 1; break; } if (flag1 == 0) System.out.println("task not present"); else { System.out.println("Enter new name of task"); String ch9 = sc2.nextLine(); while (!validateString(ch9)) { System.out.println("cannot remain blank and cannot contain only spaces"); ch9 = sc2.nextLine(); } System.out.println("Enter new description"); String ch10 = sc2.nextLine(); System.out.println("Enter End Date"); String ch11 = sc2.nextLine(); SimpleDateFormat sf1 = new SimpleDateFormat("dd/MM/yyyy"); Date dt1 = sf1.parse(ch11); ArrayList<String> xyz = model.updateTask(catName, ch8, ch9, ch10, dt1); model.reWrite(catName, xyz); System.out.println("successfully updated"); System.out.println(""); System.out.println(""); System.out.println(""); } break; // end of getting details case 6: System.out.println("Enter name of task to be deleted"); String ch7 = sc2.next(); al = model.listTasks(catName); int flag3 = 0; for (TaskBean tt : al) { if (!ch7.equals(tt.getName())) continue; else flag3 = 1; break; } if (flag3 == 0) System.out.println("task not present"); else { ArrayList<String> abc = model.deleteTask(catName, ch7); model.reWrite(catName, abc); System.out.println("Task successfully removed"); System.out.println(""); System.out.println(""); System.out.println(""); } break; case 7: System.out.println("going back..."); break label; default: System.out.println("option not supported yet!"); break; } // switch for ch4 ends here } // while for ch3!6 ends here } break; // end of loading category default: System.out.println("Option not supported...yet!"); break; case 6: System.out.println("closing task manager..."); break; case 5: System.out.println("enter the name of category"); String ch6 = sc2.nextLine(); str = model.search(ch6); System.out.println(str); if (str.equals("Not found")) System.out.println(str); else model.deleteFile(ch6); System.out.println("category removed!"); break; case 3: System.out.println("list of pending tasks"); ArrayList<TaskBean> al = model.listPendingTasks(); /*for(int i=0;i<al.size();i++) { TaskBean t = al.get(i); System.out.println(t.getName()); }*/ System.out.println("total number of pending tasks............" + al.size()); for (TaskBean tt : al) { System.out.println(tt.getName()); } } } } catch (Exception e) { System.out.println("oops! something went wrong!"); e.printStackTrace(); } }