Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
graefjk committed Jan 4, 2024
1 parent 1c32ac4 commit 13b5d54
Show file tree
Hide file tree
Showing 99 changed files with 1,331 additions and 1,369 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
*/
package de.unistuttgart.informatik.fius.icge.log;

*

import java.io.OutputStream;
import java.io.PrintStream;**
import java.io.PrintStream;


/**
Expand All @@ -25,25 +23,27 @@
* @version 2.0
*/
public abstract class Logger {
*

/** The main logger printing to {@link System#out} */
public static PrintStream out;
public static PrintStream out;
/** The error logger printing to {@link System#err} */
public static PrintStream error;*
public static PrintStream error;

private static OutputStreamMultiplier outStream;
private static OutputStreamMultiplier errorStream;*
private static OutputStreamMultiplier errorStream;

// This block intercepts {@link System.out} and {@link System.err}
static {
Logger.outStream = new OutputStreamMultiplier();
Logger.outStream.addOutputStream(System.out);
Logger.out = new PrintStream(Logger.outStream);
System.setOut(Logger.out);
*

Logger.errorStream = new OutputStreamMultiplier();
Logger.errorStream.addOutputStream(System.err);
Logger.error = new PrintStream(Logger.errorStream);
System.setErr(Logger.error);
}*
}

/**
* Function to add a {@link OutputStream} to the out logger
Expand All @@ -55,7 +55,7 @@ public abstract class Logger {
*/
public static boolean addOutOutputStream(final OutputStream stream) {
return Logger.outStream.addOutputStream(stream);
}*
}

/**
* Function to remove a {@link OutputStream} from the out logger
Expand All @@ -67,7 +67,7 @@ public static boolean addOutOutputStream(final OutputStream stream) {
*/
public static boolean removeOutOutputStream(final OutputStream stream) {
return Logger.outStream.removeOutputStream(stream);
}*
}

/**
* Clears the out OutputStreams
Expand All @@ -76,7 +76,7 @@ public static boolean removeOutOutputStream(final OutputStream stream) {
*/
public static void clearOutOutputStream() {
Logger.outStream.clearOutputStreams();
}*
}

/**
* Function to add a {@link OutputStream} to the error logger
Expand All @@ -88,7 +88,7 @@ public static void clearOutOutputStream() {
*/
public static boolean addErrorOutputStream(final OutputStream stream) {
return Logger.errorStream.addOutputStream(stream);
}*
}

/**
* Function to remove a {@link OutputStream} from the error logger
Expand All @@ -100,7 +100,7 @@ public static boolean addErrorOutputStream(final OutputStream stream) {
*/
public static boolean removeErrorOutputStream(final OutputStream stream) {
return Logger.errorStream.removeOutputStream(stream);
}*
}

/**
* Clears the error OutputStreams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
*/
package de.unistuttgart.informatik.fius.icge.log;

*

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;**
import java.util.ArrayList;


/**
Expand All @@ -23,15 +21,15 @@
* @version 1.0
*/
public class OutputStreamMultiplier extends OutputStream {
*
private final ArrayList<OutputStream> listenerStreams;*

private final ArrayList<OutputStream> listenerStreams;

/**
* Default Constructor
*/
public OutputStreamMultiplier() {
this.listenerStreams = new ArrayList<>();
}*
}

/**
* Add a output stream to also recieve everything this stream recieves
Expand All @@ -42,7 +40,7 @@ public OutputStreamMultiplier() {
*/
public boolean addOutputStream(final OutputStream listenerStream) {
return this.listenerStreams.add(listenerStream);
}*
}

/**
* Remove a output stream from recieving everything this stream recieves
Expand All @@ -53,30 +51,30 @@ public boolean addOutputStream(final OutputStream listenerStream) {
*/
public boolean removeOutputStream(final OutputStream listenerStream) {
return this.listenerStreams.remove(listenerStream);
}*
}

/**
* Clears all connected output streams
*/
public void clearOutputStreams() {
this.listenerStreams.clear();
}*
}

@Override
public void flush() throws IOException {
super.flush();
*

for (final OutputStream listenerStream : this.listenerStreams) {
listenerStream.flush();
}
}*
}

@Override
public void write(final int arg0) throws IOException {
for (final OutputStream listenerStream : this.listenerStreams) {
listenerStream.write(arg0);
}
}*
}

@Override
public void close() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
package de.unistuttgart.informatik.fius.icge.simulation;

*
/**
* The four fundamental directions possible in the simulation.
* <p>
Expand Down Expand Up @@ -38,7 +37,7 @@ public enum Direction {
SOUTH,
/** The west direction; at the left of the screen ({@link Position#getX()} getting smaller) */
WEST;
*

/**
* Get the direction that is next in a clock wise rotation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
*/
package de.unistuttgart.informatik.fius.icge.simulation;

*

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Set;**
import java.util.Set;


/**
Expand All @@ -26,8 +24,8 @@
* The parent type of all types contained in this list.
*/
public class MultiTypedList<P> {
*
private final HashMap<Class<? extends P>, List<P>> items = new HashMap<>();*

private final HashMap<Class<? extends P>, List<P>> items = new HashMap<>();

/**
* Get the relevant list for the given type.
Expand All @@ -44,15 +42,15 @@ private <T extends P> Optional<List<T>> getRelevantListGeneric(final Class<? ext
@SuppressWarnings("unchecked")
final var listOfCorrectType = (List<T>) list;
return Optional.ofNullable(listOfCorrectType);
}*
}

private Class<? extends P> getClass(final P o) {
//Actually a cast should not be necessary here.
//Should be totally safe, because o is of type P, so o.getClass() should extend P.
@SuppressWarnings("unchecked")
final var type = (Class<? extends P>) o.getClass();
return type;
}*
}

/**
* Get the relevant list for the given object.
Expand All @@ -63,7 +61,7 @@ private Class<? extends P> getClass(final P o) {
*/
private Optional<List<P>> getRelevantList(final P o) {
return this.getRelevantListGeneric(this.getClass(o));
}*
}

/**
* Get the relevant list for the given entity and create it if it is not there.
Expand All @@ -75,11 +73,11 @@ private Optional<List<P>> getRelevantList(final P o) {
private List<P> getRelevantListAndCreate(final P o) {
final var type = this.getClass(o);
if (this.items.containsKey(type)) return this.items.get(type);
*

final List<P> list = new ArrayList<>();
this.items.put(type, list);
return list;
}*
}

/**
* Add the given object to this list.
Expand All @@ -89,7 +87,7 @@ private List<P> getRelevantListAndCreate(final P o) {
*/
public synchronized void add(final P o) {
this.getRelevantListAndCreate(o).add(o);
}*
}

/**
* Check whether this list contains the given object.
Expand All @@ -102,7 +100,7 @@ public synchronized boolean contains(final P o) {
final var opt = this.getRelevantList(o);
if (opt.isEmpty()) return false;
return opt.get().contains(o);
}*
}

/**
* Return {@code true} iff the list contains no objects.
Expand All @@ -111,7 +109,7 @@ public synchronized boolean contains(final P o) {
*/
public synchronized boolean isEmpty() {
return this.items.isEmpty();
}*
}

/**
* Remove the given object from this list.
Expand All @@ -124,7 +122,7 @@ public synchronized boolean remove(final P o) {
final var opt = this.getRelevantList(o);
if (opt.isEmpty()) return false;
return opt.get().remove(o);
}*
}

/**
* Get all objects in this list of the given type.
Expand All @@ -139,19 +137,19 @@ public synchronized boolean remove(final P o) {
*/
public synchronized <T extends P> List<T> get(final Class<? extends T> type, final boolean includeSubclasses) {
if (!includeSubclasses) return this.<T>getRelevantListGeneric(type).orElse(List.of());
*

final List<T> result = new ArrayList<>();
*

for (final Class<? extends P> storedType : this.items.keySet()) {
if (type.isAssignableFrom(storedType)) {
final Class<? extends T> storedTypeAsSubOfRequested = storedType.asSubclass(type);
final List<T> listForStoredType = this.<T>getRelevantListGeneric(storedTypeAsSubOfRequested).orElse(List.of());
result.addAll(listForStoredType);
}
}
*

return result;
}*
}

/**
* @return a list of stored types.
Expand Down
Loading

0 comments on commit 13b5d54

Please sign in to comment.