https://github.com/timoschwarzer/ex04
homework
https://github.com/timoschwarzer/ex04
Last synced: 3 months ago
JSON representation
homework
- Host: GitHub
- URL: https://github.com/timoschwarzer/ex04
- Owner: timoschwarzer
- Created: 2019-06-24T20:02:23.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-24T20:07:37.000Z (about 6 years ago)
- Last Synced: 2025-02-10T04:41:25.592Z (5 months ago)
- Language: Java
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ex04
homeworkpublic class Paragraph {
String text;
static int counter = 0;
int id;Paragraph(String text){
this.id = counter;
this.text = text;
counter++;
}}
public void getTask() {
Request task;
final ConcurrentLinkedQueue lock = request;synchronized (lock) {
if (lock.isEmpty()) {
System.out.println(this.getName() + " had no work");
return;
}task = lock.poll();
}
switch (task.getReqType()) {case APPEND_PAR:
print(task);
doc.appendParagraph(task.getText());
break;
case APPEND_TEXT:
print(task);
doc.appendText(task.getText(), task.getParagraphID());
break;case REPLACE:
print(task);
doc.replaceText(task.getText(), task.getParagraphID());
break;case DELETE:
print(task);
doc.deleteParagraph(task.getParagraphID());
break;case GET_TEXT:
print(task);
doc.getText();
break;case MERGE:
print(task);
doc.mergeParagraphs(task.getParagraphID());
break;case INSERT_AFTER:
print(task);
doc.insertAfterParagraph(task.getText(), task.getParagraphID());
break;default:
System.out.println(this.getName() + " shouldn't be here!");
break;
}}
private void print(Request task){
System.out.println(this.getName() + " executed task: " + task.getReqType().toString());}
public void run() {while(true) {
getTask();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}if (request.isEmpty()) {
break;
}
}}