Skip to content

Commit

Permalink
Merge pull request #75 from hkupty/logger-storage-improvements
Browse files Browse the repository at this point in the history
Logger storage improvements
  • Loading branch information
hkupty authored Jan 14, 2024
2 parents b13612a + 4a5afde commit a564c70
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 317 deletions.
78 changes: 78 additions & 0 deletions penna-core/src/main/java/penna/core/internals/StringNavigator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package penna.core.internals;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;

public class StringNavigator implements Iterator<StringNavigator.StringView> {
public static final int DOT = 0x2E;
public static final int DOLLAR = 0x24;
public final String base;
public int startIndex;
public int nextIndex;
public boolean hasNext = true;
public int symbol = DOT;


@Override
public boolean hasNext() {
return hasNext;
}

@Override
public StringView next() {
StringView view;
nextIndex = base.indexOf(symbol, startIndex);
if (nextIndex == -1 && symbol == DOT) {
symbol = DOLLAR;
nextIndex = base.indexOf(symbol, startIndex);
}
if (nextIndex == -1) {
hasNext = false;
view = new StringView(base, startIndex, base.length() - startIndex);
} else {
view = new StringView(base, startIndex, nextIndex - startIndex);
startIndex = nextIndex + 1;
}
return view;
}

public record StringView(String base, int startingPoint, int length) implements CharSequence {

@Override
public int length() {return length;}

@Override
public char charAt(int index) {
return base.charAt(startingPoint + index);
}

@Override
public @NotNull CharSequence subSequence(int start, int end) {
return base.subSequence(startingPoint + start, startingPoint + Math.min(end, length));
}

@Override
public @NotNull String toString() {
return base.substring(startingPoint, startingPoint + length);
}

public int indexCompare(String against) {
int diff = CharSequence.compare(this, against);
return Integer.signum(diff) + 1;
}
}

public StringNavigator(final String base) {
this.base = base;
}

public StringView chunk(int index) {
return null;
}

public int indexCompare(int index, String against) {
return -1;
}

}
Loading

0 comments on commit a564c70

Please sign in to comment.