repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Null() { // return new Null<>(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // }
import junit.framework.TestCase; import org.junit.Test; import java.util.Objects; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Null; import static org.smallibs.suitcase.cases.core.Cases.Var;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class MatcherTest { @Test public void shouldMatchNullValue() throws Exception { final Matcher<Object, Boolean> isNull = Matcher.create(); isNull.caseOf(Null()).then(true);
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Null() { // return new Null<>(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // Path: src/test/java/org/smallibs/suitcase/match/MatcherTest.java import junit.framework.TestCase; import org.junit.Test; import java.util.Objects; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Null; import static org.smallibs.suitcase.cases.core.Cases.Var; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class MatcherTest { @Test public void shouldMatchNullValue() throws Exception { final Matcher<Object, Boolean> isNull = Matcher.create(); isNull.caseOf(Null()).then(true);
isNull.caseOf(Any()).then(false);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Null() { // return new Null<>(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // }
import junit.framework.TestCase; import org.junit.Test; import java.util.Objects; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Null; import static org.smallibs.suitcase.cases.core.Cases.Var;
TestCase.assertTrue(isInteger.match(0)); TestCase.assertFalse(isInteger.match("0")); } @Test public void shouldMatchIntegerByValue() throws Exception { final Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(0).then(true); isZero.caseOf(Any()).then(false); TestCase.assertTrue(isZero.match(0)); TestCase.assertFalse(isZero.match(1)); } @Test public void shouldMatchIntegerByValueAndSuppliers() throws Exception { final Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(0).then(() -> true); isZero.caseOf(Any()).then(() -> false); TestCase.assertTrue(isZero.match(0)); TestCase.assertFalse(isZero.match(1)); } @Test public void shouldMatchIntegerByValueAndConditional() throws Exception { final Matcher<Integer, Boolean> isZero = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Null() { // return new Null<>(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // Path: src/test/java/org/smallibs/suitcase/match/MatcherTest.java import junit.framework.TestCase; import org.junit.Test; import java.util.Objects; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Null; import static org.smallibs.suitcase.cases.core.Cases.Var; TestCase.assertTrue(isInteger.match(0)); TestCase.assertFalse(isInteger.match("0")); } @Test public void shouldMatchIntegerByValue() throws Exception { final Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(0).then(true); isZero.caseOf(Any()).then(false); TestCase.assertTrue(isZero.match(0)); TestCase.assertFalse(isZero.match(1)); } @Test public void shouldMatchIntegerByValueAndSuppliers() throws Exception { final Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(0).then(() -> true); isZero.caseOf(Any()).then(() -> false); TestCase.assertTrue(isZero.match(0)); TestCase.assertFalse(isZero.match(1)); } @Test public void shouldMatchIntegerByValueAndConditional() throws Exception { final Matcher<Integer, Boolean> isZero = Matcher.create();
isZero.caseOf(Var()).when(i -> i == 0).then(i -> true);
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case5.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case5.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; }
public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case5.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case5.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; }
public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case5.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; } public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) { final Case4<P, R, E1, E2, E3, Pair<E4, E5>> case4 = new Case4<>(predicate, compute1, compute2, compute3, (p -> new Pair<>(compute4.apply(p), compute5.apply(p)))); final WithoutCapture<Pair<E4, E5>, Pair<C4, C5>> capture = e4e5 -> aCase4.unapply(e4e5._1)
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case5.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; } public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) { final Case4<P, R, E1, E2, E3, Pair<E4, E5>> case4 = new Case4<>(predicate, compute1, compute2, compute3, (p -> new Pair<>(compute4.apply(p), compute5.apply(p)))); final WithoutCapture<Pair<E4, E5>, Pair<C4, C5>> capture = e4e5 -> aCase4.unapply(e4e5._1)
.flatMap(c4 -> aCase5.unapply(e4e5._2).map(c5 -> Result.success(new Pair<>(c4.resultValue(), c5.resultValue()))));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case5.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; } public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) { final Case4<P, R, E1, E2, E3, Pair<E4, E5>> case4 = new Case4<>(predicate, compute1, compute2, compute3, (p -> new Pair<>(compute4.apply(p), compute5.apply(p)))); final WithoutCapture<Pair<E4, E5>, Pair<C4, C5>> capture = e4e5 -> aCase4.unapply(e4e5._1) .flatMap(c4 -> aCase5.unapply(e4e5._2).map(c5 -> Result.success(new Pair<>(c4.resultValue(), c5.resultValue())))); return case4.$(aCase1, aCase2, aCase3, capture); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case5.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case5<P, R, E1, E2, E3, E4, E5> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; public Case5(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; } public <C1, C2, C3, C4, C5> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, C5>>>>> $(WithoutCapture<E1,C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) { final Case4<P, R, E1, E2, E3, Pair<E4, E5>> case4 = new Case4<>(predicate, compute1, compute2, compute3, (p -> new Pair<>(compute4.apply(p), compute5.apply(p)))); final WithoutCapture<Pair<E4, E5>, Pair<C4, C5>> capture = e4e5 -> aCase4.unapply(e4e5._1) .flatMap(c4 -> aCase5.unapply(e4e5._2).map(c5 -> Result.success(new Pair<>(c4.resultValue(), c5.resultValue())))); return case4.$(aCase1, aCase2, aCase3, capture); }
public <C1, C2, C3, C4, C5> WithCapture<P, C2> $(WithoutCapture<E1,C1> aCase1, WithCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Null.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import java.util.Optional;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; class Null<T> implements Case.WithoutCapture<T, T> { Null() { // Nothing } @Override
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Null.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import java.util.Optional; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; class Null<T> implements Case.WithoutCapture<T, T> { Null() { // Nothing } @Override
public Optional<Result.WithoutCapture<T>> unapply(T object) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case4.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case4.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; }
public <C1, C2, C3, C4> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, C4>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case4.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case4.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; }
public <C1, C2, C3, C4> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, C4>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case4.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; } public <C1, C2, C3, C4> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, C4>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) { final Case3<P, R, E1, E2, Pair<E3, E4>> case3 = new Case3<>(predicate, compute1, compute2, (p -> new Pair<>(compute3.apply(p), compute4.apply(p)))); final WithoutCapture<Pair<E3, E4>, Pair<C3, C4>> capture = e3e4 -> aCase3.unapply(e3e4._1)
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case4.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; } public <C1, C2, C3, C4> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, C4>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) { final Case3<P, R, E1, E2, Pair<E3, E4>> case3 = new Case3<>(predicate, compute1, compute2, (p -> new Pair<>(compute3.apply(p), compute4.apply(p)))); final WithoutCapture<Pair<E3, E4>, Pair<C3, C4>> capture = e3e4 -> aCase3.unapply(e3e4._1)
.flatMap(c3 -> aCase4.unapply(e3e4._2).map(c4 -> Result.success(new Pair<>(c3.resultValue(), c4.resultValue()))));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case4.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; } public <C1, C2, C3, C4> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, C4>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) { final Case3<P, R, E1, E2, Pair<E3, E4>> case3 = new Case3<>(predicate, compute1, compute2, (p -> new Pair<>(compute3.apply(p), compute4.apply(p)))); final WithoutCapture<Pair<E3, E4>, Pair<C3, C4>> capture = e3e4 -> aCase3.unapply(e3e4._1) .flatMap(c3 -> aCase4.unapply(e3e4._2).map(c4 -> Result.success(new Pair<>(c3.resultValue(), c4.resultValue())))); return case3.$(aCase1, aCase2, capture); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case4.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case4<P, R, E1, E2, E3, E4> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; public Case4(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; } public <C1, C2, C3, C4> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, C4>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) { final Case3<P, R, E1, E2, Pair<E3, E4>> case3 = new Case3<>(predicate, compute1, compute2, (p -> new Pair<>(compute3.apply(p), compute4.apply(p)))); final WithoutCapture<Pair<E3, E4>, Pair<C3, C4>> capture = e3e4 -> aCase3.unapply(e3e4._1) .flatMap(c3 -> aCase4.unapply(e3e4._2).map(c4 -> Result.success(new Pair<>(c3.resultValue(), c4.resultValue())))); return case3.$(aCase1, aCase2, capture); }
public <C1, C2, C3, C4> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/genlex/TokenStream.java
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.utils.Pair; import java.io.IOException; import java.util.Optional;
final Optional<? extends Token<?>> recognize = token.recognize(sequence); if (recognize.isPresent()) { this.sequence.commit(recognize.get().length()); return recognize.get(); } } throw new UnexpectedCharException(sequence.index, sequence.charAt(0)); } public boolean isEmpty() { performSkip(); return sequence.length() == 0; } private void performSkip() { boolean skipped; do { skipped = false; for (Tokenizer<?> token : lexer.getSkipped()) { final Optional<? extends Token<?>> recognize = token.recognize(sequence); if (recognize.isPresent()) { this.sequence.commit(recognize.get().length()); skipped = true; break; } } } while (skipped); }
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/genlex/TokenStream.java import org.smallibs.suitcase.utils.Pair; import java.io.IOException; import java.util.Optional; final Optional<? extends Token<?>> recognize = token.recognize(sequence); if (recognize.isPresent()) { this.sequence.commit(recognize.get().length()); return recognize.get(); } } throw new UnexpectedCharException(sequence.index, sequence.charAt(0)); } public boolean isEmpty() { performSkip(); return sequence.length() == 0; } private void performSkip() { boolean skipped; do { skipped = false; for (Tokenizer<?> token : lexer.getSkipped()) { final Optional<? extends Token<?>> recognize = token.recognize(sequence); if (recognize.isPresent()) { this.sequence.commit(recognize.get().length()); skipped = true; break; } } } while (skipped); }
public Pair<TokenStream, Lexer> setLexer(Lexer lexer) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case3.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case3.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; }
public <C1, C2, C3> WithoutCapture<P, Pair<C1, Pair<C2, C3>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case3.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case3.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; }
public <C1, C2, C3> WithoutCapture<P, Pair<C1, Pair<C2, C3>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case3.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; } public <C1, C2, C3> WithoutCapture<P, Pair<C1, Pair<C2, C3>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) { final Case2<P, R, E1, Pair<E2, E3>> case2 = new Case2<>(predicate, compute1, (p -> new Pair<>(compute2.apply(p), compute3.apply(p)))); final WithoutCapture<Pair<E2, E3>, Pair<C2, C3>> capture = e2e3 -> aCase2.unapply(e2e3._1). flatMap(c2 -> aCase3.unapply(e2e3._2).
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case3.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; } public <C1, C2, C3> WithoutCapture<P, Pair<C1, Pair<C2, C3>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) { final Case2<P, R, E1, Pair<E2, E3>> case2 = new Case2<>(predicate, compute1, (p -> new Pair<>(compute2.apply(p), compute3.apply(p)))); final WithoutCapture<Pair<E2, E3>, Pair<C2, C3>> capture = e2e3 -> aCase2.unapply(e2e3._1). flatMap(c2 -> aCase3.unapply(e2e3._2).
map(c3 -> Result.success(new Pair<>(c2.resultValue(), c3.resultValue()))));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case3.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; } public <C1, C2, C3> WithoutCapture<P, Pair<C1, Pair<C2, C3>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) { final Case2<P, R, E1, Pair<E2, E3>> case2 = new Case2<>(predicate, compute1, (p -> new Pair<>(compute2.apply(p), compute3.apply(p)))); final WithoutCapture<Pair<E2, E3>, Pair<C2, C3>> capture = e2e3 -> aCase2.unapply(e2e3._1). flatMap(c2 -> aCase3.unapply(e2e3._2). map(c3 -> Result.success(new Pair<>(c2.resultValue(), c3.resultValue())))); return case2.$(aCase1, capture); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case3.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; ; public class Case3<P, R, E1, E2, E3> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; public Case3(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; } public <C1, C2, C3> WithoutCapture<P, Pair<C1, Pair<C2, C3>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) { final Case2<P, R, E1, Pair<E2, E3>> case2 = new Case2<>(predicate, compute1, (p -> new Pair<>(compute2.apply(p), compute3.apply(p)))); final WithoutCapture<Pair<E2, E3>, Pair<C2, C3>> capture = e2e3 -> aCase2.unapply(e2e3._1). flatMap(c2 -> aCase3.unapply(e2e3._2). map(c3 -> Result.success(new Pair<>(c2.resultValue(), c3.resultValue())))); return case2.$(aCase1, capture); }
public <C1, C2, C3> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2, WithoutCapture<E3, C3> aCase3) {
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry;
/* * * * Copyright (C)2013 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ package org.smallibs.suitcase.match; public class MapsCaseTest { @Test public void shouldRetrieveAndEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry; /* * * * Copyright (C)2013 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ package org.smallibs.suitcase.match; public class MapsCaseTest { @Test public void shouldRetrieveAndEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
matcher.caseOf(Entry(1, "a")).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry;
/* * * * Copyright (C)2013 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ package org.smallibs.suitcase.match; public class MapsCaseTest { @Test public void shouldRetrieveAndEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, "a")).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry; /* * * * Copyright (C)2013 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ package org.smallibs.suitcase.match; public class MapsCaseTest { @Test public void shouldRetrieveAndEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, "a")).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
matcher.caseOf(Entry(1, Strings.Regex("a+"))).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry;
/* * * * Copyright (C)2013 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ package org.smallibs.suitcase.match; public class MapsCaseTest { @Test public void shouldRetrieveAndEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, "a")).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Strings.Regex("a+"))).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndCaptureEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry; /* * * * Copyright (C)2013 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 2, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */ package org.smallibs.suitcase.match; public class MapsCaseTest { @Test public void shouldRetrieveAndEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, "a")).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Strings.Regex("a+"))).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndCaptureEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
matcher.caseOf(Entry(1, Var())).when(s -> s.equals("a")).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry;
public void shouldRetrieveAndCaptureEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Var())).when(s -> s.equals("a")).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndCaptureEntryUsingKeyRegexp() throws Exception { final Matcher<Map<String, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(Strings.Regex("1|2"), Var())).when(s -> s.equals("a")).then(true); final HashMap<String, String> map = new HashMap<String, String>() {{ this.put("1", "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldNotRetrieveEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Var("b"))).then(true);
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry; public void shouldRetrieveAndCaptureEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Var())).when(s -> s.equals("a")).then(true); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldRetrieveAndCaptureEntryUsingKeyRegexp() throws Exception { final Matcher<Map<String, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(Strings.Regex("1|2"), Var())).when(s -> s.equals("a")).then(true); final HashMap<String, String> map = new HashMap<String, String>() {{ this.put("1", "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldNotRetrieveEntryUsingRegexp() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Var("b"))).then(true);
matcher.caseOf(Any()).then(false);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry;
final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Var("b"))).then(true); matcher.caseOf(Any()).then(false); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertFalse(matcher.match(map)); } @Test public void shouldMatchNonEmptyMap() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(Any(), Any())).then(true); matcher.caseOf(Any()).then(false); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldCaptureAnEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // public interface Strings { // // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // // class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> { // private final Pattern expression; // // public RegularExpression(Pattern expression) { // this.expression = expression; // } // // @Override // public Optional<Result.WithoutCapture<List<String>>> unapply(String s) { // final Matcher matcher = expression.matcher(s); // if (matcher.matches()) { // final List<String> strings = new ArrayList<>(); // for (int i = 0; i <= matcher.groupCount(); i += 1) { // strings.add(s.substring(matcher.start(i), matcher.end(i))); // } // return Optional.of(Result.success(strings)); // } else { // return Optional.empty(); // } // } // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java // static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { // return Entry(Constant(o1), Constant(o2)); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/MapsCaseTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.cases.lang.Strings; import java.util.HashMap; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Maps.Entry; final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(1, Var("b"))).then(true); matcher.caseOf(Any()).then(false); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertFalse(matcher.match(map)); } @Test public void shouldMatchNonEmptyMap() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create(); matcher.caseOf(Entry(Any(), Any())).then(true); matcher.caseOf(Any()).then(false); final HashMap<Integer, String> map = new HashMap<Integer, String>() {{ this.put(1, "a"); }}; TestCase.assertTrue(matcher.match(map)); } @Test public void shouldCaptureAnEntry() throws Exception { final Matcher<Map<Integer, String>, Boolean> matcher = Matcher.create();
matcher.caseOf(Entry(Var(), Var())).then(function((o1, o2) -> o1 == 1 && o2.equals("a")));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/genlex/Tokenizer.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern;
return new QuotedStringRecognizer(); } public static Tokenizer<Integer> Int() { return new IntRecognizer(); } public static Tokenizer<Float> Float() { return new FloatRecognizer(); } public static Tokenizer<Integer> Hexa() { return new HexadecimalRecognizer(); } public static Skip Skip(String value) { return new Skip(value); } public static <T> GenericRecognizer<T> Generic(String kind, Tokenizer<T> value) { return new GenericRecognizer<>(kind, value); } // ----------------------------------------------------------------------------------------------------------------- // Public abstract methods // ----------------------------------------------------------------------------------------------------------------- public abstract Optional<Token<T>> recognize(CharSequence sequence); @Override
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // Path: src/main/java/org/smallibs/suitcase/cases/genlex/Tokenizer.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; return new QuotedStringRecognizer(); } public static Tokenizer<Integer> Int() { return new IntRecognizer(); } public static Tokenizer<Float> Float() { return new FloatRecognizer(); } public static Tokenizer<Integer> Hexa() { return new HexadecimalRecognizer(); } public static Skip Skip(String value) { return new Skip(value); } public static <T> GenericRecognizer<T> Generic(String kind, Tokenizer<T> value) { return new GenericRecognizer<>(kind, value); } // ----------------------------------------------------------------------------------------------------------------- // Public abstract methods // ----------------------------------------------------------------------------------------------------------------- public abstract Optional<Token<T>> recognize(CharSequence sequence); @Override
public Optional<Result.WithoutCapture<Token<T>>> unapply(CharSequence charSequence) {
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() {
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() {
Matcher<Expr, Integer> adder = Matcher.create();
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create();
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create();
adder.caseOf(Var(Nat.class)).then(n -> n.val);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create();
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create();
adder.caseOf(Var(Nat.class)).then(n -> n.val);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create(); adder.caseOf(Var(Nat.class)).then(n -> n.val);
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create(); adder.caseOf(Var(Nat.class)).then(n -> n.val);
adder.caseOf(Var(Add.class)).then(n -> adder.match(n.left) + adder.match(n.right));
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create(); adder.caseOf(Var(Nat.class)).then(n -> n.val); adder.caseOf(Var(Add.class)).then(n -> adder.match(n.left) + adder.match(n.right)); assertEquals((int) adder.match(Expr.Nat(1)), 1); assertEquals((int) adder.match(Expr.Add(Expr.Nat(1), Expr.Nat(3))), 4); } @Test public void shouldEvalCapturedExpression() { Matcher<Expr, Integer> adder = Matcher.create(); adder.caseOf(Nat.$(Var())).then(n -> n);
// Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // public interface Expr { // // static Expr Nat(int i) { // return new Nat(i); // } // // static Expr Add(Expr l, Expr r) { // return new Add(l, r); // } // // static Expr Add3(Expr l, Expr m, Expr r) { // return new Add3(l, m, r); // } // // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // class Add3 implements Expr { // public Expr left, middle, right; // // public Add3(Expr left, Expr middle, Expr right) { // this.left = left; // this.middle = middle; // this.right = right; // } // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Add implements Expr { // public Expr left, right; // // public Add(Expr left, Expr right) { // this.left = left; // this.right = right; // } // } // // Path: src/test/java/org/smallibs/suitcase/cases/ExprTest.java // class Nat implements Expr { // public int val; // // public Nat(int val) { // this.val = val; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ExprMatcherTest.java import org.junit.Test; import org.smallibs.suitcase.cases.ExprTest.Expr; import org.smallibs.suitcase.cases.ExprTest.Expr.Add; import org.smallibs.suitcase.cases.ExprTest.Expr.Nat; import static junit.framework.Assert.assertEquals; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Add3; import static org.smallibs.suitcase.cases.ExprTest.Patterns.Nat; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.utils.Functions.function; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ExprMatcherTest { @Test public void shouldEvalExpression() { Matcher<Expr, Integer> adder = Matcher.create(); adder.caseOf(Var(Nat.class)).then(n -> n.val); adder.caseOf(Var(Add.class)).then(n -> adder.match(n.left) + adder.match(n.right)); assertEquals((int) adder.match(Expr.Nat(1)), 1); assertEquals((int) adder.match(Expr.Add(Expr.Nat(1), Expr.Nat(3))), 4); } @Test public void shouldEvalCapturedExpression() { Matcher<Expr, Integer> adder = Matcher.create(); adder.caseOf(Nat.$(Var())).then(n -> n);
adder.caseOf(Add.$(Var(), Var())).then(function((p1, p2) -> adder.match(p1) + adder.match(p2)));
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();
isEmpty.caseOf(Cons(Constant(1), Any())).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();
isEmpty.caseOf(Cons(Constant(1), Any())).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create();
isEmpty.caseOf(Cons(Constant(1), Any())).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create(); isEmpty.caseOf(Cons(Constant(1), Any())).then(true); isEmpty.caseOf(Any()).then(false); TestCase.assertTrue(isEmpty.match(Collections.singletonList(1))); TestCase.assertFalse(isEmpty.match(Collections.emptyList())); TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3))); } @Test public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException { final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create(); isEmpty.caseOf(Cons(Constant(1), Any())).then(true); isEmpty.caseOf(Any()).then(false); TestCase.assertTrue(isEmpty.match(Collections.singletonList(1))); TestCase.assertFalse(isEmpty.match(Collections.emptyList())); TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3))); } @Test public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException { final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create();
sizeOfMatcher.caseOf(Empty()).then(0);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create(); isEmpty.caseOf(Cons(Constant(1), Any())).then(true); isEmpty.caseOf(Any()).then(false); TestCase.assertTrue(isEmpty.match(Collections.singletonList(1))); TestCase.assertFalse(isEmpty.match(Collections.emptyList())); TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3))); } @Test public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException { final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create(); sizeOfMatcher.caseOf(Empty()).then(0);
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create(); isEmpty.caseOf(Cons(Constant(1), Any())).then(true); isEmpty.caseOf(Any()).then(false); TestCase.assertTrue(isEmpty.match(Collections.singletonList(1))); TestCase.assertFalse(isEmpty.match(Collections.emptyList())); TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3))); } @Test public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException { final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create(); sizeOfMatcher.caseOf(Empty()).then(0);
sizeOfMatcher.caseOf(Cons(Any(), Var())).then(tail -> 1 + sizeOfMatcher.match(tail));
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // }
import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create(); isEmpty.caseOf(Cons(Constant(1), Any())).then(true); isEmpty.caseOf(Any()).then(false); TestCase.assertTrue(isEmpty.match(Collections.singletonList(1))); TestCase.assertFalse(isEmpty.match(Collections.emptyList())); TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3))); } @Test public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException { final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create(); sizeOfMatcher.caseOf(Empty()).then(0); sizeOfMatcher.caseOf(Cons(Any(), Var())).then(tail -> 1 + sizeOfMatcher.match(tail)); TestCase.assertEquals(0, sizeOfMatcher.match(Collections.emptyList()).intValue()); TestCase.assertEquals(4, sizeOfMatcher.match(Arrays.asList(1, 2, 3, 4)).intValue()); } @Test public void shouldComputeAdditionWithAdHocPatternObject() throws MatchingException { final Matcher<List<Integer>, Integer> addAll = Matcher.create(); addAll.caseOf(Empty()).then(0);
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case2<List<T>, List<T>, T, List<T>> Cons() { // return new Case2<>( // l -> !l.isEmpty() ? Optional.of(l) : Optional.empty(), // l -> l.get(0), // l -> l.subList(1, l.size()) // ); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Lists.java // static <T> Case.WithoutCapture<List<T>, List<T>> Empty() { // return new Case0<List<T>, List<T>>( // p -> p.isEmpty() ? Optional.of(p) : Optional.empty() // ).$(); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public static <C1, C2, R> Function<Pair<C1, C2>, R> function(Function2<C1, C2, R> function) { // return params -> function.apply(params._1, params._2); // } // Path: src/test/java/org/smallibs/suitcase/match/ListMatcherTest.java import static org.smallibs.suitcase.utils.Functions.function; import junit.framework.TestCase; import org.junit.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Constant; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Lists.Cons; import static org.smallibs.suitcase.cases.lang.Lists.Empty; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class ListMatcherTest { @Test public void shouldMatchLisContainingAnObject() throws MatchingException { final Matcher<List<Integer>, Boolean> isEmpty = Matcher.create(); isEmpty.caseOf(Cons(Constant(1), Any())).then(true); isEmpty.caseOf(Any()).then(false); TestCase.assertTrue(isEmpty.match(Collections.singletonList(1))); TestCase.assertFalse(isEmpty.match(Collections.emptyList())); TestCase.assertFalse(isEmpty.match(Arrays.asList(2, 3))); } @Test public void shouldComputeListSizeWithAdHocPatternObject() throws MatchingException { final Matcher<List<?>, Integer> sizeOfMatcher = Matcher.create(); sizeOfMatcher.caseOf(Empty()).then(0); sizeOfMatcher.caseOf(Cons(Any(), Var())).then(tail -> 1 + sizeOfMatcher.match(tail)); TestCase.assertEquals(0, sizeOfMatcher.match(Collections.emptyList()).intValue()); TestCase.assertEquals(4, sizeOfMatcher.match(Arrays.asList(1, 2, 3, 4)).intValue()); } @Test public void shouldComputeAdditionWithAdHocPatternObject() throws MatchingException { final Matcher<List<Integer>, Integer> addAll = Matcher.create(); addAll.caseOf(Empty()).then(0);
addAll.caseOf(Cons(Var(), Var())).then(function((p1,p2) -> p1 + addAll.match(p2)));
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/RegexpMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // }
import junit.framework.TestCase; import org.junit.Test; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.lang.Strings.Regex;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class RegexpMatcherTest { @Test public void shouldMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // Path: src/test/java/org/smallibs/suitcase/match/RegexpMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.lang.Strings.Regex; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class RegexpMatcherTest { @Test public void shouldMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create();
matcher.caseOf(Regex("Hello")).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/RegexpMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // }
import junit.framework.TestCase; import org.junit.Test; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.lang.Strings.Regex;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class RegexpMatcherTest { @Test public void shouldMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create(); matcher.caseOf(Regex("Hello")).then(true);
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // Path: src/test/java/org/smallibs/suitcase/match/RegexpMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.lang.Strings.Regex; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class RegexpMatcherTest { @Test public void shouldMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create(); matcher.caseOf(Regex("Hello")).then(true);
matcher.caseOf(Any()).then(false);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/RegexpMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // }
import junit.framework.TestCase; import org.junit.Test; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.lang.Strings.Regex;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class RegexpMatcherTest { @Test public void shouldMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create(); matcher.caseOf(Regex("Hello")).then(true); matcher.caseOf(Any()).then(false); TestCase.assertTrue(matcher.match("Hello")); } @Test public void shouldNotMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create(); matcher.caseOf(Regex("Hello")).then(true); matcher.caseOf(Any()).then(false); TestCase.assertFalse(matcher.match("Hello, World")); } @Test public void shouldMatchSubStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java // static WithoutCapture<String, List<String>> Regex(String expression) { // return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); // } // Path: src/test/java/org/smallibs/suitcase/match/RegexpMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.lang.Strings.Regex; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class RegexpMatcherTest { @Test public void shouldMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create(); matcher.caseOf(Regex("Hello")).then(true); matcher.caseOf(Any()).then(false); TestCase.assertTrue(matcher.match("Hello")); } @Test public void shouldNotMatchStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create(); matcher.caseOf(Regex("Hello")).then(true); matcher.caseOf(Any()).then(false); TestCase.assertFalse(matcher.match("Hello, World")); } @Test public void shouldMatchSubStringUsingRegex() throws Exception { final Matcher<String, Boolean> matcher = Matcher.create();
matcher.caseOf(Var(Regex("Hello, (.*)"))).then(strings -> strings.get(1).equals("World"));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; }
public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; }
public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; } public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithoutCapture.adapt(new Pattern<>(
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; } public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithoutCapture.adapt(new Pattern<>(
(c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())),
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; } public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithoutCapture.adapt(new Pattern<>( (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public class Case2<P, R, E1, E2> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; public Case2(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; } public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithoutCapture.adapt(new Pattern<>( (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); }
public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; } public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithoutCapture.adapt(new Pattern<>( (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); } public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c1, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, C2> $(WithoutCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c2, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, Pair<C1, C2>> $(WithCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>(
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; } public <C1, C2> WithoutCapture<P, Pair<C1, C2>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithoutCapture.adapt(new Pattern<>( (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); } public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c1, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, C2> $(WithoutCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c2, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, Pair<C1, C2>> $(WithCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>(
(c1, c2) -> successWithCapture(new Pair<>(c1.resultValue(), c2.resultValue())),
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
return WithoutCapture.adapt(new Pattern<>( (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); } public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c1, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, C2> $(WithoutCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c2, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, Pair<C1, C2>> $(WithCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> successWithCapture(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2) ); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; return WithoutCapture.adapt(new Pattern<>( (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); } public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c1, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, C2> $(WithoutCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c2, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, Pair<C1, C2>> $(WithCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> successWithCapture(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2) ); }
public class Pattern<C1, C2, C> implements Case<P, C> {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case2.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture;
(c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); } public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c1, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, C2> $(WithoutCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c2, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, Pair<C1, C2>> $(WithCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> successWithCapture(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2) ); } public class Pattern<C1, C2, C> implements Case<P, C> {
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/utils/Functions.java // public interface Function2<A, B, R> { // R apply(A a, B b); // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case2.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.utils.Functions.Function2; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; import static org.smallibs.suitcase.cases.Result.success; import static org.smallibs.suitcase.cases.Result.successWithCapture; (c1, c2) -> success(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2)); } public <C1, C2> WithCapture<P, C1> $(WithCapture<E1, C1> aCase1, WithoutCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c1, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, C2> $(WithoutCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> c2, aCase1, aCase2) ); } public <C1, C2> WithCapture<P, Pair<C1, C2>> $(WithCapture<E1, C1> aCase1, WithCapture<E2, C2> aCase2) { return WithCapture.adapt(new Pattern<>( (c1, c2) -> successWithCapture(new Pair<>(c1.resultValue(), c2.resultValue())), aCase1, aCase2) ); } public class Pattern<C1, C2, C> implements Case<P, C> {
private final Function2<C1, C2, C> combination;
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/lang/Strings.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern;
package org.smallibs.suitcase.cases.lang; public interface Strings { static WithoutCapture<String, List<String>> Regex(String expression) { return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; package org.smallibs.suitcase.cases.lang; public interface Strings { static WithoutCapture<String, List<String>> Regex(String expression) { return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); }
class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/lang/Strings.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern;
package org.smallibs.suitcase.cases.lang; public interface Strings { static WithoutCapture<String, List<String>> Regex(String expression) { return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // Path: src/main/java/org/smallibs/suitcase/cases/lang/Strings.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; package org.smallibs.suitcase.cases.lang; public interface Strings { static WithoutCapture<String, List<String>> Regex(String expression) { return WithoutCapture.adapt(new RegularExpression(Pattern.compile(expression))); }
class RegularExpression implements Case<String, Result.WithoutCapture<List<String>>> {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Cases.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // }
import org.smallibs.suitcase.cases.Case; import java.util.Objects; import java.util.Optional;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public interface Cases { static <T> Var.WithoutInnerCapture<T, T> Var() { return Var(Any()); } static <T> Var.WithoutInnerCapture<T, T> Var(T value) { return Var(Constant(value)); } static <T> Var.WithoutInnerCapture<T, T> Var(Class<T> value) { return Var(typeOf(value)); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java import org.smallibs.suitcase.cases.Case; import java.util.Objects; import java.util.Optional; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public interface Cases { static <T> Var.WithoutInnerCapture<T, T> Var() { return Var(Any()); } static <T> Var.WithoutInnerCapture<T, T> Var(T value) { return Var(Constant(value)); } static <T> Var.WithoutInnerCapture<T, T> Var(Class<T> value) { return Var(typeOf(value)); }
static <T, R> Var.WithoutInnerCapture<T, R> Var(Case.WithoutCapture<T, R> value) {
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // }
import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // } // Path: src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create();
isZero.caseOf(Zero()).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // }
import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(Zero()).then(true);
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // } // Path: src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(Zero()).then(true);
isZero.caseOf(Succ(Any())).then(false);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // }
import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(Zero()).then(true);
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // } // Path: src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(Zero()).then(true);
isZero.caseOf(Succ(Any())).then(false);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // }
import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(Zero()).then(true); isZero.caseOf(Succ(Any())).then(false); TestCase.assertEquals((boolean) isZero.match(0), true); TestCase.assertEquals((boolean) isZero.match(1), false); } @Test public void shouldMatchExtractedInteger() throws Exception { final Matcher<Integer, Optional<Integer>> minus2 = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Succ(int i) { // return Succ.$(Constant(i)); // } // // Path: src/test/java/org/smallibs/suitcase/cases/PeanoTest.java // public static WithoutCapture<Integer, Integer> Zero() { // return Zero.$(); // } // Path: src/test/java/org/smallibs/suitcase/match/PeanoMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import java.util.Optional; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.PeanoTest.Succ; import static org.smallibs.suitcase.cases.PeanoTest.Zero; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PeanoMatcherTest { @Test public void shouldCheckZero() throws Exception { Matcher<Integer, Boolean> isZero = Matcher.create(); isZero.caseOf(Zero()).then(true); isZero.caseOf(Succ(Any())).then(false); TestCase.assertEquals((boolean) isZero.match(0), true); TestCase.assertEquals((boolean) isZero.match(1), false); } @Test public void shouldMatchExtractedInteger() throws Exception { final Matcher<Integer, Optional<Integer>> minus2 = Matcher.create();
minus2.caseOf(Succ(Succ(Var()))).then(Optional::of);
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/lang/Maps.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Constant;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.lang; public interface Maps { static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) {
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Constant; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.lang; public interface Maps { static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) {
return Entry(Constant(o1), Constant(o2));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/lang/Maps.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Constant;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.lang; public interface Maps { static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { return Entry(Constant(o1), Constant(o2)); } static <T1, T2, C2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, C2>> Entry(T1 o1, Case.WithoutCapture<T2, C2> o2) { return Entry(Constant(o1), o2); } static <T1, T2, C1> Case.WithoutCapture<Map<T1, T2>, Pair<C1, T2>> Entry(Case.WithoutCapture<T1, C1> o1, T2 o2) { return Entry(o1, Constant(o2)); } static <T1, T2, C2> Case.WithCapture<Map<T1, T2>, C2> Entry(T1 o1, Case.WithCapture<T2, C2> o2) { return Entry(Constant(o1), o2); } static <T1, T2, C1> Case.WithCapture<Map<T1, T2>, C1> Entry(Case.WithCapture<T1, C1> o1, T2 o2) { return Entry(o1, Constant(o2)); } static <T1, T2, C1, C2> Case.WithoutCapture<Map<T1, T2>, Pair<C1, C2>> Entry(Case.WithoutCapture<T1, C1> o1, Case.WithoutCapture<T2, C2> o2) { return map -> map.keySet().stream().filter(k -> o1.unapply(k).isPresent()).findFirst().
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // Path: src/main/java/org/smallibs/suitcase/cases/lang/Maps.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Map; import static org.smallibs.suitcase.cases.core.Cases.Constant; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.lang; public interface Maps { static <T1, T2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, T2>> Entry(T1 o1, T2 o2) { return Entry(Constant(o1), Constant(o2)); } static <T1, T2, C2> Case.WithoutCapture<Map<T1, T2>, Pair<T1, C2>> Entry(T1 o1, Case.WithoutCapture<T2, C2> o2) { return Entry(Constant(o1), o2); } static <T1, T2, C1> Case.WithoutCapture<Map<T1, T2>, Pair<C1, T2>> Entry(Case.WithoutCapture<T1, C1> o1, T2 o2) { return Entry(o1, Constant(o2)); } static <T1, T2, C2> Case.WithCapture<Map<T1, T2>, C2> Entry(T1 o1, Case.WithCapture<T2, C2> o2) { return Entry(Constant(o1), o2); } static <T1, T2, C1> Case.WithCapture<Map<T1, T2>, C1> Entry(Case.WithCapture<T1, C1> o1, T2 o2) { return Entry(o1, Constant(o2)); } static <T1, T2, C1, C2> Case.WithoutCapture<Map<T1, T2>, Pair<C1, C2>> Entry(Case.WithoutCapture<T1, C1> o1, Case.WithoutCapture<T2, C2> o2) { return map -> map.keySet().stream().filter(k -> o1.unapply(k).isPresent()).findFirst().
flatMap(k -> o2.unapply(map.get(k)).map(c2 -> Result.success(new Pair<>(o1.unapply(k).get().resultValue(), c2.resultValue()))));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Var.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import java.util.Optional; import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public interface Var { class WithInnerCapture<T, R> implements Case.WithCapture<T, Pair<T, R>> { private final Case.WithCapture<T, R> aCase; public WithInnerCapture(Case.WithCapture<T, R> aCase) { this.aCase = aCase; } @Override
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Var.java import java.util.Optional; import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.core; public interface Var { class WithInnerCapture<T, R> implements Case.WithCapture<T, Pair<T, R>> { private final Case.WithCapture<T, R> aCase; public WithInnerCapture(Case.WithCapture<T, R> aCase) { this.aCase = aCase; } @Override
public Optional<Result.WithCapture<Pair<T, R>>> unapply(T t) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case6.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case6.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; }
public <C1, C2, C3, C4, C5, C6> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, Pair<C5, C6>>>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case6.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case6.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; }
public <C1, C2, C3, C4, C5, C6> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, Pair<C5, C6>>>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case6.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; } public <C1, C2, C3, C4, C5, C6> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, Pair<C5, C6>>>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) { final Case5<P, R, E1, E2, E3, E4, Pair<E5, E6>> case5 = new Case5<>(predicate, compute1, compute2, compute3, compute4, (p -> new Pair<>(compute5.apply(p), compute6.apply(p)))); final WithoutCapture<Pair<E5, E6>, Pair<C5, C6>> capture = e5e6 -> aCase5.unapply(e5e6._1)
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case6.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; } public <C1, C2, C3, C4, C5, C6> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, Pair<C5, C6>>>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) { final Case5<P, R, E1, E2, E3, E4, Pair<E5, E6>> case5 = new Case5<>(predicate, compute1, compute2, compute3, compute4, (p -> new Pair<>(compute5.apply(p), compute6.apply(p)))); final WithoutCapture<Pair<E5, E6>, Pair<C5, C6>> capture = e5e6 -> aCase5.unapply(e5e6._1)
.flatMap(c5 -> aCase6.unapply(e5e6._2).map(c6 -> Result.success(new Pair<>(c5.resultValue(), c6.resultValue()))));
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/core/Case6.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // }
import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function;
/* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; } public <C1, C2, C3, C4, C5, C6> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, Pair<C5, C6>>>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) { final Case5<P, R, E1, E2, E3, E4, Pair<E5, E6>> case5 = new Case5<>(predicate, compute1, compute2, compute3, compute4, (p -> new Pair<>(compute5.apply(p), compute6.apply(p)))); final WithoutCapture<Pair<E5, E6>, Pair<C5, C6>> capture = e5e6 -> aCase5.unapply(e5e6._1) .flatMap(c5 -> aCase6.unapply(e5e6._2).map(c6 -> Result.success(new Pair<>(c5.resultValue(), c6.resultValue())))); return case5.$(aCase1, aCase2, aCase3, aCase4, capture); }
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Case.java // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/Result.java // public abstract class Result<R> { // // public static <R> WithoutCapture<R> success(R term) { // return new WithoutCapture<>(term); // } // // public static <C> WithCapture<C> successWithCapture(C result) { // return new WithCapture<>(result); // } // // private final R capturedObject; // // public Result(R capturedObject) { // this.capturedObject = capturedObject; // } // // public R resultValue() { // return capturedObject; // } // // public static class WithCapture<C> extends Result<C> { // public WithCapture(C capturedObject) { // super(capturedObject); // } // } // // public static class WithoutCapture<T> extends Result<T> { // public WithoutCapture(T capturedObject) { // super(capturedObject); // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // Path: src/main/java/org/smallibs/suitcase/cases/core/Case6.java import org.smallibs.suitcase.cases.Case.WithCapture; import org.smallibs.suitcase.cases.Case.WithoutCapture; import org.smallibs.suitcase.cases.Result; import org.smallibs.suitcase.utils.Pair; import java.util.Optional; import java.util.function.Function; /* * * * Copyright (C)3024 D. Plaindoux. * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published * * by the Free Software Foundation; either version 3, or (at your option) any * * later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, 676 Mass Ave, Cambridge, MA 03249, USA. * */ package org.smallibs.suitcase.cases.core; ; public class Case6<P, R, E1, E2, E3, E4, E5, E6> { private final Function<P, Optional<R>> predicate; private final Function<P, E1> compute1; private final Function<P, E2> compute2; private final Function<P, E3> compute3; private final Function<P, E4> compute4; private final Function<P, E5> compute5; private final Function<P, E6> compute6; public Case6(Function<P, Optional<R>> predicate, Function<P, E1> compute1, Function<P, E2> compute2, Function<P, E3> compute3, Function<P, E4> compute4, Function<P, E5> compute5, Function<P, E6> compute6) { this.predicate = predicate; this.compute1 = compute1; this.compute2 = compute2; this.compute3 = compute3; this.compute4 = compute4; this.compute5 = compute5; this.compute6 = compute6; } public <C1, C2, C3, C4, C5, C6> WithoutCapture<P, Pair<C1, Pair<C2, Pair<C3, Pair<C4, Pair<C5, C6>>>>>> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithoutCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) { final Case5<P, R, E1, E2, E3, E4, Pair<E5, E6>> case5 = new Case5<>(predicate, compute1, compute2, compute3, compute4, (p -> new Pair<>(compute5.apply(p), compute6.apply(p)))); final WithoutCapture<Pair<E5, E6>, Pair<C5, C6>> capture = e5e6 -> aCase5.unapply(e5e6._1) .flatMap(c5 -> aCase6.unapply(e5e6._2).map(c6 -> Result.success(new Pair<>(c5.resultValue(), c6.resultValue())))); return case5.$(aCase1, aCase2, aCase3, aCase4, capture); }
public <C1, C2, C3, C4, C5, C6> WithCapture<P, C3> $(WithoutCapture<E1, C1> aCase1, WithoutCapture<E2,C2> aCase2, WithCapture<E3, C3> aCase3, WithoutCapture<E4, C4> aCase4, WithoutCapture<E5, C5> aCase5, WithoutCapture<E6, C6> aCase6) {
d-plaindoux/suitcase
src/main/java/org/smallibs/suitcase/cases/lang/Beans.java
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // public interface Cases { // // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // static <T> Var.WithoutInnerCapture<T, T> Var(T value) { // return Var(Constant(value)); // } // // static <T> Var.WithoutInnerCapture<T, T> Var(Class<T> value) { // return Var(typeOf(value)); // } // // static <T, R> Var.WithoutInnerCapture<T, R> Var(Case.WithoutCapture<T, R> value) { // return new Var.WithoutInnerCapture<>(value); // } // // static <T, R> Var.WithInnerCapture<T, R> Var(Case.WithCapture<T, R> value) { // return new Var.WithInnerCapture<>(value); // } // // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // static <T> Case.WithoutCapture<T, T> Null() { // return new Null<>(); // } // // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // static <T> Case.WithoutCapture<T, T> typeOf(Class<T> type) { // return new Case0<T, T>(p -> p.getClass().isAssignableFrom(type) ? Optional.of(type.cast(p)) : Optional.empty()).$(); // } // }
import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.core.Cases; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Optional;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.lang; public interface Beans { static <T, R, C> Case.WithoutCapture<T, C> Att(String nameCase, Case.WithoutCapture<R, C> valueCase) {
// Path: src/main/java/org/smallibs/suitcase/cases/Case.java // public interface Case<T, R> { // // Optional<R> unapply(T t); // // interface WithoutCapture<T, R> extends Case<T, Result.WithoutCapture<R>> { // static <T, R> WithoutCapture<T, R> adapt(Case<T, Result.WithoutCapture<R>> aCase) { // return aCase::unapply; // } // } // // interface WithCapture<T, R> extends Case<T, Result.WithCapture<R>> { // static <T, R> WithCapture<T, R> adapt(Case<T, Result.WithCapture<R>> aCase) { // return aCase::unapply; // } // } // // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // public interface Cases { // // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // static <T> Var.WithoutInnerCapture<T, T> Var(T value) { // return Var(Constant(value)); // } // // static <T> Var.WithoutInnerCapture<T, T> Var(Class<T> value) { // return Var(typeOf(value)); // } // // static <T, R> Var.WithoutInnerCapture<T, R> Var(Case.WithoutCapture<T, R> value) { // return new Var.WithoutInnerCapture<>(value); // } // // static <T, R> Var.WithInnerCapture<T, R> Var(Case.WithCapture<T, R> value) { // return new Var.WithInnerCapture<>(value); // } // // static <T> Case.WithoutCapture<T, T> Constant(T value) { // return new Case0<T, T>(p -> Objects.deepEquals(p, value) ? Optional.of(p) : Optional.empty()).$(); // } // // static <T> Case.WithoutCapture<T, T> Null() { // return new Null<>(); // } // // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // static <T> Case.WithoutCapture<T, T> typeOf(Class<T> type) { // return new Case0<T, T>(p -> p.getClass().isAssignableFrom(type) ? Optional.of(type.cast(p)) : Optional.empty()).$(); // } // } // Path: src/main/java/org/smallibs/suitcase/cases/lang/Beans.java import org.smallibs.suitcase.cases.Case; import org.smallibs.suitcase.cases.core.Cases; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Optional; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.cases.lang; public interface Beans { static <T, R, C> Case.WithoutCapture<T, C> Att(String nameCase, Case.WithoutCapture<R, C> valueCase) {
return Att(Cases.Constant(nameCase), valueCase);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PairMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Pairs.java // static <T1, T2> Case2<Pair<T1, T2>, Pair<T1, T2>, T1, T2> Pair() { // return new Case2<>( // Optional::of, // l -> l._1, // l -> l._2 // ); // }
import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.utils.Pair; import static java.util.function.Function.identity; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Pairs.Pair;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PairMatcherTest { @Test public void shouldMatchAPair() { final Matcher<Object, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Pairs.java // static <T1, T2> Case2<Pair<T1, T2>, Pair<T1, T2>, T1, T2> Pair() { // return new Case2<>( // Optional::of, // l -> l._1, // l -> l._2 // ); // } // Path: src/test/java/org/smallibs/suitcase/match/PairMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.utils.Pair; import static java.util.function.Function.identity; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Pairs.Pair; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PairMatcherTest { @Test public void shouldMatchAPair() { final Matcher<Object, Boolean> matcher = Matcher.create();
matcher.caseOf(Pair(Any(), Any())).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PairMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Pairs.java // static <T1, T2> Case2<Pair<T1, T2>, Pair<T1, T2>, T1, T2> Pair() { // return new Case2<>( // Optional::of, // l -> l._1, // l -> l._2 // ); // }
import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.utils.Pair; import static java.util.function.Function.identity; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Pairs.Pair;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PairMatcherTest { @Test public void shouldMatchAPair() { final Matcher<Object, Boolean> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Pairs.java // static <T1, T2> Case2<Pair<T1, T2>, Pair<T1, T2>, T1, T2> Pair() { // return new Case2<>( // Optional::of, // l -> l._1, // l -> l._2 // ); // } // Path: src/test/java/org/smallibs/suitcase/match/PairMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.utils.Pair; import static java.util.function.Function.identity; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Pairs.Pair; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PairMatcherTest { @Test public void shouldMatchAPair() { final Matcher<Object, Boolean> matcher = Matcher.create();
matcher.caseOf(Pair(Any(), Any())).then(true);
d-plaindoux/suitcase
src/test/java/org/smallibs/suitcase/match/PairMatcherTest.java
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Pairs.java // static <T1, T2> Case2<Pair<T1, T2>, Pair<T1, T2>, T1, T2> Pair() { // return new Case2<>( // Optional::of, // l -> l._1, // l -> l._2 // ); // }
import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.utils.Pair; import static java.util.function.Function.identity; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Pairs.Pair;
/* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PairMatcherTest { @Test public void shouldMatchAPair() { final Matcher<Object, Boolean> matcher = Matcher.create(); matcher.caseOf(Pair(Any(), Any())).then(true); TestCase.assertTrue(matcher.match(new Pair<>(1, 2))); } @Test public void shouldMatchAPairAndGetFirst() { final Matcher<Pair<Integer, String>, Integer> matcher = Matcher.create();
// Path: src/main/java/org/smallibs/suitcase/utils/Pair.java // public class Pair<T1, T2> { // // public final T1 _1; // public final T2 _2; // // public Pair(T1 _1, T2 _2) { // this._1 = _1; // this._2 = _2; // } // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Case.WithoutCapture<T, T> Any() { // return new Case0<T, T>(Optional::of).$(); // } // // Path: src/main/java/org/smallibs/suitcase/cases/core/Cases.java // static <T> Var.WithoutInnerCapture<T, T> Var() { // return Var(Any()); // } // // Path: src/main/java/org/smallibs/suitcase/cases/lang/Pairs.java // static <T1, T2> Case2<Pair<T1, T2>, Pair<T1, T2>, T1, T2> Pair() { // return new Case2<>( // Optional::of, // l -> l._1, // l -> l._2 // ); // } // Path: src/test/java/org/smallibs/suitcase/match/PairMatcherTest.java import junit.framework.TestCase; import org.junit.Test; import org.smallibs.suitcase.utils.Pair; import static java.util.function.Function.identity; import static org.smallibs.suitcase.cases.core.Cases.Any; import static org.smallibs.suitcase.cases.core.Cases.Var; import static org.smallibs.suitcase.cases.lang.Pairs.Pair; /* * Copyright (C)2015 D. Plaindoux. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 2, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.smallibs.suitcase.match; public class PairMatcherTest { @Test public void shouldMatchAPair() { final Matcher<Object, Boolean> matcher = Matcher.create(); matcher.caseOf(Pair(Any(), Any())).then(true); TestCase.assertTrue(matcher.match(new Pair<>(1, 2))); } @Test public void shouldMatchAPairAndGetFirst() { final Matcher<Pair<Integer, String>, Integer> matcher = Matcher.create();
matcher.caseOf(Pair(Var(), Any())).then(e -> e);
MarcGiffing/wicket-spring-boot-examples
simple-war/src/test/java/com/giffing/examples/wicket/spring/boot/simple/HomePageTest.java
// Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/HomePage.java // @WicketHomePage // public class HomePage extends WebPage { // // Label currentTime; // // public HomePage() { // currentTime = new Label( "currentTime", "no time" ); // currentTime.setOutputMarkupId( true ); // add(currentTime); // // Form form = new Form("form"){ // @Override // protected void onSubmit() { // setResponsePage(SecondPage.class); // } // }; // queue(form); // // // add(new Link<Void>("mylink") { // @Override // public void onClick() { // setResponsePage(SecondPage.class); // } // }); // } // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/SecondPage.java // public class SecondPage extends WebPage { // // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/WicketApplication.java // @SpringBootApplication // public class WicketApplication extends SpringBootServletInitializer { // // public static void main(String[] args) throws Exception { // new SpringApplicationBuilder() // .sources(WicketApplication.class) // .run(args); // } // // }
import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTester; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import com.giffing.examples.wicket.spring.boot.simplewar.HomePage; import com.giffing.examples.wicket.spring.boot.simplewar.SecondPage; import com.giffing.examples.wicket.spring.boot.simplewar.WicketApplication;
package com.giffing.examples.wicket.spring.boot.simple; @RunWith(SpringRunner.class) @SpringBootTest(classes = WicketApplication.class) public class HomePageTest { private WicketTester tester; @Autowired private WebApplication wicketApplication; @Autowired private ApplicationContext applicationContextMock; @Before public void setUp() { ReflectionTestUtils.setField(wicketApplication, "applicationContext", applicationContextMock); tester = new WicketTester(wicketApplication); } @Test public void testest() {
// Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/HomePage.java // @WicketHomePage // public class HomePage extends WebPage { // // Label currentTime; // // public HomePage() { // currentTime = new Label( "currentTime", "no time" ); // currentTime.setOutputMarkupId( true ); // add(currentTime); // // Form form = new Form("form"){ // @Override // protected void onSubmit() { // setResponsePage(SecondPage.class); // } // }; // queue(form); // // // add(new Link<Void>("mylink") { // @Override // public void onClick() { // setResponsePage(SecondPage.class); // } // }); // } // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/SecondPage.java // public class SecondPage extends WebPage { // // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/WicketApplication.java // @SpringBootApplication // public class WicketApplication extends SpringBootServletInitializer { // // public static void main(String[] args) throws Exception { // new SpringApplicationBuilder() // .sources(WicketApplication.class) // .run(args); // } // // } // Path: simple-war/src/test/java/com/giffing/examples/wicket/spring/boot/simple/HomePageTest.java import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTester; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import com.giffing.examples.wicket.spring.boot.simplewar.HomePage; import com.giffing.examples.wicket.spring.boot.simplewar.SecondPage; import com.giffing.examples.wicket.spring.boot.simplewar.WicketApplication; package com.giffing.examples.wicket.spring.boot.simple; @RunWith(SpringRunner.class) @SpringBootTest(classes = WicketApplication.class) public class HomePageTest { private WicketTester tester; @Autowired private WebApplication wicketApplication; @Autowired private ApplicationContext applicationContextMock; @Before public void setUp() { ReflectionTestUtils.setField(wicketApplication, "applicationContext", applicationContextMock); tester = new WicketTester(wicketApplication); } @Test public void testest() {
tester.startPage(HomePage.class);
MarcGiffing/wicket-spring-boot-examples
simple-war/src/test/java/com/giffing/examples/wicket/spring/boot/simple/HomePageTest.java
// Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/HomePage.java // @WicketHomePage // public class HomePage extends WebPage { // // Label currentTime; // // public HomePage() { // currentTime = new Label( "currentTime", "no time" ); // currentTime.setOutputMarkupId( true ); // add(currentTime); // // Form form = new Form("form"){ // @Override // protected void onSubmit() { // setResponsePage(SecondPage.class); // } // }; // queue(form); // // // add(new Link<Void>("mylink") { // @Override // public void onClick() { // setResponsePage(SecondPage.class); // } // }); // } // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/SecondPage.java // public class SecondPage extends WebPage { // // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/WicketApplication.java // @SpringBootApplication // public class WicketApplication extends SpringBootServletInitializer { // // public static void main(String[] args) throws Exception { // new SpringApplicationBuilder() // .sources(WicketApplication.class) // .run(args); // } // // }
import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTester; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import com.giffing.examples.wicket.spring.boot.simplewar.HomePage; import com.giffing.examples.wicket.spring.boot.simplewar.SecondPage; import com.giffing.examples.wicket.spring.boot.simplewar.WicketApplication;
package com.giffing.examples.wicket.spring.boot.simple; @RunWith(SpringRunner.class) @SpringBootTest(classes = WicketApplication.class) public class HomePageTest { private WicketTester tester; @Autowired private WebApplication wicketApplication; @Autowired private ApplicationContext applicationContextMock; @Before public void setUp() { ReflectionTestUtils.setField(wicketApplication, "applicationContext", applicationContextMock); tester = new WicketTester(wicketApplication); } @Test public void testest() { tester.startPage(HomePage.class); FormTester newFormTester = tester.newFormTester("form"); newFormTester.submit();
// Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/HomePage.java // @WicketHomePage // public class HomePage extends WebPage { // // Label currentTime; // // public HomePage() { // currentTime = new Label( "currentTime", "no time" ); // currentTime.setOutputMarkupId( true ); // add(currentTime); // // Form form = new Form("form"){ // @Override // protected void onSubmit() { // setResponsePage(SecondPage.class); // } // }; // queue(form); // // // add(new Link<Void>("mylink") { // @Override // public void onClick() { // setResponsePage(SecondPage.class); // } // }); // } // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/SecondPage.java // public class SecondPage extends WebPage { // // } // // Path: simple-war/src/main/java/com/giffing/examples/wicket/spring/boot/simplewar/WicketApplication.java // @SpringBootApplication // public class WicketApplication extends SpringBootServletInitializer { // // public static void main(String[] args) throws Exception { // new SpringApplicationBuilder() // .sources(WicketApplication.class) // .run(args); // } // // } // Path: simple-war/src/test/java/com/giffing/examples/wicket/spring/boot/simple/HomePageTest.java import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.util.tester.FormTester; import org.apache.wicket.util.tester.WicketTester; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import com.giffing.examples.wicket.spring.boot.simplewar.HomePage; import com.giffing.examples.wicket.spring.boot.simplewar.SecondPage; import com.giffing.examples.wicket.spring.boot.simplewar.WicketApplication; package com.giffing.examples.wicket.spring.boot.simple; @RunWith(SpringRunner.class) @SpringBootTest(classes = WicketApplication.class) public class HomePageTest { private WicketTester tester; @Autowired private WebApplication wicketApplication; @Autowired private ApplicationContext applicationContextMock; @Before public void setUp() { ReflectionTestUtils.setField(wicketApplication, "applicationContext", applicationContextMock); tester = new WicketTester(wicketApplication); } @Test public void testest() { tester.startPage(HomePage.class); FormTester newFormTester = tester.newFormTester("form"); newFormTester.submit();
tester.assertRenderedPage(SecondPage.class);
MarcGiffing/wicket-spring-boot-examples
bootstrap/src/main/java/com/giffing/examples/wicket/spring/boot/bootstrap/pages/BasePage.java
// Path: bootstrap/src/main/java/com/giffing/examples/wicket/spring/boot/bootstrap/HomePage.java // @WicketHomePage // public class HomePage extends BasePage { // // public HomePage(PageParameters parameters) { // super(parameters); // // } // // }
import org.apache.wicket.markup.html.GenericWebPage; import org.apache.wicket.model.Model; import org.apache.wicket.request.mapper.parameter.PageParameters; import com.giffing.examples.wicket.spring.boot.bootstrap.HomePage; import de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType; import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.Navbar; import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarButton; import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarComponents;
package com.giffing.examples.wicket.spring.boot.bootstrap.pages; public class BasePage extends GenericWebPage<Void> { public BasePage(final PageParameters parameters) { super(parameters); add(newNavbar("navbar")); } protected Navbar newNavbar(String markupId) { Navbar navbar = new Navbar(markupId); navbar.setPosition(Navbar.Position.TOP); navbar.setInverted(true); navbar.setBrandName(Model.of("Wicket Boot - Bootstrap")); navbar.addComponents(NavbarComponents.transform(Navbar.ComponentPosition.LEFT,
// Path: bootstrap/src/main/java/com/giffing/examples/wicket/spring/boot/bootstrap/HomePage.java // @WicketHomePage // public class HomePage extends BasePage { // // public HomePage(PageParameters parameters) { // super(parameters); // // } // // } // Path: bootstrap/src/main/java/com/giffing/examples/wicket/spring/boot/bootstrap/pages/BasePage.java import org.apache.wicket.markup.html.GenericWebPage; import org.apache.wicket.model.Model; import org.apache.wicket.request.mapper.parameter.PageParameters; import com.giffing.examples.wicket.spring.boot.bootstrap.HomePage; import de.agilecoders.wicket.core.markup.html.bootstrap.image.GlyphIconType; import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.Navbar; import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarButton; import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarComponents; package com.giffing.examples.wicket.spring.boot.bootstrap.pages; public class BasePage extends GenericWebPage<Void> { public BasePage(final PageParameters parameters) { super(parameters); add(newNavbar("navbar")); } protected Navbar newNavbar(String markupId) { Navbar navbar = new Navbar(markupId); navbar.setPosition(Navbar.Position.TOP); navbar.setInverted(true); navbar.setBrandName(Model.of("Wicket Boot - Bootstrap")); navbar.addComponents(NavbarComponents.transform(Navbar.ComponentPosition.LEFT,
new NavbarButton<Void>(HomePage.class, Model.of("Home"))
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/FollowButton.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // }
import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ToggleButton; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper;
package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class FollowButton extends ToggleButton { public FollowButton(Context context) { super(context); } public FollowButton(Context context, AttributeSet attrs) { super(context, attrs); } public FollowButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/FollowButton.java import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ToggleButton; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper; package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class FollowButton extends ToggleButton { public FollowButton(Context context) { super(context); } public FollowButton(Context context, AttributeSet attrs) { super(context, attrs); } public FollowButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); }
public void setData(final User currentUser, final User followUser) {
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/FollowButton.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // }
import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ToggleButton; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper;
package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class FollowButton extends ToggleButton { public FollowButton(Context context) { super(context); } public FollowButton(Context context, AttributeSet attrs) { super(context, attrs); } public FollowButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void setData(final User currentUser, final User followUser) {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/FollowButton.java import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ToggleButton; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper; package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class FollowButton extends ToggleButton { public FollowButton(Context context) { super(context); } public FollowButton(Context context, AttributeSet attrs) { super(context, attrs); } public FollowButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void setData(final User currentUser, final User followUser) {
final Follow follow = currentUser.getFollow();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/FollowButton.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // }
import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ToggleButton; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper;
setBackgroundColor(getResources().getColor(R.color.br_button)); setTextColor(getResources().getColor(R.color.br_text)); } private void onFollowClicked(List<User> followingUsers, final User followingUser, final User currentUser) { if (followingUsers.contains(followingUser)) { setColorToggleOff(); followingUsers.remove(followingUser); } else { setColorToggleOn(); followingUsers.add(followingUser); } currentUser.getFollow().saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { followingUser.getFollow().fetchIfNeededInBackground(new GetCallback<ParseObject>() { @Override public void done(ParseObject parseObject, ParseException e) { if (e == null) { Follow follow = (Follow) parseObject; List<User> followers = follow.getFollowers(); if (followers.contains(currentUser)) { followers.remove(currentUser); } else { followers.add(currentUser); } follow.saveInBackground(); } else {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/FollowButton.java import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.ToggleButton; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseObject; import com.parse.SaveCallback; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper; setBackgroundColor(getResources().getColor(R.color.br_button)); setTextColor(getResources().getColor(R.color.br_text)); } private void onFollowClicked(List<User> followingUsers, final User followingUser, final User currentUser) { if (followingUsers.contains(followingUser)) { setColorToggleOff(); followingUsers.remove(followingUser); } else { setColorToggleOn(); followingUsers.add(followingUser); } currentUser.getFollow().saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { followingUser.getFollow().fetchIfNeededInBackground(new GetCallback<ParseObject>() { @Override public void done(ParseObject parseObject, ParseException e) { if (e == null) { Follow follow = (Follow) parseObject; List<User> followers = follow.getFollowers(); if (followers.contains(currentUser)) { followers.remove(currentUser); } else { followers.add(currentUser); } follow.saveInBackground(); } else {
NotificationHelper.alert(getContext(),
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) {
if (LocalDb.getInstance().getSelectedRoom() != null) {
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { if (LocalDb.getInstance().getSelectedRoom() != null) { try {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { if (LocalDb.getInstance().getSelectedRoom() != null) { try {
Room selectedRoom = LocalDb.getInstance().getSelectedRoom();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { if (LocalDb.getInstance().getSelectedRoom() != null) { try { Room selectedRoom = LocalDb.getInstance().getSelectedRoom(); selectedRoom.fetch();
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { if (LocalDb.getInstance().getSelectedRoom() != null) { try { Room selectedRoom = LocalDb.getInstance().getSelectedRoom(); selectedRoom.fetch();
List<User> users = selectedRoom.getUsers();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { if (LocalDb.getInstance().getSelectedRoom() != null) { try { Room selectedRoom = LocalDb.getInstance().getSelectedRoom(); selectedRoom.fetch(); List<User> users = selectedRoom.getUsers(); for (User user : users) { user.fetchIfNeeded();
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/RetrieveRoomDataService.java import android.app.IntentService; import android.content.Intent; import android.util.Log; import com.parse.ParseException; import java.util.ConcurrentModificationException; import java.util.List; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.services; public class RetrieveRoomDataService extends IntentService { public static final String BROADCAST_RESULT = "bg.mentormate.academy.BROADCAST_RESULT"; public RetrieveRoomDataService() { super(RetrieveRoomDataService.class.getSimpleName()); } @Override protected void onHandleIntent(Intent intent) { if (LocalDb.getInstance().getSelectedRoom() != null) { try { Room selectedRoom = LocalDb.getInstance().getSelectedRoom(); selectedRoom.fetch(); List<User> users = selectedRoom.getUsers(); for (User user : users) { user.fetchIfNeeded();
UserDetail userDetail = user.getUserDetail();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this);
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this);
ParseObject.registerSubclass(User.class);
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); ParseObject.registerSubclass(User.class);
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); ParseObject.registerSubclass(User.class);
ParseObject.registerSubclass(Room.class);
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); ParseObject.registerSubclass(User.class); ParseObject.registerSubclass(Room.class);
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); ParseObject.registerSubclass(User.class); ParseObject.registerSubclass(Room.class);
ParseObject.registerSubclass(UserDetail.class);
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); ParseObject.registerSubclass(User.class); ParseObject.registerSubclass(Room.class); ParseObject.registerSubclass(UserDetail.class);
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Follow.java // @ParseClassName(Constants.FOLLOW_TABLE) // public class Follow extends ParseObject { // public List<User> getFollowers() { // return getList(Constants.FOLLOW_COL_FOLLOWERS); // } // // public void setFollowers(List<User> followers) { // put(Constants.FOLLOW_COL_FOLLOWERS, followers); // } // // public List<User> getFollowings() { // return getList(Constants.FOLLOW_COL_FOLLOWINGS); // } // // public void setFollowings(List<User> followings) { // put(Constants.FOLLOW_COL_FOLLOWINGS, followings); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/RadarApplication.java import android.app.Application; import com.parse.Parse; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.Follow; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp; /** * Created by tl on 05.02.15. */ public class RadarApplication extends Application { @Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); ParseObject.registerSubclass(User.class); ParseObject.registerSubclass(Room.class); ParseObject.registerSubclass(UserDetail.class);
ParseObject.registerSubclass(Follow.class);
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/UserItem.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/ProfileActivity.java // public class ProfileActivity extends ActionBarActivity { // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_profile); // // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // if (savedInstanceState == null) { // ProfileFragment profileFragment = new ProfileFragment(); // profileFragment.setArguments(getIntent().getExtras()); // // getSupportFragmentManager().beginTransaction() // .add(R.id.container, profileFragment) // .commit(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // switch (id) { // case android.R.id.home: // finish(); // break; // } // // return super.onOptionsItemSelected(item); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseImageView; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.activities.ProfileActivity; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class UserItem extends LinearLayout implements View.OnClickListener { private static final String USER_ID = "USER_ID"; private TextView mTvUsername; private ParseImageView mPivAvatar; private FollowButton mFbFollow;
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/ProfileActivity.java // public class ProfileActivity extends ActionBarActivity { // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_profile); // // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // if (savedInstanceState == null) { // ProfileFragment profileFragment = new ProfileFragment(); // profileFragment.setArguments(getIntent().getExtras()); // // getSupportFragmentManager().beginTransaction() // .add(R.id.container, profileFragment) // .commit(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // switch (id) { // case android.R.id.home: // finish(); // break; // } // // return super.onOptionsItemSelected(item); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/UserItem.java import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseImageView; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.activities.ProfileActivity; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class UserItem extends LinearLayout implements View.OnClickListener { private static final String USER_ID = "USER_ID"; private TextView mTvUsername; private ParseImageView mPivAvatar; private FollowButton mFbFollow;
private User mSelectedUser;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/UserItem.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/ProfileActivity.java // public class ProfileActivity extends ActionBarActivity { // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_profile); // // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // if (savedInstanceState == null) { // ProfileFragment profileFragment = new ProfileFragment(); // profileFragment.setArguments(getIntent().getExtras()); // // getSupportFragmentManager().beginTransaction() // .add(R.id.container, profileFragment) // .commit(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // switch (id) { // case android.R.id.home: // finish(); // break; // } // // return super.onOptionsItemSelected(item); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseImageView; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.activities.ProfileActivity; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class UserItem extends LinearLayout implements View.OnClickListener { private static final String USER_ID = "USER_ID"; private TextView mTvUsername; private ParseImageView mPivAvatar; private FollowButton mFbFollow; private User mSelectedUser; private User mCurrentUser; public UserItem(Context context) { super(context); init(); } public UserItem(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(R.layout.item_user, this);
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/ProfileActivity.java // public class ProfileActivity extends ActionBarActivity { // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_profile); // // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // if (savedInstanceState == null) { // ProfileFragment profileFragment = new ProfileFragment(); // profileFragment.setArguments(getIntent().getExtras()); // // getSupportFragmentManager().beginTransaction() // .add(R.id.container, profileFragment) // .commit(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // switch (id) { // case android.R.id.home: // finish(); // break; // } // // return super.onOptionsItemSelected(item); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/UserItem.java import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseImageView; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.activities.ProfileActivity; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.views; /** * Created by tl on 18.02.15. */ public class UserItem extends LinearLayout implements View.OnClickListener { private static final String USER_ID = "USER_ID"; private TextView mTvUsername; private ParseImageView mPivAvatar; private FollowButton mFbFollow; private User mSelectedUser; private User mCurrentUser; public UserItem(Context context) { super(context); init(); } public UserItem(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { LayoutInflater inflater = LayoutInflater.from(getContext()); inflater.inflate(R.layout.item_user, this);
mCurrentUser = LocalDb.getInstance().getCurrentUser();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/UserItem.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/ProfileActivity.java // public class ProfileActivity extends ActionBarActivity { // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_profile); // // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // if (savedInstanceState == null) { // ProfileFragment profileFragment = new ProfileFragment(); // profileFragment.setArguments(getIntent().getExtras()); // // getSupportFragmentManager().beginTransaction() // .add(R.id.container, profileFragment) // .commit(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // switch (id) { // case android.R.id.home: // finish(); // break; // } // // return super.onOptionsItemSelected(item); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseImageView; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.activities.ProfileActivity; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User;
public void done(ParseObject parseObject, ParseException e) { mTvUsername.setText(mSelectedUser.getUsername()); mPivAvatar.setParseFile(mSelectedUser.getAvatar()); if (mSelectedUser.getAvatar() != null) { mPivAvatar.loadInBackground(); } else { mPivAvatar.setBackground(getResources().getDrawable(R.drawable.ic_avatar)); } if (!mCurrentUser.equals(mSelectedUser)) { mFbFollow.setData(mCurrentUser, mSelectedUser); } } }); } @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.tvUsername: case R.id.pivAvatar: goToProfile(); break; } } private void goToProfile() {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/ProfileActivity.java // public class ProfileActivity extends ActionBarActivity { // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_profile); // // getSupportActionBar().setDisplayHomeAsUpEnabled(true); // // if (savedInstanceState == null) { // ProfileFragment profileFragment = new ProfileFragment(); // profileFragment.setArguments(getIntent().getExtras()); // // getSupportFragmentManager().beginTransaction() // .add(R.id.container, profileFragment) // .commit(); // } // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // switch (id) { // case android.R.id.home: // finish(); // break; // } // // return super.onOptionsItemSelected(item); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/UserItem.java import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseImageView; import com.parse.ParseObject; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.activities.ProfileActivity; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; public void done(ParseObject parseObject, ParseException e) { mTvUsername.setText(mSelectedUser.getUsername()); mPivAvatar.setParseFile(mSelectedUser.getAvatar()); if (mSelectedUser.getAvatar() != null) { mPivAvatar.loadInBackground(); } else { mPivAvatar.setBackground(getResources().getDrawable(R.drawable.ic_avatar)); } if (!mCurrentUser.equals(mSelectedUser)) { mFbFollow.setData(mCurrentUser, mSelectedUser); } } }); } @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.tvUsername: case R.id.pivAvatar: goToProfile(); break; } } private void goToProfile() {
Intent profileIntent = new Intent(getContext(), ProfileActivity.class);
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/BitmapHelper.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.location.LocationManager; import android.widget.ImageView; import com.google.maps.android.ui.IconGenerator; import com.parse.ParseException; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.tools; /** * Created by tl on 25.02.15. */ public class BitmapHelper { public static Bitmap buildAvatarIcon(Context context,
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/BitmapHelper.java import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.location.LocationManager; import android.widget.ImageView; import com.google.maps.android.ui.IconGenerator; import com.parse.ParseException; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.tools; /** * Created by tl on 25.02.15. */ public class BitmapHelper { public static Bitmap buildAvatarIcon(Context context,
User user,
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/fragments/SearchRoomsFragment.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/adapters/RoomQueryAdapter.java // public class RoomQueryAdapter extends ParseQueryAdapter<Room> { // // private static final int LIMIT = 50; // // public RoomQueryAdapter(final Context context, final String searchQuery) { // super(context, new QueryFactory<Room>() { // // @Override // public ParseQuery<Room> create() { // ParseQuery<Room> query = new ParseQuery<>(Constants.ROOM_TABLE); // // if (searchQuery != null) { // query.whereContains(Constants.ROOM_COL_NAME, searchQuery); // } // // query.whereNotEqualTo(Constants.ROOM_COL_CREATED_BY, // LocalDb.getInstance().getCurrentUser()) // .orderByDescending(Constants.PARSE_COL_CREATED_AT) // .setLimit(LIMIT); // // return query; // } // }); // } // // @Override // public View getItemView(Room room, View v, ViewGroup parent) { // if (v == null) { // v = new RoomItem(getContext()); // } // // ((RoomItem) v).setData(LocalDb.getInstance().getCurrentUser(), room); // // return v; // } // }
import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.adapters.RoomQueryAdapter;
package bg.mentormate.academy.radarapp.fragments; /** * Created by tl on 16.02.15. */ public class SearchRoomsFragment extends ListFragment implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener { private static final String QUERY = "query"; /** * The fragment argument representing the section number for this * fragment. */ private static final String ARG_TAB_NUMBER = "tab_number"; /** * Returns a new instance of this fragment for the given section * number. */ public static SearchRoomsFragment newInstance(int sectionNumber) { SearchRoomsFragment fragment = new SearchRoomsFragment(); Bundle args = new Bundle(); args.putInt(ARG_TAB_NUMBER, sectionNumber); fragment.setArguments(args); return fragment; }
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/adapters/RoomQueryAdapter.java // public class RoomQueryAdapter extends ParseQueryAdapter<Room> { // // private static final int LIMIT = 50; // // public RoomQueryAdapter(final Context context, final String searchQuery) { // super(context, new QueryFactory<Room>() { // // @Override // public ParseQuery<Room> create() { // ParseQuery<Room> query = new ParseQuery<>(Constants.ROOM_TABLE); // // if (searchQuery != null) { // query.whereContains(Constants.ROOM_COL_NAME, searchQuery); // } // // query.whereNotEqualTo(Constants.ROOM_COL_CREATED_BY, // LocalDb.getInstance().getCurrentUser()) // .orderByDescending(Constants.PARSE_COL_CREATED_AT) // .setLimit(LIMIT); // // return query; // } // }); // } // // @Override // public View getItemView(Room room, View v, ViewGroup parent) { // if (v == null) { // v = new RoomItem(getContext()); // } // // ((RoomItem) v).setData(LocalDb.getInstance().getCurrentUser(), room); // // return v; // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/fragments/SearchRoomsFragment.java import android.os.Bundle; import android.support.v4.app.ListFragment; import android.support.v4.widget.SwipeRefreshLayout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.adapters.RoomQueryAdapter; package bg.mentormate.academy.radarapp.fragments; /** * Created by tl on 16.02.15. */ public class SearchRoomsFragment extends ListFragment implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener { private static final String QUERY = "query"; /** * The fragment argument representing the section number for this * fragment. */ private static final String ARG_TAB_NUMBER = "tab_number"; /** * Returns a new instance of this fragment for the given section * number. */ public static SearchRoomsFragment newInstance(int sectionNumber) { SearchRoomsFragment fragment = new SearchRoomsFragment(); Bundle args = new Bundle(); args.putInt(ARG_TAB_NUMBER, sectionNumber); fragment.setArguments(args); return fragment; }
private RoomQueryAdapter mRoomQueryAdapter;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/QueryHelper.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/Constants.java // public class Constants { // // public final static String INACTIVE_STATE = "INACTIVE"; // // public final static String CATEGORY = "CATEGORY"; // public final static String FOLLOWER = "FOLLOWER"; // public final static String FOLLOWING = "FOLLOWING"; // public final static String SEARCH = "SEARCH"; // // public final static String ROOM_ID = "ROOM_ID"; // // /** // * Parse.com common cols // */ // public final static String PARSE_COL_CREATED_AT = "createdAt"; // public final static String PARSE_COL_OBJECT_ID = "objectId"; // // /** // * Parse.com Follow table constants // */ // public final static String FOLLOW_TABLE = "Follow"; // public final static String FOLLOW_COL_FOLLOWERS = "followers"; // public final static String FOLLOW_COL_FOLLOWINGS = "followings"; // // /** // * Parse.com UserDetail table constants // */ // public final static String USER_DETAIL_TABLE = "CurrentLocation"; // public final static String USER_DETAIL_COL_LOCATION = "location"; // public final static String USER_DETAIL_COL_PROVIDER = "provider"; // public final static String USER_DETAIL_COL_ACTIVE = "active"; // public static final String USER_DETAIL_COL_STATUS = "status"; // // /** // * Parse.com Room table constants // */ // public final static String ROOM_TABLE = "Room"; // public final static String ROOM_COL_NAME = "name"; // public final static String ROOM_COL_PASSKEY = "passKey"; // public final static String ROOM_COL_CREATED_BY = "createdBy"; // public final static String ROOM_COL_USERS = "users"; // // /** // * Parse.com _User table constants // */ // public final static String USER_TABLE = "_User"; // public final static String USER_COL_USER_DETAIL = "currentLocation"; // public final static String USER_COL_ROOM = "room"; // public final static String USER_COL_AVATAR = "avatar"; // public final static String USER_COL_FOLLOW = "follow"; // public final static String USER_COL_USERNAME = "username"; // // /*** // * Constants for working with the camera // */ // public static final int ACTION_TAKE_PHOTO = 0; // public static final String CAMERA_DIR = "/DCIM/"; // public static final String JPEG_FILE_PREFIX = "IMG_"; // public static final String JPEG_FILE_SUFFIX = ".jpg"; // public static final String ALBUM_NAME = "CameraSample"; // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import com.parse.GetCallback; import com.parse.ParseQuery; import bg.mentormate.academy.radarapp.Constants; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.tools; /** * Created by tl on 25.02.15. */ public class QueryHelper { public static void getRoomById(String roomId, GetCallback<Room> callback) {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/Constants.java // public class Constants { // // public final static String INACTIVE_STATE = "INACTIVE"; // // public final static String CATEGORY = "CATEGORY"; // public final static String FOLLOWER = "FOLLOWER"; // public final static String FOLLOWING = "FOLLOWING"; // public final static String SEARCH = "SEARCH"; // // public final static String ROOM_ID = "ROOM_ID"; // // /** // * Parse.com common cols // */ // public final static String PARSE_COL_CREATED_AT = "createdAt"; // public final static String PARSE_COL_OBJECT_ID = "objectId"; // // /** // * Parse.com Follow table constants // */ // public final static String FOLLOW_TABLE = "Follow"; // public final static String FOLLOW_COL_FOLLOWERS = "followers"; // public final static String FOLLOW_COL_FOLLOWINGS = "followings"; // // /** // * Parse.com UserDetail table constants // */ // public final static String USER_DETAIL_TABLE = "CurrentLocation"; // public final static String USER_DETAIL_COL_LOCATION = "location"; // public final static String USER_DETAIL_COL_PROVIDER = "provider"; // public final static String USER_DETAIL_COL_ACTIVE = "active"; // public static final String USER_DETAIL_COL_STATUS = "status"; // // /** // * Parse.com Room table constants // */ // public final static String ROOM_TABLE = "Room"; // public final static String ROOM_COL_NAME = "name"; // public final static String ROOM_COL_PASSKEY = "passKey"; // public final static String ROOM_COL_CREATED_BY = "createdBy"; // public final static String ROOM_COL_USERS = "users"; // // /** // * Parse.com _User table constants // */ // public final static String USER_TABLE = "_User"; // public final static String USER_COL_USER_DETAIL = "currentLocation"; // public final static String USER_COL_ROOM = "room"; // public final static String USER_COL_AVATAR = "avatar"; // public final static String USER_COL_FOLLOW = "follow"; // public final static String USER_COL_USERNAME = "username"; // // /*** // * Constants for working with the camera // */ // public static final int ACTION_TAKE_PHOTO = 0; // public static final String CAMERA_DIR = "/DCIM/"; // public static final String JPEG_FILE_PREFIX = "IMG_"; // public static final String JPEG_FILE_SUFFIX = ".jpg"; // public static final String ALBUM_NAME = "CameraSample"; // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/QueryHelper.java import com.parse.GetCallback; import com.parse.ParseQuery; import bg.mentormate.academy.radarapp.Constants; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.tools; /** * Created by tl on 25.02.15. */ public class QueryHelper { public static void getRoomById(String roomId, GetCallback<Room> callback) {
ParseQuery<Room> query = new ParseQuery<>(Constants.ROOM_TABLE);
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/QueryHelper.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/Constants.java // public class Constants { // // public final static String INACTIVE_STATE = "INACTIVE"; // // public final static String CATEGORY = "CATEGORY"; // public final static String FOLLOWER = "FOLLOWER"; // public final static String FOLLOWING = "FOLLOWING"; // public final static String SEARCH = "SEARCH"; // // public final static String ROOM_ID = "ROOM_ID"; // // /** // * Parse.com common cols // */ // public final static String PARSE_COL_CREATED_AT = "createdAt"; // public final static String PARSE_COL_OBJECT_ID = "objectId"; // // /** // * Parse.com Follow table constants // */ // public final static String FOLLOW_TABLE = "Follow"; // public final static String FOLLOW_COL_FOLLOWERS = "followers"; // public final static String FOLLOW_COL_FOLLOWINGS = "followings"; // // /** // * Parse.com UserDetail table constants // */ // public final static String USER_DETAIL_TABLE = "CurrentLocation"; // public final static String USER_DETAIL_COL_LOCATION = "location"; // public final static String USER_DETAIL_COL_PROVIDER = "provider"; // public final static String USER_DETAIL_COL_ACTIVE = "active"; // public static final String USER_DETAIL_COL_STATUS = "status"; // // /** // * Parse.com Room table constants // */ // public final static String ROOM_TABLE = "Room"; // public final static String ROOM_COL_NAME = "name"; // public final static String ROOM_COL_PASSKEY = "passKey"; // public final static String ROOM_COL_CREATED_BY = "createdBy"; // public final static String ROOM_COL_USERS = "users"; // // /** // * Parse.com _User table constants // */ // public final static String USER_TABLE = "_User"; // public final static String USER_COL_USER_DETAIL = "currentLocation"; // public final static String USER_COL_ROOM = "room"; // public final static String USER_COL_AVATAR = "avatar"; // public final static String USER_COL_FOLLOW = "follow"; // public final static String USER_COL_USERNAME = "username"; // // /*** // * Constants for working with the camera // */ // public static final int ACTION_TAKE_PHOTO = 0; // public static final String CAMERA_DIR = "/DCIM/"; // public static final String JPEG_FILE_PREFIX = "IMG_"; // public static final String JPEG_FILE_SUFFIX = ".jpg"; // public static final String ALBUM_NAME = "CameraSample"; // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import com.parse.GetCallback; import com.parse.ParseQuery; import bg.mentormate.academy.radarapp.Constants; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.tools; /** * Created by tl on 25.02.15. */ public class QueryHelper { public static void getRoomById(String roomId, GetCallback<Room> callback) { ParseQuery<Room> query = new ParseQuery<>(Constants.ROOM_TABLE); query.getInBackground(roomId, callback); }
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/Constants.java // public class Constants { // // public final static String INACTIVE_STATE = "INACTIVE"; // // public final static String CATEGORY = "CATEGORY"; // public final static String FOLLOWER = "FOLLOWER"; // public final static String FOLLOWING = "FOLLOWING"; // public final static String SEARCH = "SEARCH"; // // public final static String ROOM_ID = "ROOM_ID"; // // /** // * Parse.com common cols // */ // public final static String PARSE_COL_CREATED_AT = "createdAt"; // public final static String PARSE_COL_OBJECT_ID = "objectId"; // // /** // * Parse.com Follow table constants // */ // public final static String FOLLOW_TABLE = "Follow"; // public final static String FOLLOW_COL_FOLLOWERS = "followers"; // public final static String FOLLOW_COL_FOLLOWINGS = "followings"; // // /** // * Parse.com UserDetail table constants // */ // public final static String USER_DETAIL_TABLE = "CurrentLocation"; // public final static String USER_DETAIL_COL_LOCATION = "location"; // public final static String USER_DETAIL_COL_PROVIDER = "provider"; // public final static String USER_DETAIL_COL_ACTIVE = "active"; // public static final String USER_DETAIL_COL_STATUS = "status"; // // /** // * Parse.com Room table constants // */ // public final static String ROOM_TABLE = "Room"; // public final static String ROOM_COL_NAME = "name"; // public final static String ROOM_COL_PASSKEY = "passKey"; // public final static String ROOM_COL_CREATED_BY = "createdBy"; // public final static String ROOM_COL_USERS = "users"; // // /** // * Parse.com _User table constants // */ // public final static String USER_TABLE = "_User"; // public final static String USER_COL_USER_DETAIL = "currentLocation"; // public final static String USER_COL_ROOM = "room"; // public final static String USER_COL_AVATAR = "avatar"; // public final static String USER_COL_FOLLOW = "follow"; // public final static String USER_COL_USERNAME = "username"; // // /*** // * Constants for working with the camera // */ // public static final int ACTION_TAKE_PHOTO = 0; // public static final String CAMERA_DIR = "/DCIM/"; // public static final String JPEG_FILE_PREFIX = "IMG_"; // public static final String JPEG_FILE_SUFFIX = ".jpg"; // public static final String ALBUM_NAME = "CameraSample"; // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/QueryHelper.java import com.parse.GetCallback; import com.parse.ParseQuery; import bg.mentormate.academy.radarapp.Constants; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.tools; /** * Created by tl on 25.02.15. */ public class QueryHelper { public static void getRoomById(String roomId, GetCallback<Room> callback) { ParseQuery<Room> query = new ParseQuery<>(Constants.ROOM_TABLE); query.getInBackground(roomId, callback); }
public static void getUserById(String userId, GetCallback<User> callback) {
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/FollowActivity.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/fragments/FollowFragment.java // public class FollowFragment extends ListFragment implements View.OnClickListener, // SwipeRefreshLayout.OnRefreshListener{ // // private static final String USER_ID = "USER_ID"; // // private UserQueryAdapter mUserQueryAdapter; // private EditText mEtQuery; // private Button mBtnSearch; // private SwipeRefreshLayout mSrlRefresh; // // private User mUser; // private String mState; // // public FollowFragment() { // } // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, // Bundle savedInstanceState) { // View rootView = inflater.inflate(R.layout.fragment_search_list, container, false); // // initData(); // initViews(rootView); // // return rootView; // } // // private void initData() { // String id = getArguments().getString(USER_ID); // mState = getArguments().getString(Constants.CATEGORY); // // if (id != null && mState != null) { // QueryHelper.getUserById(id, new GetCallback<User>() { // @Override // public void done(User user, ParseException e) { // if (e == null) { // mUser = user; // // mUserQueryAdapter = new UserQueryAdapter(getActivity(), null, mState, mUser); // setListAdapter(mUserQueryAdapter); // } else { // NotificationHelper.alert(getActivity(), // getString(R.string.dialog_error_title), // e.getMessage()); // } // } // }); // } // } // // private void initViews(View rootView) { // mEtQuery = (EditText) rootView.findViewById(R.id.etQuery); // mBtnSearch = (Button) rootView.findViewById(R.id.btnSeach); // mSrlRefresh = (SwipeRefreshLayout) rootView.findViewById(R.id.srlRefresh); // // mSrlRefresh.setColorSchemeColors( // getResources().getColor(R.color.br_dark_background)); // // mBtnSearch.setOnClickListener(this); // mSrlRefresh.setOnRefreshListener(this); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // setActivityTitle(); // } // // private void setActivityTitle() { // ActionBar actionBar = ((ActionBarActivity)getActivity()).getSupportActionBar(); // // if (mState.equals(Constants.FOLLOWER)) { // actionBar.setTitle(getString(R.string.followers_label)); // } else { // actionBar.setTitle(getString(R.string.following_label)); // } // } // // @Override // public void onClick(View v) { // int id = v.getId(); // // switch (id) { // case R.id.btnSeach: // onSearchClicked(); // break; // } // } // // private void onSearchClicked() { // String query = mEtQuery.getText().toString(); // // mUserQueryAdapter = new UserQueryAdapter(getActivity(), query, mState, mUser); // // setListAdapter(mUserQueryAdapter); // } // // @Override // public void onRefresh() { // onSearchClicked(); // mSrlRefresh.setRefreshing(false); // } // }
import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.MenuItem; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.fragments.FollowFragment;
package bg.mentormate.academy.radarapp.activities; public class FollowActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_follow); getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (savedInstanceState == null) {
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/fragments/FollowFragment.java // public class FollowFragment extends ListFragment implements View.OnClickListener, // SwipeRefreshLayout.OnRefreshListener{ // // private static final String USER_ID = "USER_ID"; // // private UserQueryAdapter mUserQueryAdapter; // private EditText mEtQuery; // private Button mBtnSearch; // private SwipeRefreshLayout mSrlRefresh; // // private User mUser; // private String mState; // // public FollowFragment() { // } // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, // Bundle savedInstanceState) { // View rootView = inflater.inflate(R.layout.fragment_search_list, container, false); // // initData(); // initViews(rootView); // // return rootView; // } // // private void initData() { // String id = getArguments().getString(USER_ID); // mState = getArguments().getString(Constants.CATEGORY); // // if (id != null && mState != null) { // QueryHelper.getUserById(id, new GetCallback<User>() { // @Override // public void done(User user, ParseException e) { // if (e == null) { // mUser = user; // // mUserQueryAdapter = new UserQueryAdapter(getActivity(), null, mState, mUser); // setListAdapter(mUserQueryAdapter); // } else { // NotificationHelper.alert(getActivity(), // getString(R.string.dialog_error_title), // e.getMessage()); // } // } // }); // } // } // // private void initViews(View rootView) { // mEtQuery = (EditText) rootView.findViewById(R.id.etQuery); // mBtnSearch = (Button) rootView.findViewById(R.id.btnSeach); // mSrlRefresh = (SwipeRefreshLayout) rootView.findViewById(R.id.srlRefresh); // // mSrlRefresh.setColorSchemeColors( // getResources().getColor(R.color.br_dark_background)); // // mBtnSearch.setOnClickListener(this); // mSrlRefresh.setOnRefreshListener(this); // } // // @Override // public void onViewCreated(View view, Bundle savedInstanceState) { // super.onViewCreated(view, savedInstanceState); // setActivityTitle(); // } // // private void setActivityTitle() { // ActionBar actionBar = ((ActionBarActivity)getActivity()).getSupportActionBar(); // // if (mState.equals(Constants.FOLLOWER)) { // actionBar.setTitle(getString(R.string.followers_label)); // } else { // actionBar.setTitle(getString(R.string.following_label)); // } // } // // @Override // public void onClick(View v) { // int id = v.getId(); // // switch (id) { // case R.id.btnSeach: // onSearchClicked(); // break; // } // } // // private void onSearchClicked() { // String query = mEtQuery.getText().toString(); // // mUserQueryAdapter = new UserQueryAdapter(getActivity(), query, mState, mUser); // // setListAdapter(mUserQueryAdapter); // } // // @Override // public void onRefresh() { // onSearchClicked(); // mSrlRefresh.setRefreshing(false); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/FollowActivity.java import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.MenuItem; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.fragments.FollowFragment; package bg.mentormate.academy.radarapp.activities; public class FollowActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_follow); getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (savedInstanceState == null) {
FollowFragment followFragment = new FollowFragment();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/LoginActivity.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // }
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper;
package bg.mentormate.academy.radarapp.activities; public class LoginActivity extends ActionBarActivity implements View.OnClickListener { private EditText mEtUsername; private EditText mEtPassword; private Button mBtnLogin; private TextView mTvRegister; private ProgressBar mProgressBar;
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/LoginActivity.java import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper; package bg.mentormate.academy.radarapp.activities; public class LoginActivity extends ActionBarActivity implements View.OnClickListener { private EditText mEtUsername; private EditText mEtPassword; private Button mBtnLogin; private TextView mTvRegister; private ProgressBar mProgressBar;
private LocalDb mLocalDb;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/LoginActivity.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // }
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper;
mEtUsername = (EditText) findViewById(R.id.etUsername); mEtPassword = (EditText) findViewById(R.id.etPassword); mBtnLogin = (Button) findViewById(R.id.btnLogin); mTvRegister = (TextView) findViewById(R.id.tvRegister); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mBtnLogin.setOnClickListener(this); mTvRegister.setOnClickListener(this); } @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.btnLogin: login(); break; case R.id.tvRegister: goToRegister(); break; } } private void login() { String username = mEtUsername.getText().toString().trim(); String password = mEtPassword.getText().toString().trim(); if (username.isEmpty() || password.isEmpty()) { // The input are empty, show an alert
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/LoginActivity.java import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper; mEtUsername = (EditText) findViewById(R.id.etUsername); mEtPassword = (EditText) findViewById(R.id.etPassword); mBtnLogin = (Button) findViewById(R.id.btnLogin); mTvRegister = (TextView) findViewById(R.id.tvRegister); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mBtnLogin.setOnClickListener(this); mTvRegister.setOnClickListener(this); } @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.btnLogin: login(); break; case R.id.tvRegister: goToRegister(); break; } } private void login() { String username = mEtUsername.getText().toString().trim(); String password = mEtPassword.getText().toString().trim(); if (username.isEmpty() || password.isEmpty()) { // The input are empty, show an alert
NotificationHelper.alert(this, getString(R.string.dialog_error_title),
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/LoginActivity.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // }
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper;
mBtnLogin.setOnClickListener(this); mTvRegister.setOnClickListener(this); } @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.btnLogin: login(); break; case R.id.tvRegister: goToRegister(); break; } } private void login() { String username = mEtUsername.getText().toString().trim(); String password = mEtPassword.getText().toString().trim(); if (username.isEmpty() || password.isEmpty()) { // The input are empty, show an alert NotificationHelper.alert(this, getString(R.string.dialog_error_title), getString(R.string.login_invalid_inputs_message)); } else { showProgressBar(); // Log the new user in Parse.com
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/tools/NotificationHelper.java // public class NotificationHelper { // // public static void alert(Context context, String title, String message) { // AlertDialog.Builder builder = new AlertDialog.Builder(context); // builder.setMessage(message) // .setTitle(title) // .setPositiveButton(android.R.string.ok, null); // // AlertDialog dialog = builder.create(); // dialog.show(); // } // // public static void notifyTheUser(Context context, int title, int description, Intent intent) { // NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) // .setContentTitle(context.getString(title)) // .setContentText(context.getString(description)) // .setSmallIcon(R.drawable.ic_stat_ic_launcher) // .setAutoCancel(true); // // PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // notificationBuilder.setContentIntent(pendingIntent); // // NotificationManager notificationManager = (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); // // notificationManager.notify(1, notificationBuilder.build()); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/activities/LoginActivity.java import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.parse.LogInCallback; import com.parse.ParseException; import com.parse.ParseUser; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.User; import bg.mentormate.academy.radarapp.tools.NotificationHelper; mBtnLogin.setOnClickListener(this); mTvRegister.setOnClickListener(this); } @Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.btnLogin: login(); break; case R.id.tvRegister: goToRegister(); break; } } private void login() { String username = mEtUsername.getText().toString().trim(); String password = mEtPassword.getText().toString().trim(); if (username.isEmpty() || password.isEmpty()) { // The input are empty, show an alert NotificationHelper.alert(this, getString(R.string.dialog_error_title), getString(R.string.login_invalid_inputs_message)); } else { showProgressBar(); // Log the new user in Parse.com
User.logInInBackground(username, password, new LogInCallback() {
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/ServiceLocationListener.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.location.Location; import android.location.LocationListener; import android.os.Bundle; import android.util.Log; import com.parse.ParseException; import com.parse.ParseGeoPoint; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services; /** * Created by tl on 13.02.15. */ public class ServiceLocationListener implements LocationListener { private User mCurrentUser; public ServiceLocationListener() { } @Override public void onLocationChanged(Location location) { Log.d(ServiceLocationListener.class.getSimpleName(), "Provider: " +location.getProvider() + "|" + "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude());
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/ServiceLocationListener.java import android.location.Location; import android.location.LocationListener; import android.os.Bundle; import android.util.Log; import com.parse.ParseException; import com.parse.ParseGeoPoint; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.services; /** * Created by tl on 13.02.15. */ public class ServiceLocationListener implements LocationListener { private User mCurrentUser; public ServiceLocationListener() { } @Override public void onLocationChanged(Location location) { Log.d(ServiceLocationListener.class.getSimpleName(), "Provider: " +location.getProvider() + "|" + "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude());
if (LocalDb.getInstance() != null) {
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/ServiceLocationListener.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.location.Location; import android.location.LocationListener; import android.os.Bundle; import android.util.Log; import com.parse.ParseException; import com.parse.ParseGeoPoint; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.services; /** * Created by tl on 13.02.15. */ public class ServiceLocationListener implements LocationListener { private User mCurrentUser; public ServiceLocationListener() { } @Override public void onLocationChanged(Location location) { Log.d(ServiceLocationListener.class.getSimpleName(), "Provider: " +location.getProvider() + "|" + "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude()); if (LocalDb.getInstance() != null) { mCurrentUser = LocalDb.getInstance().getCurrentUser();
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java // public class LocalDb { // // private static LocalDb instance; // // public static LocalDb getInstance() { // if (instance == null) { // instance = new LocalDb(); // } // // return instance; // } // // private User currentUser; // private Room selectedRoom; // private boolean isTrackingOn; // // private LocalDb() { // currentUser = (User) User.getCurrentUser(); // isTrackingOn = false; // } // // public User getCurrentUser() { // return currentUser; // } // // public void setCurrentUser(User currentUser) { // this.currentUser = currentUser; // } // // public Room getSelectedRoom() { // return selectedRoom; // } // // public void setSelectedRoom(Room selectedRoom) { // this.selectedRoom = selectedRoom; // } // // public boolean isTrackingOn() { // return isTrackingOn; // } // // public void setTrackingOn(boolean isTrackingOn) { // this.isTrackingOn = isTrackingOn; // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/UserDetail.java // @ParseClassName(Constants.USER_DETAIL_TABLE) // public class UserDetail extends ParseObject { // // public ParseGeoPoint getLocation() { // return getParseGeoPoint(Constants.USER_DETAIL_COL_LOCATION); // } // // public void setLocation(ParseGeoPoint location) { // put(Constants.USER_DETAIL_COL_LOCATION, location); // } // // public String getProvider() { // return getString(Constants.USER_DETAIL_COL_PROVIDER); // } // // public void setProvider(String provider) { // put(Constants.USER_DETAIL_COL_PROVIDER, provider); // } // // public boolean getActive() { // return getBoolean(Constants.USER_DETAIL_COL_ACTIVE); // } // // public void setActive(boolean active) { // put(Constants.USER_DETAIL_COL_ACTIVE, active); // } // // public String getStatus() { return getString(Constants.USER_DETAIL_COL_STATUS); } // // public void setStatus(String status) { put(Constants.USER_DETAIL_COL_STATUS, status); } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/services/ServiceLocationListener.java import android.location.Location; import android.location.LocationListener; import android.os.Bundle; import android.util.Log; import com.parse.ParseException; import com.parse.ParseGeoPoint; import bg.mentormate.academy.radarapp.data.LocalDb; import bg.mentormate.academy.radarapp.models.UserDetail; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.services; /** * Created by tl on 13.02.15. */ public class ServiceLocationListener implements LocationListener { private User mCurrentUser; public ServiceLocationListener() { } @Override public void onLocationChanged(Location location) { Log.d(ServiceLocationListener.class.getSimpleName(), "Provider: " +location.getProvider() + "|" + "Lat/Lng: " + location.getLatitude() + "/" + location.getLongitude()); if (LocalDb.getInstance() != null) { mCurrentUser = LocalDb.getInstance().getCurrentUser();
UserDetail userDetail = mCurrentUser.getUserDetail();
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/adapters/EditRoomUserAdapter.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseFile; import com.parse.ParseImageView; import com.parse.ParseObject; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.adapters; /** * Created by lopi on 2/22/2015. */ public class EditRoomUserAdapter extends BaseAdapter { private Context mContext;
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/adapters/EditRoomUserAdapter.java import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.parse.GetCallback; import com.parse.ParseException; import com.parse.ParseFile; import com.parse.ParseImageView; import com.parse.ParseObject; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.adapters; /** * Created by lopi on 2/22/2015. */ public class EditRoomUserAdapter extends BaseAdapter { private Context mContext;
private List<User> mUsers;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.data; /** * Created by tl on 14.02.15. */ public class LocalDb { private static LocalDb instance; public static LocalDb getInstance() { if (instance == null) { instance = new LocalDb(); } return instance; }
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.data; /** * Created by tl on 14.02.15. */ public class LocalDb { private static LocalDb instance; public static LocalDb getInstance() { if (instance == null) { instance = new LocalDb(); } return instance; }
private User currentUser;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.data; /** * Created by tl on 14.02.15. */ public class LocalDb { private static LocalDb instance; public static LocalDb getInstance() { if (instance == null) { instance = new LocalDb(); } return instance; } private User currentUser;
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/data/LocalDb.java import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.data; /** * Created by tl on 14.02.15. */ public class LocalDb { private static LocalDb instance; public static LocalDb getInstance() { if (instance == null) { instance = new LocalDb(); } return instance; } private User currentUser;
private Room selectedRoom;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/adapters/RoomUserAdapter.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.parse.ParseImageView; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.adapters; /** * Created by tl on 21.02.15. */ public class RoomUserAdapter extends BaseAdapter { private Context mContext;
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/adapters/RoomUserAdapter.java import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.TextView; import com.parse.ParseImageView; import java.util.List; import bg.mentormate.academy.radarapp.R; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.adapters; /** * Created by tl on 21.02.15. */ public class RoomUserAdapter extends BaseAdapter { private Context mContext;
private List<User> mUsers;
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/RegisterButton.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.content.Context; import android.util.AttributeSet; import android.widget.ToggleButton; import java.util.List; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.views; /** * Created by tl on 19.02.15. */ public class RegisterButton extends ToggleButton { public RegisterButton(Context context) { super(context); } public RegisterButton(Context context, AttributeSet attrs) { super(context, attrs); }
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/RegisterButton.java import android.content.Context; import android.util.AttributeSet; import android.widget.ToggleButton; import java.util.List; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.views; /** * Created by tl on 19.02.15. */ public class RegisterButton extends ToggleButton { public RegisterButton(Context context) { super(context); } public RegisterButton(Context context, AttributeSet attrs) { super(context, attrs); }
public void setData(User currentUser, Room selectedRoom) {
tl-nguyen/RadarApp
RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/RegisterButton.java
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // }
import android.content.Context; import android.util.AttributeSet; import android.widget.ToggleButton; import java.util.List; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User;
package bg.mentormate.academy.radarapp.views; /** * Created by tl on 19.02.15. */ public class RegisterButton extends ToggleButton { public RegisterButton(Context context) { super(context); } public RegisterButton(Context context, AttributeSet attrs) { super(context, attrs); }
// Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/Room.java // @ParseClassName(Constants.ROOM_TABLE) // public class Room extends ParseObject{ // public String getName() { // return getString(Constants.ROOM_COL_NAME); // } // // public void setName(String name) { // put(Constants.ROOM_COL_NAME, name); // } // // public String getPassKey() { // return getString(Constants.ROOM_COL_PASSKEY); // } // // public void setPassKey(String passKey) { // put(Constants.ROOM_COL_PASSKEY, passKey); // } // // public User getCreatedBy() { // return (User) getParseUser(Constants.ROOM_COL_CREATED_BY); // } // // public void setCreatedBy(User createdBy) { // put(Constants.ROOM_COL_CREATED_BY, createdBy); // } // // public List<User> getUsers() { // return getList(Constants.ROOM_COL_USERS); // } // // public void setUsers(List<User> users) { // put(Constants.ROOM_COL_USERS, users); // } // } // // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/models/User.java // @ParseClassName(Constants.USER_TABLE) // public class User extends ParseUser{ // // public UserDetail getUserDetail() { // return (UserDetail) getParseObject(Constants.USER_COL_USER_DETAIL); // } // // public void setUserDetail(UserDetail userDetail) { // put(Constants.USER_COL_USER_DETAIL, userDetail); // } // // public Room getRoom() { // return (Room) getParseObject(Constants.USER_COL_ROOM); // } // // public void setRoom(Room room) { // put(Constants.USER_COL_ROOM, room); // } // // public ParseFile getAvatar() { // return getParseFile(Constants.USER_COL_AVATAR); // } // // public void setAvatar(ParseFile avatar) { // put(Constants.USER_COL_AVATAR, avatar); // } // // public Follow getFollow() { // return (Follow) getParseObject(Constants.USER_COL_FOLLOW); // } // // public void setFollow(Follow follow) { // put(Constants.USER_COL_FOLLOW, follow); // } // } // Path: RadarApp/app/src/main/java/bg/mentormate/academy/radarapp/views/RegisterButton.java import android.content.Context; import android.util.AttributeSet; import android.widget.ToggleButton; import java.util.List; import bg.mentormate.academy.radarapp.models.Room; import bg.mentormate.academy.radarapp.models.User; package bg.mentormate.academy.radarapp.views; /** * Created by tl on 19.02.15. */ public class RegisterButton extends ToggleButton { public RegisterButton(Context context) { super(context); } public RegisterButton(Context context, AttributeSet attrs) { super(context, attrs); }
public void setData(User currentUser, Room selectedRoom) {
PeteGoo/tcSlackBuildNotifier
tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationProjectSettingsFactory.java
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // }
import jetbrains.buildServer.serverSide.settings.ProjectSettingsFactory; import jetbrains.buildServer.serverSide.settings.ProjectSettingsManager; import slacknotifications.teamcity.Loggers;
package slacknotifications.teamcity.settings; public class SlackNotificationProjectSettingsFactory implements ProjectSettingsFactory { public SlackNotificationProjectSettingsFactory(ProjectSettingsManager projectSettingsManager){
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // } // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationProjectSettingsFactory.java import jetbrains.buildServer.serverSide.settings.ProjectSettingsFactory; import jetbrains.buildServer.serverSide.settings.ProjectSettingsManager; import slacknotifications.teamcity.Loggers; package slacknotifications.teamcity.settings; public class SlackNotificationProjectSettingsFactory implements ProjectSettingsFactory { public SlackNotificationProjectSettingsFactory(ProjectSettingsManager projectSettingsManager){
Loggers.SERVER.info("SlackNotificationProjectSettingsFactory :: Registering");
PeteGoo/tcSlackBuildNotifier
tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/payload/util/SlackNotificationBeanUtilsVariableResolver.java
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // }
import org.apache.commons.beanutils.PropertyUtils; import slacknotifications.teamcity.Loggers; import slacknotifications.teamcity.payload.util.TemplateMatcher.VariableResolver; import java.lang.reflect.InvocationTargetException;
package slacknotifications.teamcity.payload.util; /** * This is a VariableResolver for the TemplateMatcher * * It resolves the values of variables from javaBean objects using * org.apache.commons.beanutils.PropertyUtils * * @author NetWolfUK * */ public class SlackNotificationBeanUtilsVariableResolver implements VariableResolver { private static final String EXCEPTION_MESSAGE = " thrown when trying to resolve value for "; Object bean; public SlackNotificationBeanUtilsVariableResolver(Object javaBean) { this.bean = javaBean; } @Override public String resolve(String variableName) { String value = "UNRESOLVED"; try { value = (String) PropertyUtils.getProperty(bean, variableName); } catch (IllegalAccessException e) {
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // } // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/payload/util/SlackNotificationBeanUtilsVariableResolver.java import org.apache.commons.beanutils.PropertyUtils; import slacknotifications.teamcity.Loggers; import slacknotifications.teamcity.payload.util.TemplateMatcher.VariableResolver; import java.lang.reflect.InvocationTargetException; package slacknotifications.teamcity.payload.util; /** * This is a VariableResolver for the TemplateMatcher * * It resolves the values of variables from javaBean objects using * org.apache.commons.beanutils.PropertyUtils * * @author NetWolfUK * */ public class SlackNotificationBeanUtilsVariableResolver implements VariableResolver { private static final String EXCEPTION_MESSAGE = " thrown when trying to resolve value for "; Object bean; public SlackNotificationBeanUtilsVariableResolver(Object javaBean) { this.bean = javaBean; } @Override public String resolve(String variableName) { String value = "UNRESOLVED"; try { value = (String) PropertyUtils.getProperty(bean, variableName); } catch (IllegalAccessException e) {
Loggers.SERVER.warn(this.getClass().getSimpleName() + " :: " + e.getClass() + EXCEPTION_MESSAGE + variableName);
PeteGoo/tcSlackBuildNotifier
tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainSettings.java
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // }
import jetbrains.buildServer.serverSide.MainConfigProcessor; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; import org.jdom.Element; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties;
package slacknotifications.teamcity.settings; public class SlackNotificationMainSettings implements MainConfigProcessor { private static final String NAME = SlackNotificationMainSettings.class.getName(); private SlackNotificationMainConfig slackNotificationMainConfig; private SBuildServer server; private ServerPaths serverPaths; private String version; public SlackNotificationMainSettings(SBuildServer server, ServerPaths serverPaths){ this.serverPaths = serverPaths;
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // } // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainSettings.java import jetbrains.buildServer.serverSide.MainConfigProcessor; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; import org.jdom.Element; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; package slacknotifications.teamcity.settings; public class SlackNotificationMainSettings implements MainConfigProcessor { private static final String NAME = SlackNotificationMainSettings.class.getName(); private SlackNotificationMainConfig slackNotificationMainConfig; private SBuildServer server; private ServerPaths serverPaths; private String version; public SlackNotificationMainSettings(SBuildServer server, ServerPaths serverPaths){ this.serverPaths = serverPaths;
Loggers.SERVER.debug(NAME + " :: Constructor called");
PeteGoo/tcSlackBuildNotifier
tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainSettings.java
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // }
import jetbrains.buildServer.serverSide.MainConfigProcessor; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; import org.jdom.Element; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties;
} public boolean getShowCommits(){ return this.slackNotificationMainConfig.getContent().getShowCommits(); } public boolean getShowCommitters(){ return this.slackNotificationMainConfig.getContent().getShowCommitters(); } public boolean getShowTriggeredBy(){ return this.slackNotificationMainConfig.getContent().getShowTriggeredBy(); } public Boolean getShowFailureReason() { return this.slackNotificationMainConfig.getContent().getShowFailureReason(); } public String getFilterBranchName() { return this.slackNotificationMainConfig.getFilterBranchName(); } public Boolean getSlackNotificationShowFurtherReading(){ return this.slackNotificationMainConfig.getSlackNotificationShowFurtherReading(); } public void dispose() { Loggers.SERVER.debug(NAME + ":dispose() called"); }
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // } // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainSettings.java import jetbrains.buildServer.serverSide.MainConfigProcessor; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.ServerPaths; import org.jdom.Element; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; } public boolean getShowCommits(){ return this.slackNotificationMainConfig.getContent().getShowCommits(); } public boolean getShowCommitters(){ return this.slackNotificationMainConfig.getContent().getShowCommitters(); } public boolean getShowTriggeredBy(){ return this.slackNotificationMainConfig.getContent().getShowTriggeredBy(); } public Boolean getShowFailureReason() { return this.slackNotificationMainConfig.getContent().getShowFailureReason(); } public String getFilterBranchName() { return this.slackNotificationMainConfig.getFilterBranchName(); } public Boolean getSlackNotificationShowFurtherReading(){ return this.slackNotificationMainConfig.getSlackNotificationShowFurtherReading(); } public void dispose() { Loggers.SERVER.debug(NAME + ":dispose() called"); }
public SlackNotificationProxyConfig getProxyConfig() {
PeteGoo/tcSlackBuildNotifier
tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainConfig.java
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // }
import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.configuration.ChangeListener; import jetbrains.buildServer.configuration.FileWatcher; import jetbrains.buildServer.serverSide.ServerPaths; import jetbrains.buildServer.util.FileUtil; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.IOException; import java.nio.file.Files;
private String teamName; private String token; private Boolean proxyShortNames = false; private boolean enabled = true; public final String SINGLE_HOST_REGEX = "^[^./~`'\"]+(?:/.*)?$"; public final String HOSTNAME_ONLY_REGEX = "^([^/]+)(?:/.*)?$"; private SlackNotificationContentConfig content; private boolean configFileExists; public SlackNotificationMainConfig(ServerPaths serverPaths) { this.content = new SlackNotificationContentConfig(); this.myConfigDir = new File(serverPaths.getConfigDir(), "slack"); this.myConfigFile = new File(this.myConfigDir, "slack-config.xml"); configFileExists = this.myConfigFile.exists(); reloadConfiguration(); this.myChangeObserver = new FileWatcher(this.myConfigFile); this.myChangeObserver.setSleepingPeriod(10000L); this.myChangeObserver.registerListener(this); this.myChangeObserver.start(); } public void refresh(){ reloadConfiguration(); } private void reloadConfiguration() {
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // } // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainConfig.java import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.configuration.ChangeListener; import jetbrains.buildServer.configuration.FileWatcher; import jetbrains.buildServer.serverSide.ServerPaths; import jetbrains.buildServer.util.FileUtil; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.IOException; import java.nio.file.Files; private String teamName; private String token; private Boolean proxyShortNames = false; private boolean enabled = true; public final String SINGLE_HOST_REGEX = "^[^./~`'\"]+(?:/.*)?$"; public final String HOSTNAME_ONLY_REGEX = "^([^/]+)(?:/.*)?$"; private SlackNotificationContentConfig content; private boolean configFileExists; public SlackNotificationMainConfig(ServerPaths serverPaths) { this.content = new SlackNotificationContentConfig(); this.myConfigDir = new File(serverPaths.getConfigDir(), "slack"); this.myConfigFile = new File(this.myConfigDir, "slack-config.xml"); configFileExists = this.myConfigFile.exists(); reloadConfiguration(); this.myChangeObserver = new FileWatcher(this.myConfigFile); this.myChangeObserver.setSleepingPeriod(10000L); this.myChangeObserver.registerListener(this); this.myChangeObserver.start(); } public void refresh(){ reloadConfiguration(); } private void reloadConfiguration() {
Loggers.ACTIVITIES.info("Loading configuration file: " + this.myConfigFile.getAbsolutePath());
PeteGoo/tcSlackBuildNotifier
tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainConfig.java
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // }
import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.configuration.ChangeListener; import jetbrains.buildServer.configuration.FileWatcher; import jetbrains.buildServer.serverSide.ServerPaths; import jetbrains.buildServer.util.FileUtil; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.IOException; import java.nio.file.Files;
{ if (proxyElement.getAttribute("proxyShortNames") != null){ setProxyShortNames(Boolean.parseBoolean(proxyElement.getAttributeValue("proxyShortNames"))); } if (proxyElement.getAttribute("host") != null){ setProxyHost(proxyElement.getAttributeValue("host")); } if (proxyElement.getAttribute("port") != null){ setProxyPort(Integer.parseInt(proxyElement.getAttributeValue("port"))); } if (proxyElement.getAttribute(USERNAME) != null){ setProxyUsername(proxyElement.getAttributeValue(USERNAME)); } if (proxyElement.getAttribute(PASSWORD) != null){ setProxyPassword(proxyElement.getAttributeValue(PASSWORD)); } } else { setProxyHost(null); setProxyPort(null); setProxyUsername(null); setProxyPassword(null); } } }
// Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationProxyConfig.java // public class SlackNotificationProxyConfig { // private Credentials creds = null; // private String proxyHost = null; // private Integer proxyPort = null; // private String proxyUsername = null; // private String proxyPassword = null; // // public SlackNotificationProxyConfig(String hostname, Integer port, String username, String password) { // this.proxyUsername = username; // this.proxyPassword = password; // this.proxyHost = hostname; // this.proxyPort = port; // this.setCreds(); // } // // public SlackNotificationProxyConfig(String hostname, Integer port) { // this.proxyHost = hostname; // this.proxyPort = port; // } // // private void setCreds() { // if ( this.proxyUsername != null && this.proxyUsername.length() > 0 // && this.proxyPassword != null && this.proxyPassword.length() > 0){ // this.creds = new UsernamePasswordCredentials(this.proxyUsername,this.proxyPassword); // } // } // // public Credentials getCreds(){ // return this.creds; // } // // public String getProxyHost() { // return proxyHost; // } // // public void setProxyHost(String proxyHost) { // this.proxyHost = proxyHost; // } // // public Integer getProxyPort() { // return proxyPort; // } // // public void setProxyPort(Integer proxyPort) { // this.proxyPort = proxyPort; // } // // } // // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/Loggers.java // public final class Loggers { // // private Loggers(){} // public static final Logger SERVER = Logger.getInstance("jetbrains.buildServer.SERVER"); // public static final Logger ACTIVITIES = Logger.getInstance("jetbrains.buildServer.ACTIVITIES"); // } // Path: tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainConfig.java import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; import jetbrains.buildServer.configuration.ChangeListener; import jetbrains.buildServer.configuration.FileWatcher; import jetbrains.buildServer.serverSide.ServerPaths; import jetbrains.buildServer.util.FileUtil; import org.jdom.Document; import org.jdom.Element; import org.jdom.JDOMException; import slacknotifications.SlackNotificationProxyConfig; import slacknotifications.teamcity.Loggers; import java.io.File; import java.io.IOException; import java.nio.file.Files; { if (proxyElement.getAttribute("proxyShortNames") != null){ setProxyShortNames(Boolean.parseBoolean(proxyElement.getAttributeValue("proxyShortNames"))); } if (proxyElement.getAttribute("host") != null){ setProxyHost(proxyElement.getAttributeValue("host")); } if (proxyElement.getAttribute("port") != null){ setProxyPort(Integer.parseInt(proxyElement.getAttributeValue("port"))); } if (proxyElement.getAttribute(USERNAME) != null){ setProxyUsername(proxyElement.getAttributeValue(USERNAME)); } if (proxyElement.getAttribute(PASSWORD) != null){ setProxyPassword(proxyElement.getAttributeValue(PASSWORD)); } } else { setProxyHost(null); setProxyPort(null); setProxyUsername(null); setProxyPassword(null); } } }
public SlackNotificationProxyConfig getProxyConfig() {