Checkstyle

This commit is contained in:
Arne Keller 2020-03-05 21:54:18 +01:00
parent ea15f218cb
commit c0f22b2697

View File

@ -79,49 +79,6 @@ public final class Train {
} }
} }
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder(Integer.toString(getIdentifier()));
for (final RollingStock rollingStock : rollingStocks) {
stringBuilder.append(' ');
stringBuilder.append(rollingStock.getIdentifier());
}
return stringBuilder.toString();
}
/**
* Get the ASCII art of this train.
*
* @return rows of ASCII art
*/
public List<String> show() {
final List<StringBuilder> lines = new ArrayList<>();
for (final RollingStock rollingStock : rollingStocks) {
for (final StringBuilder line : lines) {
line.append(' ');
}
final String[] text = rollingStock.textRepresentation();
final int currentLength = lines.stream().mapToInt(StringBuilder::length).max().orElse(0);
while (lines.size() < text.length) {
final StringBuilder line = new StringBuilder();
for (int i = 0; i < currentLength; i++) {
line.append(' ');
}
lines.add(0, line);
}
for (int i = 0; i < text.length; i++) {
lines.get(lines.size() - 1 - i).append(text[text.length - 1 - i]);
}
final int finalLength = lines.stream().mapToInt(StringBuilder::length).max().getAsInt();
for (final StringBuilder line : lines) {
while (line.length() < finalLength) {
line.append(' ');
}
}
}
return lines.stream().map(StringBuilder::toString).collect(Collectors.toList());
}
/** /**
* Check whether this train is on a particular rail. Note that at least one rolling stock has to be on the rail, * Check whether this train is on a particular rail. Note that at least one rolling stock has to be on the rail,
* just touching the rail is not enough. * just touching the rail is not enough.
@ -367,4 +324,47 @@ public final class Train {
public long getLength() { public long getLength() {
return rollingStocks.stream().mapToLong(RollingStock::getLength).sum(); return rollingStocks.stream().mapToLong(RollingStock::getLength).sum();
} }
/**
* Get the ASCII art of this train.
*
* @return rows of ASCII art
*/
public List<String> show() {
final List<StringBuilder> lines = new ArrayList<>();
for (final RollingStock rollingStock : rollingStocks) {
for (final StringBuilder line : lines) {
line.append(ROLLING_STOCK_SEPARATOR);
}
final String[] text = rollingStock.textRepresentation();
final int currentLength = lines.stream().mapToInt(StringBuilder::length).max().orElse(0);
while (lines.size() < text.length) {
final StringBuilder line = new StringBuilder();
for (int i = 0; i < currentLength; i++) {
line.append(ROLLING_STOCK_SEPARATOR);
}
lines.add(0, line);
}
for (int i = 0; i < text.length; i++) {
lines.get(lines.size() - 1 - i).append(text[text.length - 1 - i]);
}
final int finalLength = lines.stream().mapToInt(StringBuilder::length).max().getAsInt();
for (final StringBuilder line : lines) {
while (line.length() < finalLength) {
line.append(ROLLING_STOCK_SEPARATOR);
}
}
}
return lines.stream().map(StringBuilder::toString).collect(Collectors.toList());
}
@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder(Integer.toString(getIdentifier()));
for (final RollingStock rollingStock : rollingStocks) {
stringBuilder.append(' ');
stringBuilder.append(rollingStock.getIdentifier());
}
return stringBuilder.toString();
}
} }