Skip to content

Commit

Permalink
Unified code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jodzga committed Apr 7, 2015
1 parent fd044bd commit a97586c
Show file tree
Hide file tree
Showing 222 changed files with 2,773 additions and 4,657 deletions.
Expand Up @@ -14,29 +14,25 @@
import com.linkedin.parseq.example.common.ExampleUtil;
import com.linkedin.parseq.example.common.MockService;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class FParFilterExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class FParFilterExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new FParFilterExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
final MockService<String> httpClient = getService();
List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");

Task<String> find =
ParSeqCollection.fromValues(urls)
.mapTask(url -> fetchUrl(httpClient, url)
.withTimeout(200, TimeUnit.MILLISECONDS)
.recover("default", t -> ""))
.filter(s -> s.contains("google"))
.find(s -> s.contains("google"));
.mapTask(
url -> fetchUrl(httpClient, url).withTimeout(200, TimeUnit.MILLISECONDS).recover("default", t -> ""))
.filter(s -> s.contains("google")).find(s -> s.contains("google"));

engine.run(find);

Expand Down
Expand Up @@ -10,29 +10,27 @@
import com.linkedin.parseq.example.common.ExampleUtil;
import com.linkedin.parseq.example.common.MockService;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class GroupByExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class GroupByExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new GroupByExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
final MockService<String> httpClient = getService();
List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com",
"http://www.linkedin.com", "http://www.google.com", "http://www.linkedin.com");

Task<String> result = null;
// Collections.fromIterable(urls)
// .par(url -> fetchUrl(httpClient, url))
// .groupBy(i -> i)
// .map(group -> "group: " + group.getKey() + ", count: " + group.count())
// .reduce((a, b) -> a + "\n" + b );
// Collections.fromIterable(urls)
// .par(url -> fetchUrl(httpClient, url))
// .groupBy(i -> i)
// .map(group -> "group: " + group.getKey() + ", count: " + group.count())
// .reduce((a, b) -> a + "\n" + b );

engine.run(result);

Expand Down
Expand Up @@ -11,25 +11,20 @@
import com.linkedin.parseq.example.common.AbstractExample;
import com.linkedin.parseq.example.common.ExampleUtil;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class MaxCollectionExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class MaxCollectionExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new MaxCollectionExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");


Task<String> task = ParSeqCollection.fromValues(urls)
.max(Comparator.naturalOrder())
.andThen(System.out::println);
Task<String> task = ParSeqCollection.fromValues(urls).max(Comparator.naturalOrder()).andThen(System.out::println);

engine.run(task);

Expand Down
Expand Up @@ -15,30 +15,25 @@
import com.linkedin.parseq.example.common.ExampleUtil;
import com.linkedin.parseq.example.common.MockService;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class ParFilterExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class ParFilterExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new ParFilterExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
final MockService<String> httpClient = getService();
List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");

List<Task<String>> fetchSizes = fetchList(httpClient, urls);

Task<String> find =
ParSeqCollection.fromTasks(fetchSizes)
.filter(s -> !s.contains("google"))
.flatMap(z -> ParSeqCollection.fromTasks(fetchList(httpClient, urls))
.filter(s -> s.contains("twitter")))
.find(s -> s.contains("twitter"));
Task<String> find = ParSeqCollection.fromTasks(fetchSizes).filter(s -> !s.contains("google"))
.flatMap(z -> ParSeqCollection.fromTasks(fetchList(httpClient, urls)).filter(s -> s.contains("twitter")))
.find(s -> s.contains("twitter"));

engine.run(find);

Expand All @@ -50,12 +45,8 @@ protected void doRunExample(final Engine engine) throws Exception
}

private List<Task<String>> fetchList(final MockService<String> httpClient, List<String> urls) {
List<Task<String>> fetchSizes =
urls.stream()
.map(url ->
fetchUrl(httpClient, url)
.withTimeout(200, TimeUnit.MILLISECONDS)
.recover("default", t -> ""))
List<Task<String>> fetchSizes = urls.stream()
.map(url -> fetchUrl(httpClient, url).withTimeout(200, TimeUnit.MILLISECONDS).recover("default", t -> ""))
.collect(Collectors.toList());
return fetchSizes;
}
Expand Down
Expand Up @@ -15,30 +15,25 @@
import com.linkedin.parseq.example.common.ExampleUtil;
import com.linkedin.parseq.example.common.MockService;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class ParFindExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class ParFindExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new ParFindExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
final MockService<String> httpClient = getService();
List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");

List<Task<String>> fetchSizes = fetchList(httpClient, urls);

Task<String> find =
ParSeqCollection.fromTasks(fetchSizes)
.filter(s -> s.contains("twitter"))
.mapTask(z -> ParSeqCollection.fromTasks(fetchList(httpClient, urls))
.find(s -> s.contains("linkedin")))
.first();
Task<String> find = ParSeqCollection.fromTasks(fetchSizes).filter(s -> s.contains("twitter"))
.mapTask(z -> ParSeqCollection.fromTasks(fetchList(httpClient, urls)).find(s -> s.contains("linkedin")))
.first();

engine.run(find);

Expand All @@ -50,12 +45,8 @@ protected void doRunExample(final Engine engine) throws Exception
}

private List<Task<String>> fetchList(final MockService<String> httpClient, List<String> urls) {
List<Task<String>> fetchSizes =
urls.stream()
.map(url ->
fetchUrl(httpClient, url)
.withTimeout(200, TimeUnit.MILLISECONDS)
.recover("default", t -> ""))
List<Task<String>> fetchSizes = urls.stream()
.map(url -> fetchUrl(httpClient, url).withTimeout(200, TimeUnit.MILLISECONDS).recover("default", t -> ""))
.collect(Collectors.toList());
return fetchSizes;
}
Expand Down
Expand Up @@ -11,26 +11,21 @@
import com.linkedin.parseq.example.common.AbstractExample;
import com.linkedin.parseq.example.common.ExampleUtil;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class SortedCollectionExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class SortedCollectionExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new SortedCollectionExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
List<Integer> numbers = Arrays.asList(10, 20, 5, 8, 21, 14);


Task<?> task = ParSeqCollection.fromValues(numbers)
.sorted(Comparator.naturalOrder())
.toList()
.andThen(System.out::println);
Task<?> task =
ParSeqCollection.fromValues(numbers).sorted(Comparator.naturalOrder()).toList().andThen(System.out::println);

engine.run(task);

Expand Down
50 changes: 23 additions & 27 deletions example/com/linkedin/parseq/example/collections/StreamExample.java
Expand Up @@ -15,48 +15,44 @@
import com.linkedin.parseq.example.common.ExampleUtil;
import com.linkedin.parseq.example.common.MockService;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class StreamExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class StreamExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new StreamExample().runExample();
}

static final List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");
static final List<String> urls =
Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");
static final List<String> paths = Arrays.asList("/p1", "/p2");

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
final MockService<String> httpClient = getService();

Task<?> task = ParSeqCollection.fromValues(urls)
.flatMap(base -> ParSeqCollection.fromValues(paths)
.map(path -> base + path)
.mapTask(url -> fetchUrl(httpClient, url)))
.subscribe(new Subscriber<String>() {

@Override
public void onSubscribe(Subscription subscription) {
}
Task<?> task = ParSeqCollection.fromValues(urls).flatMap(
base -> ParSeqCollection.fromValues(paths).map(path -> base + path).mapTask(url -> fetchUrl(httpClient, url)))
.subscribe(new Subscriber<String>() {

@Override
public void onNext(String element) {
System.out.println(element);
}
@Override
public void onSubscribe(Subscription subscription) {
}

@Override
public void onError(Throwable cause) {
}
@Override
public void onNext(String element) {
System.out.println(element);
}

@Override
public void onComplete() {
}
});
@Override
public void onError(Throwable cause) {
}

@Override
public void onComplete() {
}
});

engine.run(task);

Expand Down
20 changes: 7 additions & 13 deletions example/com/linkedin/parseq/example/collections/SumExample.java
Expand Up @@ -11,32 +11,26 @@
import com.linkedin.parseq.example.common.AbstractExample;
import com.linkedin.parseq.example.common.ExampleUtil;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class SumExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class SumExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new SumExample().runExample();
}

static final List<Integer> numbers = Arrays.asList(1, 2, 3);

static Task<Integer> toTask(final Integer i) {
// if (true) throw new RuntimeException();
// if (true) throw new RuntimeException();
return Task.callable("number", () -> i);
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
Task<?> task = ParSeqCollection.fromValues(numbers)
.mapTask(SumExample::toTask)
.reduce((a, b) -> a + b)
.map(sum -> "result: " + sum)
.recover(e -> "error")
.andThen(System.out::println);
protected void doRunExample(final Engine engine) throws Exception {
Task<?> task = ParSeqCollection.fromValues(numbers).mapTask(SumExample::toTask).reduce((a, b) -> a + b)
.map(sum -> "result: " + sum).recover(e -> "error").andThen(System.out::println);

engine.run(task);

Expand Down
Expand Up @@ -10,25 +10,20 @@
import com.linkedin.parseq.example.common.AbstractExample;
import com.linkedin.parseq.example.common.ExampleUtil;


/**
* @author Jaroslaw Odzga (jodzga@linkedin.com)
*/
public class SyncCollectionExample extends AbstractExample
{
public static void main(String[] args) throws Exception
{
public class SyncCollectionExample extends AbstractExample {
public static void main(String[] args) throws Exception {
new SyncCollectionExample().runExample();
}

@Override
protected void doRunExample(final Engine engine) throws Exception
{
protected void doRunExample(final Engine engine) throws Exception {
List<String> urls = Arrays.asList("http://www.linkedin.com", "http://www.google.com", "http://www.twitter.com");


Task<String> task = ParSeqCollection.fromValues(urls)
.reduce((a, b) -> a + ", " + b)
.andThen(System.out::println);
Task<String> task = ParSeqCollection.fromValues(urls).reduce((a, b) -> a + ", " + b).andThen(System.out::println);

engine.run(task);

Expand Down

0 comments on commit a97586c

Please sign in to comment.