51 lines
1.7 KiB
Java
51 lines
1.7 KiB
Java
|
package com.discord.utilities.collections;
|
||
|
|
||
|
import d0.t.u;
|
||
|
import d0.z.d.m;
|
||
|
import java.util.Iterator;
|
||
|
import kotlin.collections.ArrayDeque;
|
||
|
/* compiled from: FixedSizeLineBuffer.kt */
|
||
|
public final class FixedSizeLineBuffer {
|
||
|
private final int maxCharacterCount;
|
||
|
private final ArrayDeque<String> output = new ArrayDeque<>();
|
||
|
private int outputLength;
|
||
|
private final Object sync = new Object();
|
||
|
|
||
|
public FixedSizeLineBuffer(int i) {
|
||
|
this.maxCharacterCount = i;
|
||
|
}
|
||
|
|
||
|
public final void addLine(String str) {
|
||
|
String removeFirstOrNull;
|
||
|
m.checkNotNullParameter(str, "line");
|
||
|
synchronized (this.sync) {
|
||
|
this.output.add(str);
|
||
|
this.outputLength = str.length() + 1 + this.outputLength;
|
||
|
while (this.outputLength > this.maxCharacterCount && (removeFirstOrNull = this.output.removeFirstOrNull()) != null) {
|
||
|
this.outputLength -= removeFirstOrNull.length() - 1;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final void appendString(StringBuilder sb) {
|
||
|
m.checkNotNullParameter(sb, "sb");
|
||
|
synchronized (this.sync) {
|
||
|
Iterator<String> it = this.output.iterator();
|
||
|
while (it.hasNext()) {
|
||
|
sb.append(it.next());
|
||
|
m.checkNotNullExpressionValue(sb, "append(value)");
|
||
|
sb.append('\n');
|
||
|
m.checkNotNullExpressionValue(sb, "append('\\n')");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final String getString() {
|
||
|
String joinToString$default;
|
||
|
synchronized (this.sync) {
|
||
|
joinToString$default = u.joinToString$default(this.output, "\n", null, null, 0, null, null, 62, null);
|
||
|
}
|
||
|
return joinToString$default;
|
||
|
}
|
||
|
}
|