Skip to content

Add lombok #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ out
.idea
.gradle
*.iml
*.class
*.class
.idea
1,142 changes: 0 additions & 1,142 deletions .idea/workspace.xml

This file was deleted.

24 changes: 19 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ group 'com.example'
version '0.0.1-SNAPSHOT'

apply plugin: 'java'
apply plugin: "net.ltgt.apt"
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.13"
}
}

sourceCompatibility = 1.8

sourceCompatibility = 1.9

repositories {
mavenCentral()
Expand All @@ -13,7 +23,7 @@ repositories {
}

ext {
lombokVersion = '1.16.18'
lombokVersion = '1.16.20'
jacksonVersion = '2.9.2'
socketioVersion = '1.0.0'
reactorVersion = '3.2.0.BUILD-SNAPSHOT'
Expand All @@ -24,15 +34,19 @@ ext {
}

dependencies {
compile group: 'io.reactivex', name:'rxjava', version: rxJava1Version
compile group: 'io.reactivex', name: 'rxjava', version: rxJava1Version
compile group: 'io.socket', name: 'socket.io-client', version: socketioVersion
compile group: 'io.projectreactor.ipc', name: 'reactor-netty', version: reactorNettyVersion
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: jacksonVersion

compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'io.projectreactor', name: 'reactor-test', version: reactorVersion

testCompile group: 'org.powermock', name:'powermock-module-junit4', version: powerMockVersion
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion

apt group: 'org.projectlombok', name: 'lombok', version: lombokVersion

testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: powerMockVersion
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: powerMockVersion
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sun Dec 03 12:42:02 EET 2017
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
zipStoreBase=GRADLE_USER_HOME
1 change: 0 additions & 1 deletion src/main/java/com/example/common/StringEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import java.util.function.Consumer;

public interface StringEmitter {

void onString(Consumer<String> consumer);
}
65 changes: 11 additions & 54 deletions src/main/java/com/example/cryptotrading/StatisticMessage.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.example.cryptotrading;

import lombok.Data;
import lombok.experimental.FieldDefaults;

import java.time.Instant;

import static lombok.AccessLevel.PRIVATE;

@Data
@FieldDefaults(level = PRIVATE, makeFinal = true)
public class StatisticMessage {
private final long timestamp;
private final float data;
private final String currency;
private final StatisticMessage.Type type;
long timestamp;
float data;
String currency;
StatisticMessage.Type type;

public StatisticMessage(float data, String currency, Type type) {
this.timestamp = Instant.now().toEpochMilli();
Expand All @@ -15,56 +22,6 @@ public StatisticMessage(float data, String currency, Type type) {
this.type = type;
}

public float getData() {
return this.data;
}

public String getCurrency() {
return this.currency;
}

public Type getType() {
return this.type;
}

public long getTimestamp() {
return timestamp;
}

public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof StatisticMessage)) return false;
final StatisticMessage other = (StatisticMessage) o;
if (Float.compare(this.getData(), other.getData()) != 0) return false;
final Object this$currency = this.getCurrency();
final Object other$currency = other.getCurrency();
if (this$currency == null ? other$currency != null : !this$currency.equals(other$currency)) return false;
final Object this$type = this.getType();
final Object other$type = other.getType();
if (this$type == null ? other$type != null : !this$type.equals(other$type)) return false;
final Object this$timestamp = this.getTimestamp();
final Object other$timestamp = other.getTimestamp();
if (!this$timestamp.equals(other$timestamp)) return false;
return true;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + Float.floatToIntBits(this.getData());
final Object $currency = this.getCurrency();
result = result * PRIME + ($currency == null ? 43 : $currency.hashCode());
final Object $type = this.getType();
result = result * PRIME + ($type == null ? 43 : $type.hashCode());
final Object $timestamp = this.getTimestamp();
result = result * PRIME + ($timestamp.hashCode());
return result;
}

public String toString() {
return "StatisticMessage(data=" + this.getData() + ", currency=" + this.getCurrency() + ", type=" + this.getType() + ", timestamp=" + this.getTimestamp() + ")";
}

public enum Type {
PRICE, AVG
}
Expand Down
47 changes: 25 additions & 22 deletions src/main/java/com/example/cryptotrading/utils/StatisticUtils.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.example.cryptotrading.utils;

import com.example.cryptotrading.StatisticMessage;
import lombok.experimental.FieldDefaults;
import reactor.core.publisher.Flux;

import java.util.Map;

import static lombok.AccessLevel.PRIVATE;

@FieldDefaults(level = PRIVATE, makeFinal = true)
public class StatisticUtils {
private static final String PRICE_KEY = "PRICE";
private static final String CURRENCY_KEY = "FROMSYMBOL";
static String PRICE_KEY = "PRICE";
static String CURRENCY_KEY = "FROMSYMBOL";

public static Flux<StatisticMessage> transform(Flux<Map<String, Object>> input,
Flux<Long> averagesTimeInterval) {
public static Flux<StatisticMessage> transform(Flux<Map<String, Object>> input, Flux<Long> averagesTimeInterval) {
throw new RuntimeException("Not implemented yet");


Expand All @@ -21,24 +24,24 @@ public static Flux<StatisticMessage> transform(Flux<Map<String, Object>> input,
// return Flux.merge(


// --------------------------------------------------------------------------------------------------

// 1.1) TODO Collect crypto currency price during the interval of seconds
// HINT consider corner case when client did not send any info about interval (add initial interval (mergeWith(...)))
// HINT use window + switchMap
// 1.2) TODO group collected Maps result by currency
// HINT to get currency name from the Map use CURRENCY_KEY constant
// HINT for reduce consider to reuse Sum.empty and Sum#add
// 1.3.1) TODO Filter grouped stream on map without price info
// 1.3.2) TODO Grouped filtered stream reduce calculate average
// 1.3.3) TODO map to Statistic message using StatisticMessage#avg()
//input...,

//
// 2.1) TODO hold latest event with currency price to send latest price if new incoming event does not include price info
// HINT use .scan() + HashMap + .filter to ensure that after proper scan passed map include Price
// 2.2) TODO map to Statistic message using StatisticMessage#price()
//input...
// --------------------------------------------------------------------------------------------------

// 1.1) TODO Collect crypto currency price during the interval of seconds
// HINT consider corner case when client did not send any info about interval (add initial interval (mergeWith(...)))
// HINT use window + switchMap
// 1.2) TODO group collected Maps result by currency
// HINT to get currency name from the Map use CURRENCY_KEY constant
// HINT for reduce consider to reuse Sum.empty and Sum#add
// 1.3.1) TODO Filter grouped stream on map without price info
// 1.3.2) TODO Grouped filtered stream reduce calculate average
// 1.3.3) TODO map to Statistic message using StatisticMessage#avg()
//input...,

//
// 2.1) TODO hold latest event with currency price to send latest price if new incoming event does not include price info
// HINT use .scan() + HashMap + .filter to ensure that after proper scan passed map include Price
// 2.2) TODO map to Statistic message using StatisticMessage#price()
//input...
// );
}

Expand Down
55 changes: 8 additions & 47 deletions src/main/java/com/example/cryptotrading/utils/Sum.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,13 @@
package com.example.cryptotrading.utils;

public class Sum {
private final float value;
private final int counter;

public Sum(float value, int counter) {
this.value = value;
this.counter = counter;
}

public Sum add(float value) {
return new Sum(this.value + value, this.counter + 1);
}

public float avg() {
return value / counter;
}

public static Sum empty() {
return new Sum(0, 0);
}
import lombok.Data;
import lombok.experimental.FieldDefaults;

public float getValue() {
return this.value;
}
import static lombok.AccessLevel.PRIVATE;

public int getCounter() {
return this.counter;
}

public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof Sum)) return false;
final Sum other = (Sum) o;
if (Float.compare(this.getValue(), other.getValue()) != 0) return false;
if (this.getCounter() != other.getCounter()) return false;
return true;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + Float.floatToIntBits(this.getValue());
result = result * PRIME + this.getCounter();
return result;
}

public String toString() {
return "Sum(value=" + this.getValue() + ", counter=" + this.getCounter() + ")";
}
@Data
@FieldDefaults(level = PRIVATE, makeFinal = true)
public class Sum {
float value;
int counter;
}
50 changes: 10 additions & 40 deletions src/main/java/com/example/essential/IndexedWord.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
package com.example.essential;

import java.util.Objects;
import lombok.Data;
import lombok.NonNull;
import lombok.experimental.FieldDefaults;

public class IndexedWord {
private final int index;
private final String word;

public IndexedWord(int index, String word) {
this.index = index;
this.word = Objects.requireNonNull(word);
}

public int getIndex() {
return this.index;
}

public String getWord() {
return this.word;
}
import static lombok.AccessLevel.PRIVATE;

public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof IndexedWord)) return false;
final IndexedWord other = (IndexedWord) o;
if (this.getIndex() != other.getIndex()) return false;
final Object this$word = this.getWord();
final Object other$word = other.getWord();
if (this$word == null ? other$word != null : !this$word.equals(other$word)) return false;
return true;
}

public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.getIndex();
final Object $word = this.getWord();
result = result * PRIME + ($word == null ? 43 : $word.hashCode());
return result;
}

public String toString() {
return "IndexedWord(index=" + this.getIndex() + ", word=" + this.getWord() + ")";
}
@Data
@FieldDefaults(level = PRIVATE, makeFinal = true)
public class IndexedWord {
int index;
@NonNull
String word;
}
Loading