diff --git a/.gitignore b/.gitignore index 216927c6..fec2ba57 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ workbench.xmi .settings .checkstyle twitter4j.properties +riskingh/twitter4j.properties +riskingh/src/main/resources/googleMaps.properties diff --git a/pom.xml b/pom.xml index a2fdfbd2..d48c78d8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + + 4.0.0 ru.fizteh.fivt.students @@ -19,7 +19,7 @@ UTF-8 - + egiby akormushin @@ -46,6 +46,7 @@ ladyae nikitarykov duha666 + riskingh diff --git a/riskingh/pom.xml b/riskingh/pom.xml new file mode 100644 index 00000000..d84352a5 --- /dev/null +++ b/riskingh/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + ru.fizteh.fivt.students + parent + 1.0-SNAPSHOT + + ru.fizteh.fivt.students + riskingh + 1.0-SNAPSHOT + riskingh + http://maven.apache.org + + UTF-8 + + + + junit + junit + 4.12 + test + + + org.twitter4j + twitter4j-core + [4.0,) + + + org.twitter4j + twitter4j-stream + 4.0.4 + + + com.beust + jcommander + 1.48 + + + org.json + json + 20151123 + + + diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Aggregates.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Aggregates.java new file mode 100644 index 00000000..f4ea462a --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Aggregates.java @@ -0,0 +1,55 @@ +package ru.fizteh.fivt.students.riskingh.CQL; + +import java.util.function.Function; + +public class Aggregates { + + /** + * Maximum value for expression for elements of given collecdtion. + * + * @param expression + * @param + * @param + * @return + */ + public static > Function max(Function expression) { + throw new UnsupportedOperationException(); + } + + /** + * Minimum value for expression for elements of given collecdtion. + * + * @param expression + * @param + * @param + * @return + */ + public static > Function min(Function expression) { + throw new UnsupportedOperationException(); + } + + /** + * Number of items in source collection that turns this expression into not null. + * + * @param expression + * @param + * @param + * @return + */ + public static > Function count(Function expression) { + throw new UnsupportedOperationException(); + } + + /** + * Average value for expression for elements of given collection. + * + * @param expression + * @param + * @param + * @return + */ + public static > Function avg(Function expression) { + throw new UnsupportedOperationException(); + } + +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/CollectionQuery.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/CollectionQuery.java new file mode 100644 index 00000000..34883cb9 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/CollectionQuery.java @@ -0,0 +1,143 @@ +package ru.fizteh.fivt.students.riskingh.CQL; + +import ru.fizteh.fivt.students.riskingh.CQL.impl.Tuple; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Objects; + + +import static ru.fizteh.fivt.students.riskingh.CQL.Aggregates.avg; +import static ru.fizteh.fivt.students.riskingh.CQL.Aggregates.count; +import static ru.fizteh.fivt.students.riskingh.CQL.CollectionQuery.Student.student; +import static ru.fizteh.fivt.students.riskingh.CQL.Conditions.rlike; +import static ru.fizteh.fivt.students.riskingh.CQL.OrderByConditions.asc; +import static ru.fizteh.fivt.students.riskingh.CQL.OrderByConditions.desc; +import static ru.fizteh.fivt.students.riskingh.CQL.Sources.list; +import static ru.fizteh.fivt.students.riskingh.CQL.impl.FromStmt.from; + +public class CollectionQuery { + + /** + * Make this code work! + * + * @param args + */ + public static void main(String[] args) { + Iterable statistics = + from(list( + student("ivanov", LocalDate.parse("1986-08-06"), "494"), + student("sidorov", LocalDate.parse("1986-08-06"), "495"), + student("smith", LocalDate.parse("1986-08-06"), "495"), + student("petrov", LocalDate.parse("2006-08-06"), "494"))) + .select(Statistics.class, Student::getGroup, count(Student::getGroup), avg(Student::age)) + .where(rlike(Student::getName, ".*ov").and(s -> s.age() > 20)) + .groupBy(Student::getGroup) + .having(s -> s.getCount() > 0) + .orderBy(asc(Statistics::getGroup), desc(Statistics::getCount)) + .limit(100) + .union() + .from(list(student("ivanov", LocalDate.parse("1985-08-06"), "494"))) + .selectDistinct(Statistics.class, s -> "all", count(s -> 1), avg(Student::age)) + .execute(); + System.out.println(statistics); + + Iterable> mentorsByStudent = + from(list(student("ivanov", LocalDate.parse("1985-08-06"), "494"))) + .join(list(new Group("494", "mr.sidorov"))) + .on((s, g) -> Objects.equals(s.getGroup(), g.getGroup())) + .select(sg -> sg.getFirst().getName(), sg -> sg.getSecond().getMentor()) + .execute(); + System.out.println(mentorsByStudent); + } + + + public static class Student { + private final String name; + + private final LocalDate dateOfBith; + + private final String group; + + public String getName() { + return name; + } + + public Student(String name, LocalDate dateOfBith, String group) { + this.name = name; + this.dateOfBith = dateOfBith; + this.group = group; + } + + public LocalDate getDateOfBith() { + return dateOfBith; + } + + public String getGroup() { + return group; + } + + public long age() { + return ChronoUnit.YEARS.between(getDateOfBith(), LocalDateTime.now()); + } + + public static Student student(String name, LocalDate dateOfBirth, String group) { + return new Student(name, dateOfBirth, group); + } + } + + public static class Group { + private final String group; + private final String mentor; + + public Group(String group, String mentor) { + this.group = group; + this.mentor = mentor; + } + + public String getGroup() { + return group; + } + + public String getMentor() { + return mentor; + } + } + + + public static class Statistics { + + private final String group; + private final Long count; + private final Long age; + + public String getGroup() { + return group; + } + + public Long getCount() { + return count; + } + + public Long getAge() { + return age; + } + + public Statistics(String group, Long count, Long age) { + this.group = group; + this.count = count; + this.age = age; + } + + @Override + public String toString() { + return "Statistics{" + + "group='" + group + '\'' + + ", count=" + count + + ", age=" + age + + '}'; + } + } + +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Conditions.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Conditions.java new file mode 100644 index 00000000..1b96814a --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Conditions.java @@ -0,0 +1,31 @@ +package ru.fizteh.fivt.students.riskingh.CQL; + +import java.util.function.Function; +import java.util.function.Predicate; + +public class Conditions { + /** + * Matches string result of expression against regexp pattern. + * + * @param expression expression result to match + * @param regexp pattern to match to + * @param source object type + * @return + */ + public static Predicate rlike(Function expression, String regexp) { + throw new UnsupportedOperationException(); + } + + /** + * Matches string result of expression against SQL like pattern. + * + * @param expression expression result to match + * @param pattern pattern to match to + * @param source object type + * @return + */ + public static Predicate like(Function expression, String pattern) { + throw new UnsupportedOperationException(); + } + +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/OrderByConditions.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/OrderByConditions.java new file mode 100644 index 00000000..32d95d25 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/OrderByConditions.java @@ -0,0 +1,31 @@ +package ru.fizteh.fivt.students.riskingh.CQL; + +import java.util.Comparator; +import java.util.function.Function; + +public class OrderByConditions { + + /** + * Ascending comparator. + * + * @param expression + * @param + * @param + * @return + */ + public static > Comparator asc(Function expression) { + return (o1, o2) -> expression.apply(o1).compareTo(expression.apply(o2)); + } + + /** + * Descending comparator. + * + * @param expression + * @param + * @param + * @return + */ + public static > Comparator desc(Function expression) { + return (o1, o2) -> expression.apply(o2).compareTo(expression.apply(o1)); + } +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Sources.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Sources.java new file mode 100644 index 00000000..1c79ac92 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/Sources.java @@ -0,0 +1,51 @@ +package ru.fizteh.fivt.students.riskingh.CQL; + +import java.io.InputStream; +import java.nio.file.Path; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + +public class Sources { + + /** + * @param items + * @param + * @return + */ + @SafeVarargs + public static List list(T... items) { + return Arrays.asList(items); + } + + /** + * @param items + * @param + * @return + */ + @SafeVarargs + public static Set set(T... items) { + throw new UnsupportedOperationException(); + } + + /** + * @param inputStream + * @param + * @return + */ + public static Stream lines(InputStream inputStream) { + throw new UnsupportedOperationException(); + } + + /** + * @param file + * @param + * @return + */ + public static Stream lines(Path file) { + throw new UnsupportedOperationException(); + } + +} + diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/FromStmt.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/FromStmt.java new file mode 100644 index 00000000..28119f3d --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/FromStmt.java @@ -0,0 +1,106 @@ +package ru.fizteh.fivt.students.riskingh.CQL.impl; + +import javax.management.Query; +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiPredicate; +import java.util.function.Function; +import java.util.stream.Stream; + + +public class FromStmt { + + private List elements = new ArrayList(); + + public List getElements() { + return elements; + } + + public FromStmt(Iterable iterable) { + for (T element : iterable) { + elements.add(element); + } + } + + public static FromStmt from(Iterable iterable) { + return new FromStmt(iterable); + } + + public static FromStmt from(Stream stream) { + throw new UnsupportedOperationException(); + } + + public static FromStmt from(Query query) { + throw new UnsupportedOperationException(); + } + + @SafeVarargs + public final SelectStmt select(Class clazz, Function... s) { + throw new UnsupportedOperationException(); + } + + /** + * Selects the only defined expression as is without wrapper. + * + * @param s + * @param + * @return statement resulting in collection of R + */ + public final SelectStmt select(Function s) { + throw new UnsupportedOperationException(); + } + + /** + * Selects the only defined expression as is without wrapper. + * + * @param first + * @param second + * @param + * @param + * @return statement resulting in collection of R + */ + public final SelectStmt> select(Function first, Function second) { + throw new UnsupportedOperationException(); + } + + @SafeVarargs + public final SelectStmt selectDistinct(Class clazz, Function... s) { + throw new UnsupportedOperationException(); + } + + /** + * Selects the only defined expression as is without wrapper. + * + * @param s + * @param + * @return statement resulting in collection of R + */ + public final SelectStmt selectDistinct(Function s) { + throw new UnsupportedOperationException(); + } + + public JoinClause join(Iterable iterable) { + throw new UnsupportedOperationException(); + } + + public JoinClause join(Stream stream) { + throw new UnsupportedOperationException(); + } + +// public JoinClause join(Query stream) { +// throw new UnsupportedOperationException(); +// } + + public class JoinClause { + + public FromStmt> on(BiPredicate condition) { + throw new UnsupportedOperationException(); + } + + public > FromStmt> on( + Function leftKey, + Function rightKey) { + throw new UnsupportedOperationException(); + } + } +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/Query.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/Query.java new file mode 100644 index 00000000..b1c72731 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/Query.java @@ -0,0 +1,10 @@ +package ru.fizteh.fivt.students.riskingh.CQL.impl; + +import java.util.stream.Stream; + +public interface Query { + + Iterable execute(); + + Stream stream(); +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/SelectStmt.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/SelectStmt.java new file mode 100644 index 00000000..7b20a588 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/SelectStmt.java @@ -0,0 +1,64 @@ +package ru.fizteh.fivt.students.riskingh.CQL.impl; + +import java.util.Comparator; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; + + +public class SelectStmt implements Query { + + @SafeVarargs + public SelectStmt(Function... s) { + throw new UnsupportedOperationException(); + } + + public WhereStmt where(Predicate predicate) { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable execute() { + throw new UnsupportedOperationException(); + } + + @Override + public Stream stream() { + throw new UnsupportedOperationException(); + } + + public class WhereStmt implements Query { + @SafeVarargs + public final WhereStmt groupBy(Function... expressions) { + throw new UnsupportedOperationException(); + } + + @SafeVarargs + public final WhereStmt orderBy(Comparator... comparators) { + throw new UnsupportedOperationException(); + } + + public WhereStmt having(Predicate condition) { + throw new UnsupportedOperationException(); + } + + public WhereStmt limit(int amount) { + throw new UnsupportedOperationException(); + } + + public UnionStmt union() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterable execute() { + throw new UnsupportedOperationException(); + } + + @Override + public Stream stream() { + throw new UnsupportedOperationException(); + } + } + +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/Tuple.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/Tuple.java new file mode 100644 index 00000000..d1a21b45 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/Tuple.java @@ -0,0 +1,28 @@ +package ru.fizteh.fivt.students.riskingh.CQL.impl; + +public class Tuple { + + private final F first; + private final S second; + + public Tuple(F first, S second) { + this.first = first; + this.second = second; + } + + public F getFirst() { + return first; + } + + public S getSecond() { + return second; + } + + @Override + public String toString() { + return "Tuple{" + + "first=" + first + + ", second=" + second + + '}'; + } +} diff --git a/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/UnionStmt.java b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/UnionStmt.java new file mode 100644 index 00000000..a4768a79 --- /dev/null +++ b/riskingh/src/main/java/ru/fizteh/fivt/students/riskingh/CQL/impl/UnionStmt.java @@ -0,0 +1,8 @@ +package ru.fizteh.fivt.students.riskingh.CQL.impl; + +public class UnionStmt { + + public FromStmt from(Iterable list) { + throw new UnsupportedOperationException(); + } +}