-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature refactor measures for repository api (#313)
* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * First pass on federated repository and fixing tests. * Fix final tests * Fix merge stompage * Add missing type * Fix merge * Fix merge * Add retrieve settings to evaluation settings --------- Co-authored-by: Jonathan Percival <[email protected]>
- Loading branch information
Showing
1,033 changed files
with
624,308 additions
and
812,433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
cqf-fhir-utility/src/main/java/org/opencds/cqf/fhir/utility/monad/Either.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package org.opencds.cqf.fhir.utility.monad; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
public class Either<L, R> { | ||
|
||
private final L left; | ||
private final R right; | ||
|
||
Either(L left, R right) { | ||
checkArgument(left == null ^ right == null, "left and right are mutually exclusive"); | ||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
public Either<R, L> swap() { | ||
if (isLeft()) { | ||
return Eithers.forRight(left()); | ||
} | ||
|
||
return Eithers.forLeft(right()); | ||
} | ||
|
||
public boolean isLeft() { | ||
return left != null; | ||
} | ||
|
||
public boolean isRight() { | ||
return right != null; | ||
} | ||
|
||
public L left() { | ||
checkState(isLeft()); | ||
return left; | ||
} | ||
|
||
public R right() { | ||
checkState(isRight()); | ||
return right; | ||
} | ||
|
||
public R get() { | ||
return right(); | ||
} | ||
|
||
public R orElse(R defaultValue) { | ||
if (isRight()) { | ||
return right; | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public R orElseGet(Supplier<R> defaultSupplier) { | ||
if (isRight()) { | ||
return right; | ||
} else { | ||
return defaultSupplier.get(); | ||
} | ||
} | ||
|
||
public Either<L, R> forEach( | ||
Consumer<? super R> forRight) { | ||
checkNotNull(forRight); | ||
if (isRight()) { | ||
forRight.accept(right()); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> Either<L, T> map(Function<? super R, ? extends T> mapRight) { | ||
checkNotNull(mapRight); | ||
if (isLeft()) { | ||
return (Either<L, T>) this; | ||
} | ||
|
||
return Eithers.forRight(mapRight.apply(right())); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> Either<L, T> flatMap( | ||
Function<? super R, ? extends Either<L, ? extends T>> flatMapRight) { | ||
checkNotNull(flatMapRight); | ||
if (isLeft()) { | ||
return (Either<L, T>) this; | ||
} | ||
|
||
return (Either<L, T>) flatMapRight.apply(right()); | ||
} | ||
|
||
public R fold( | ||
Function<? super L, ? extends R> foldLeft) { | ||
checkNotNull(foldLeft); | ||
if (isRight()) { | ||
return right; | ||
} else { | ||
return foldLeft.apply(left()); | ||
} | ||
} | ||
|
||
public <T> T fold( | ||
Function<? super L, ? extends T> foldLeft, | ||
Function<? super R, ? extends T> foldRight) { | ||
checkNotNull(foldLeft); | ||
checkNotNull(foldRight); | ||
if (isRight()) { | ||
return foldRight.apply(right()); | ||
} else { | ||
return foldLeft.apply(left()); | ||
} | ||
} | ||
|
||
public <U> U transform(Function<? super Either<? super L, ? super R>, ? extends U> transform) { | ||
return transform.apply(this); | ||
} | ||
|
||
public Stream<R> stream() { | ||
if (isRight()) { | ||
return Stream.of(right()); | ||
} else { | ||
return Stream.of(); | ||
} | ||
} | ||
|
||
public Optional<R> optional() { | ||
if (isRight()) { | ||
return Optional.of(right()); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof Either<?, ?>) { | ||
Either<?, ?> other = (Either<?, ?>) obj; | ||
return (this.left == other.left && this.right == other.right) | ||
|| (this.left != null && other.left != null && this.left.equals(other.left)) | ||
|| (this.right != null && other.right != null && this.right.equals(other.right)); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
if (this.left != null) { | ||
return this.left.hashCode(); | ||
} | ||
|
||
return this.right.hashCode(); | ||
} | ||
} |
204 changes: 204 additions & 0 deletions
204
cqf-fhir-utility/src/main/java/org/opencds/cqf/fhir/utility/monad/Either3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
package org.opencds.cqf.fhir.utility.monad; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Stream; | ||
|
||
public class Either3<L, M, R> { | ||
|
||
private final L left; | ||
private final M middle; | ||
private final R right; | ||
|
||
Either3(L left, M middle, R right) { | ||
checkArgument((left == null ^ middle == null) && (middle == null ^ right == null), | ||
"left, middle, and right are mutually exclusive"); | ||
this.left = left; | ||
this.middle = middle; | ||
this.right = right; | ||
} | ||
|
||
|
||
public Either3<R, M, L> swap() { | ||
if (isLeft()) { | ||
return Eithers.forRight3(left()); | ||
} else if (isMiddle()) { | ||
return Eithers.forMiddle3(middle()); | ||
} else { | ||
return Eithers.forLeft3(right()); | ||
} | ||
} | ||
|
||
public Either3<R, L, M> rotate() { | ||
if (isLeft()) { | ||
return Eithers.forMiddle3(left()); | ||
} else if (isMiddle()) { | ||
return Eithers.forRight3(middle()); | ||
} else { | ||
return Eithers.forLeft3(right()); | ||
} | ||
} | ||
|
||
public L left() { | ||
checkState(isLeft()); | ||
return left; | ||
} | ||
|
||
public M middle() { | ||
checkState(isMiddle()); | ||
return middle; | ||
} | ||
|
||
public R right() { | ||
checkState(isRight()); | ||
return right; | ||
} | ||
|
||
public R get() { | ||
return right(); | ||
} | ||
|
||
public R orElse(R defaultValue) { | ||
if (isRight()) { | ||
return right; | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
public R orElseGet(Supplier<R> defaultSupplier) { | ||
if (isRight()) { | ||
return right; | ||
} else { | ||
return defaultSupplier.get(); | ||
} | ||
} | ||
|
||
public boolean isLeft() { | ||
return left != null; | ||
} | ||
|
||
public boolean isMiddle() { | ||
return middle != null; | ||
} | ||
|
||
public boolean isRight() { | ||
return right != null; | ||
} | ||
|
||
public void forEach( | ||
Consumer<? super R> forRight) { | ||
checkNotNull(forRight); | ||
if (isRight()) { | ||
forRight.accept(right()); | ||
} | ||
} | ||
|
||
public Either3<L, M, R> peek( | ||
Consumer<? super R> forRight) { | ||
checkNotNull(forRight); | ||
if (isRight()) { | ||
forRight.accept(right()); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public <T> Either3<L, M, T> map(Function<? super R, ? extends T> mapRight) { | ||
checkNotNull(mapRight); | ||
if (isRight()) { | ||
return Eithers.forRight3(mapRight.apply(right())); | ||
} | ||
|
||
return propagate(); | ||
} | ||
|
||
public <T> Either3<L, M, T> flatMap( | ||
Function<? super R, Either3<L, M, ? extends T>> flatMapRight) { | ||
checkNotNull(flatMapRight); | ||
if (isRight()) { | ||
return narrow(flatMapRight.apply(right())); | ||
} | ||
|
||
return propagate(); | ||
} | ||
|
||
public <T> T fold( | ||
Function<? super L, ? extends T> foldLeft, | ||
Function<? super M, ? extends T> foldMiddle, | ||
Function<? super R, ? extends T> foldRight) { | ||
checkNotNull(foldLeft); | ||
checkNotNull(foldRight); | ||
if (isRight()) { | ||
return foldRight.apply(right()); | ||
} else if (isMiddle()) { | ||
return foldMiddle.apply(middle()); | ||
} | ||
|
||
return foldLeft.apply(left()); | ||
} | ||
|
||
public <U> U transform( | ||
Function<? super Either3<? super L, ? super M, ? super R>, ? extends U> transform) { | ||
return transform.apply(this); | ||
} | ||
|
||
public Stream<R> stream() { | ||
if (isRight()) { | ||
return Stream.of(right()); | ||
} else { | ||
return Stream.of(); | ||
} | ||
} | ||
|
||
public Optional<R> optional() { | ||
if (isRight()) { | ||
return Optional.of(right()); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected <T> Either3<L, M, T> narrow(Either3<L, M, ? extends T> wide) { | ||
return (Either3<L, M, T>) wide; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected <T> Either3<L, M, T> propagate() { | ||
return (Either3<L, M, T>) this; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof Either3<?, ?, ?>) { | ||
Either3<?, ?, ?> other = (Either3<?, ?, ?>) obj; | ||
return (this.left == other.left && this.right == other.right && this.middle == other.middle) | ||
|| (this.left != null && other.left != null && this.left.equals(other.left)) | ||
|| (this.middle != null && other.middle != null && this.middle.equals(other.middle)) | ||
|| (this.right != null && other.right != null && this.right.equals(other.right)); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public int hashCode() { | ||
if (this.left != null) { | ||
return this.left.hashCode(); | ||
} | ||
|
||
if (this.middle != null) { | ||
return this.middle.hashCode(); | ||
} | ||
|
||
return this.right.hashCode(); | ||
} | ||
} |
Oops, something went wrong.