Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ workbench.xmi
.settings
.checkstyle
twitter4j.properties
riskingh/twitter4j.properties
riskingh/src/main/resources/googleMaps.properties
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>ru.fizteh.fivt.students</groupId>
Expand All @@ -19,7 +19,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
<modules>
<module>egiby</module>
<module>akormushin</module>
<!--Add you module here-->
Expand All @@ -46,6 +46,7 @@
<module>ladyae</module>
<module>nikitarykov</module>
<module>duha666</module>
<module>riskingh</module>
</modules>

<dependencies>
Expand Down
46 changes: 46 additions & 0 deletions riskingh/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ru.fizteh.fivt.students</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>ru.fizteh.fivt.students</groupId>
<artifactId>riskingh</artifactId>
<version>1.0-SNAPSHOT</version>
<name>riskingh</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-stream</artifactId>
<version>4.0.4</version>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20151123</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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 <C>
* @param <T>
* @return
*/
public static <C, T extends Comparable<T>> Function<C, T> max(Function<C, T> expression) {
throw new UnsupportedOperationException();
}

/**
* Minimum value for expression for elements of given collecdtion.
*
* @param expression
* @param <C>
* @param <T>
* @return
*/
public static <C, T extends Comparable<T>> Function<C, T> min(Function<C, T> expression) {
throw new UnsupportedOperationException();
}

/**
* Number of items in source collection that turns this expression into not null.
*
* @param expression
* @param <C>
* @param <T>
* @return
*/
public static <C, T extends Comparable<T>> Function<C, T> count(Function<C, T> expression) {
throw new UnsupportedOperationException();
}

/**
* Average value for expression for elements of given collection.
*
* @param expression
* @param <C>
* @param <T>
* @return
*/
public static <C, T extends Comparable<T>> Function<C, T> avg(Function<C, T> expression) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -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> 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<Tuple<String, String>> 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
+ '}';
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ru.fizteh.fivt.students.riskingh.CQL;

import java.util.function.Function;
import java.util.function.Predicate;

public class Conditions<T> {
/**
* Matches string result of expression against regexp pattern.
*
* @param expression expression result to match
* @param regexp pattern to match to
* @param <T> source object type
* @return
*/
public static <T> Predicate<T> rlike(Function<T, String> 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 <T> source object type
* @return
*/
public static <T> Predicate<T> like(Function<T, String> expression, String pattern) {
throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -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 <T>
* @param <R>
* @return
*/
public static <T, R extends Comparable<R>> Comparator<T> asc(Function<T, R> expression) {
return (o1, o2) -> expression.apply(o1).compareTo(expression.apply(o2));
}

/**
* Descending comparator.
*
* @param expression
* @param <T>
* @param <R>
* @return
*/
public static <T, R extends Comparable<R>> Comparator<T> desc(Function<T, R> expression) {
return (o1, o2) -> expression.apply(o2).compareTo(expression.apply(o1));
}
}
Original file line number Diff line number Diff line change
@@ -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 <T>
* @return
*/
@SafeVarargs
public static <T> List<T> list(T... items) {
return Arrays.asList(items);
}

/**
* @param items
* @param <T>
* @return
*/
@SafeVarargs
public static <T> Set<T> set(T... items) {
throw new UnsupportedOperationException();
}

/**
* @param inputStream
* @param <T>
* @return
*/
public static <T> Stream<T> lines(InputStream inputStream) {
throw new UnsupportedOperationException();
}

/**
* @param file
* @param <T>
* @return
*/
public static <T> Stream<T> lines(Path file) {
throw new UnsupportedOperationException();
}

}

Loading