Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/unify java style #272

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
4ca06f1346d13d6e275d891de918cc6bae85c3d8
f3301743a5e4ca39b415e4f1fa32c66a39ef37b5

# normalize java style
cd7470fee76f121adaca603b594228573be4d3d9
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
}
"java.configuration.updateBuildConfiguration": "automatic",
}
4 changes: 2 additions & 2 deletions src/main/java/io/usethesource/vallang/IConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ default int getMatchFingerprint() {

@Override
default boolean match(IValue value) {
if(value == this) return true;
if(value == null) return false;
if(value == this) { return true; }
if(value == null) { return false; }

if (value instanceof IConstructor){
IConstructor otherTree = (IConstructor) value;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/usethesource/vallang/IList.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ public default boolean defaultEquals(@Nullable Object other) {
return true;
}

if (getType() != list2.getType())
if (getType() != list2.getType()) {
return false;
}

if (hashCode() != list2.hashCode()) {
return false;
Expand Down
226 changes: 106 additions & 120 deletions src/main/java/io/usethesource/vallang/impl/persistent/Constructor.java

Large diffs are not rendered by default.

292 changes: 146 additions & 146 deletions src/main/java/io/usethesource/vallang/impl/persistent/EmptySet.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,160 +31,160 @@
import io.usethesource.vallang.type.TypeFactory;

public final class EmptySet implements ISet {
private static final Type EMPTY_SET_TYPE = TypeFactory.getInstance().setType(TypeFactory.getInstance().voidType());
public static final EmptySet EMPTY_SET = new EmptySet();

private EmptySet() {}

public static final ISet of() {
return EMPTY_SET;
}

@Override
public String toString() {
return defaultToString();
}

public static final ISet of(final IValue firstElement) {
final Type firstElementType = firstElement.getType();

if (isTupleOfArityTwo.test(firstElementType)) {
return Stream.of(firstElement).map(asInstanceOf(ITuple.class))
.collect(toSetMultimap(tuple -> tuple.get(0), tuple -> tuple.get(1)));
} else {
return Stream.of(firstElement).collect(toSet());
}
}

@Override
public ISetWriter writer() {
return ValueFactory.getInstance().setWriter();
}

@Override
public Type getType() {
return EMPTY_SET_TYPE;
}

@Override
public boolean isEmpty() {
return true;
}

@Override
public ISet insert(IValue value) {
// TODO: move smart constructor
return of(value);
}

@Override
public ISet delete(IValue value) {
return this;
}

@Override
public int size() {
return 0;
}

@Override
public boolean contains(IValue value) {
return false;
}

@Override
public Iterator<IValue> iterator() {
return Collections.emptyIterator();
}

@Override
public int hashCode() {
return 0;
}

@Override
public boolean equals(@Nullable Object other) {
return other == this;
}

@Override
public boolean match(IValue other) {
return other == this;
}

@Override
public ISet union(ISet other) {
return other;
}

@Override
public ISet intersect(ISet other) {
return this;
}

@Override
public ISet subtract(ISet other) {
return this;
}

@Override
public ISet product(ISet that) {
return this;
}

@Override
public boolean isSubsetOf(ISet other) {
return true;
}

@Override
public IRelation<ISet> asRelation() {
return new IRelation<ISet>() {
@Override
public ISet asContainer() {
return EmptySet.this;
}
private static final Type EMPTY_SET_TYPE = TypeFactory.getInstance().setType(TypeFactory.getInstance().voidType());
public static final EmptySet EMPTY_SET = new EmptySet();

@Override
public ISet compose(IRelation<ISet> that) {
return EmptySet.this;
}
private EmptySet() {}

@Override
public ISet closure() {
return EmptySet.this;
}
public static final ISet of() {
return EMPTY_SET;
}

@Override
public ISet closureStar() {
return EmptySet.this;
}
@Override
public String toString() {
return defaultToString();
}

@Override
public ISet carrier() {
return EmptySet.this;
}
public static final ISet of(final IValue firstElement) {
final Type firstElementType = firstElement.getType();

@Override
public ISet domain() {
return EmptySet.this;
if (isTupleOfArityTwo.test(firstElementType)) {
return Stream.of(firstElement).map(asInstanceOf(ITuple.class))
.collect(toSetMultimap(tuple -> tuple.get(0), tuple -> tuple.get(1)));
} else {
return Stream.of(firstElement).collect(toSet());
}
}

@Override
public ISet range() {
return EmptySet.this;
}
@Override
public ISetWriter writer() {
return ValueFactory.getInstance().setWriter();
}

@Override
public ISet empty() {
return EmptySet.this;
}
@Override
public Type getType() {
return EMPTY_SET_TYPE;
}

@Override
public ISet index(IValue key) {
return EmptySet.this;
}
};
}
@Override
public boolean isEmpty() {
return true;
}

@Override
public ISet insert(IValue value) {
// TODO: move smart constructor
return of(value);
}

@Override
public ISet delete(IValue value) {
return this;
}

@Override
public int size() {
return 0;
}

@Override
public boolean contains(IValue value) {
return false;
}

@Override
public Iterator<IValue> iterator() {
return Collections.emptyIterator();
}

@Override
public int hashCode() {
return 0;
}

@Override
public boolean equals(@Nullable Object other) {
return other == this;
}

@Override
public boolean match(IValue other) {
return other == this;
}

@Override
public ISet union(ISet other) {
return other;
}

@Override
public ISet intersect(ISet other) {
return this;
}

@Override
public ISet subtract(ISet other) {
return this;
}

@Override
public ISet product(ISet that) {
return this;
}

@Override
public boolean isSubsetOf(ISet other) {
return true;
}

@Override
public IRelation<ISet> asRelation() {
return new IRelation<ISet>() {
@Override
public ISet asContainer() {
return EmptySet.this;
}

@Override
public ISet compose(IRelation<ISet> that) {
return EmptySet.this;
}

@Override
public ISet closure() {
return EmptySet.this;
}

@Override
public ISet closureStar() {
return EmptySet.this;
}

@Override
public ISet carrier() {
return EmptySet.this;
}

@Override
public ISet domain() {
return EmptySet.this;
}

@Override
public ISet range() {
return EmptySet.this;
}

@Override
public ISet empty() {
return EmptySet.this;
}

@Override
public ISet index(IValue key) {
return EmptySet.this;
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ public IList delete(int index){
newData.remove(index);

Type newElementType = TypeFactory.getInstance().voidType();
for(IValue el : newData)
for(IValue el : newData) {
newElementType = newElementType.lub(el.getType());
}

return new ListWriter(newElementType, newData).done();
}
Expand Down Expand Up @@ -268,9 +269,9 @@ class SubList implements IList {

int end = offset + length;

if(offset < 0) throw new IndexOutOfBoundsException("Offset may not be smaller than 0.");
if(length < 0) throw new IndexOutOfBoundsException("Length may not be smaller than 0.");
if(end > base.length()) throw new IndexOutOfBoundsException("'offset + length' may not be larger than 'list.size()'");
if(offset < 0) { throw new IndexOutOfBoundsException("Offset may not be smaller than 0."); }
if(length < 0) { throw new IndexOutOfBoundsException("Length may not be smaller than 0."); }
if(end > base.length()) { throw new IndexOutOfBoundsException("'offset + length' may not be larger than 'list.size()'"); }

Type newElementType = TypeFactory.getInstance().voidType();
Type baseElementType = base.getElementType();
Expand Down
Loading
Loading