aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-22 00:31:00 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-22 00:32:28 +0100
commitc8c863ce36f57954369a0b4a15e6c5e720f03f87 (patch)
tree2e49e11db5be949571642ceca947bb7b2178c777 /src/main/java/io/trygvis/esper/testing/sql/SqlOption.java
parent012b0864e95e120ea57433ab0e719cc6011c7647 (diff)
downloadesper-testing-c8c863ce36f57954369a0b4a15e6c5e720f03f87.tar.gz
esper-testing-c8c863ce36f57954369a0b4a15e6c5e720f03f87.tar.bz2
esper-testing-c8c863ce36f57954369a0b4a15e6c5e720f03f87.tar.xz
esper-testing-c8c863ce36f57954369a0b4a15e6c5e720f03f87.zip
o Moving stuff to utils package.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/sql/SqlOption.java')
-rw-r--r--src/main/java/io/trygvis/esper/testing/sql/SqlOption.java109
1 files changed, 0 insertions, 109 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java b/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java
deleted file mode 100644
index 288735a..0000000
--- a/src/main/java/io/trygvis/esper/testing/sql/SqlOption.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package io.trygvis.esper.testing.sql;
-
-import java.sql.*;
-
-public abstract class SqlOption<A> {
- public static <A> SqlOption<A> none() {
- return new None<>();
- }
-
- public static <A> SqlOption<A> some(A a) {
- return new Some<>(a);
- }
-
- public static SqlOption<ResultSet> fromRs(ResultSet rs) throws SQLException {
- if (!rs.next()) {
- return none();
- }
-
- return some(rs);
- }
-
- // -----------------------------------------------------------------------
- //
- // -----------------------------------------------------------------------
-
- public abstract <B> SqlOption<B> map(SqlF<A, B> f) throws SQLException;
-
- public <B> SqlOption<B> flatMap(SqlF<A, SqlOption<B>> f) throws SQLException {
- SqlOption<SqlOption<B>> x = map(f);
-
- if (x.isNone()) {
- return none();
- }
-
- return x.get();
- }
-
- public abstract A get() throws SQLException;
-
- public abstract boolean isSome();
-
- public boolean isNone() {
- return !isSome();
- }
-
- public abstract A getOrElse(A a);
-
- public static <A> SqlOption<A> fromNull(A a) {
- if (a != null) {
- return some(a);
- } else {
- return none();
- }
- }
-
- // -----------------------------------------------------------------------
- //
- // -----------------------------------------------------------------------
-
- private static class None<A> extends SqlOption<A> {
- public <B> SqlOption<B> map(SqlF<A, B> f) {
- return none();
- }
-
- public A get() throws SQLException {
- throw new SQLException("get() on None");
- }
-
- public boolean isSome() {
- return false;
- }
-
- public A getOrElse(A a) {
- return a;
- }
-
- public String toString() {
- return "None";
- }
- }
-
- private static class Some<A> extends SqlOption<A> {
- private final A a;
-
- private Some(A a) {
- this.a = a;
- }
-
- public <B> SqlOption<B> map(SqlF<A, B> f) throws SQLException {
- return some(f.apply(a));
- }
-
- public A get() {
- return a;
- }
-
- public boolean isSome() {
- return true;
- }
-
- public A getOrElse(A a) {
- return this.a;
- }
-
- public String toString() {
- return "Some(" + a + ")";
- }
- }
-}