From c8c863ce36f57954369a0b4a15e6c5e720f03f87 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 22 Dec 2012 00:31:00 +0100 Subject: o Moving stuff to utils package. --- .../io/trygvis/esper/testing/sql/SqlOption.java | 109 --------------------- 1 file changed, 109 deletions(-) delete mode 100644 src/main/java/io/trygvis/esper/testing/sql/SqlOption.java (limited to 'src/main/java/io/trygvis/esper/testing/sql/SqlOption.java') 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 { - public static SqlOption none() { - return new None<>(); - } - - public static SqlOption some(A a) { - return new Some<>(a); - } - - public static SqlOption fromRs(ResultSet rs) throws SQLException { - if (!rs.next()) { - return none(); - } - - return some(rs); - } - - // ----------------------------------------------------------------------- - // - // ----------------------------------------------------------------------- - - public abstract SqlOption map(SqlF f) throws SQLException; - - public SqlOption flatMap(SqlF> f) throws SQLException { - SqlOption> 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 SqlOption fromNull(A a) { - if (a != null) { - return some(a); - } else { - return none(); - } - } - - // ----------------------------------------------------------------------- - // - // ----------------------------------------------------------------------- - - private static class None extends SqlOption { - public SqlOption map(SqlF 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 extends SqlOption { - private final A a; - - private Some(A a) { - this.a = a; - } - - public SqlOption map(SqlF 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 + ")"; - } - } -} -- cgit v1.2.3