sollte beliebter bei den Tools sein,

außerdem letzer commit morgen Prüfung
This commit is contained in:
Johannes Theiner 2018-06-24 19:55:14 +02:00
parent 9e4de004e6
commit 62f4018a68
3 changed files with 43 additions and 27 deletions

View File

@ -2,7 +2,7 @@ package de.joethei.hs.java2.praktikum.praktikum1;
public class GrosseZahl {
private int zahl[];
private int[] zahl;
public GrosseZahl(String d) {
Boolean korrekteEingabe=true;
@ -37,7 +37,8 @@ public class GrosseZahl {
public GrosseZahl add(GrosseZahl b) {
int uebertrag = 0;
GrosseZahl rueckgabe, operand;
GrosseZahl rueckgabe;
GrosseZahl operand;
if(this.less(b)) {
rueckgabe = new GrosseZahl(b.toString());
operand = new GrosseZahl(this.toString());
@ -65,9 +66,7 @@ public class GrosseZahl {
public GrosseZahl sub(GrosseZahl b) {
int uebertrag = 0;
StringBuilder x;
if(this.equals(b)) {
return new GrosseZahl(0);
} else if(this.less(b)) {
if(this.equals(b) || this.less(b)) {
return new GrosseZahl(0);
}
GrosseZahl rueckgabe = new GrosseZahl(this.toString());
@ -94,8 +93,11 @@ public class GrosseZahl {
}
public GrosseZahl mult(GrosseZahl b) {
GrosseZahl rueckgabe, rueckgabe_b, operand, operand2;
rueckgabe_b = new GrosseZahl(0);
GrosseZahl rueckgabe;
GrosseZahl result;
GrosseZahl operand;
GrosseZahl operand2;
result = new GrosseZahl(0);
if(this.less(b)) {
operand2 = b;
operand = this;
@ -108,12 +110,12 @@ public class GrosseZahl {
for(int w = 0; w<operand.zahl[i]; w++) {
rueckgabe = rueckgabe.add(operand2);
}
rueckgabe_b = rueckgabe_b.add(rueckgabe);
result = result.add(rueckgabe);
if(i != operand.zahl.length-1) {
rueckgabe_b = new GrosseZahl(rueckgabe_b.toString()+"0");
result = new GrosseZahl(result.toString()+"0");
}
}
return rueckgabe_b;
return result;
}
@ -156,4 +158,8 @@ public class GrosseZahl {
return false;
}
@Override
public int hashCode() {
return super.hashCode();
}
}

View File

@ -63,7 +63,7 @@ public class CharCollection implements Cloneable{
}
public CharCollection except(CharCollection cc) {
ArrayList<Character> list= new ArrayList<>(this.list);
ArrayList<Character> list = new ArrayList<>(this.list);
boolean removeCharacterOnce = false;
for(int i=0; i<list.size(); i++){
for(int w=0; w<cc.list.size(); w++) {
@ -104,4 +104,8 @@ public class CharCollection implements Cloneable{
}return false;
}
@Override
public int hashCode() {
return super.hashCode();
}
}

View File

@ -4,6 +4,7 @@ import java.io.*;
import java.net.ServerSocket;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Logger;
public class KlausurenServer {
@ -11,11 +12,17 @@ public class KlausurenServer {
private ExecutorService executorService = Executors.newCachedThreadPool();
private ServerSocket serverSocket;
private static Logger logger = Logger.getLogger("KlausurenServer");
private static Map<String, CommandHandler> commands = new HashMap<>();
static Map<String, CommandHandler> getCommands() {
return commands;
}
public static Logger getLogger() {
return logger;
}
private boolean running;
public KlausurenServer(int port) {
@ -23,8 +30,8 @@ public class KlausurenServer {
commands.put("test", ((writer, args) -> writer.write("Hallo Welt")));
commands.put("delall", (writer, args) -> {
data.clear();
save();
data.clear();
save();
});
commands.put("put", (writer, args) -> {
if (args.size() >= 3) {
@ -52,9 +59,8 @@ public class KlausurenServer {
Set<TreeSet<Integer>> result = new HashSet<>();
set.forEach((key, value) -> set.forEach((s, integers) -> {
if(!value.equals(integers)) {
if (integers.containsAll(value))
set.remove(key);
if (!value.equals(integers) && integers.containsAll(value)) {
set.remove(key);
}
}));
@ -62,7 +68,7 @@ public class KlausurenServer {
result.removeIf(TreeSet::isEmpty);
writer.write(result.toString().substring(1, result.toString().length()-1).replace(" ", ""));
writer.write(result.toString().substring(1, result.toString().length() - 1).replace(" ", ""));
} else {
writer.write("0");
}
@ -91,7 +97,7 @@ public class KlausurenServer {
Runnable runnable = () -> {
try {
serverSocket = new ServerSocket(port);
System.out.println("waiting for clients");
logger.info("waiting for clients");
while (running) {
executorService.submit(new ClientRunnable(serverSocket.accept()));
}
@ -103,10 +109,10 @@ public class KlausurenServer {
}
serverSocket.close();
System.out.println("server shutdown");
logger.info("server shutdown");
Thread.currentThread().interrupt();
} catch (IOException e) {
e.printStackTrace();
logger.throwing("KlausurenServer", "Constructor", e.getCause());
}
};
@ -114,12 +120,12 @@ public class KlausurenServer {
thread.start();
}
synchronized void load() {
private synchronized void load() {
FileReader fileReader = null;
try {
fileReader = new FileReader(getClass().getClassLoader().getResource("praktikum4/data.txt").getFile());
fileReader = new FileReader(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum4/data.txt")).getFile());
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.throwing("KlausurenServer", "load", e.getCause());
}
try (BufferedReader br = new BufferedReader(Objects.requireNonNull(fileReader))) {
for (String line = br.readLine(); line != null; line = br.readLine()) {
@ -131,15 +137,15 @@ public class KlausurenServer {
data.put(array[0], set);
}
} catch (IOException e) {
e.printStackTrace();
logger.throwing("KlausurenServer", "load", e.getCause());
}
}
synchronized void save() {
private synchronized void save() {
FileOutputStream fileOutputStream;
PrintWriter printWriter = null;
try {
fileOutputStream = new FileOutputStream(getClass().getClassLoader().getResource("praktikum4/data.txt").getFile());
fileOutputStream = new FileOutputStream(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum4/data.txt")).getFile());
printWriter = new PrintWriter(fileOutputStream);
for (Map.Entry<String, TreeSet<Integer>> entry : data.entrySet()) {
@ -151,7 +157,7 @@ public class KlausurenServer {
}
} catch (IOException e) {
e.printStackTrace();
logger.throwing("KlausurenServer", "save", e.getCause());
} finally {
assert printWriter != null;
printWriter.close();