This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parallel.ForEach(students, student => { | |
student.GradePointAverage = student.Tests.Select(test => test.Grade * test.Weight).Sum(); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void MyParallelForEach<T>(IEnumerable<T> source, Action <T> body) | |
{ | |
int numProcs = Environment.ProcessorCount; | |
int remainingWorkItems = numProcs; | |
using(var enumerator = source.GetEnumerator()) | |
{ | |
using(ManualResetEvent mre = new ManualResetEvent(false)) | |
{ | |
// Create each of the work items. | |
for (int p = 0; p < numProcs; p++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.concurrent.*; | |
public class Parallel { | |
static final Exception CONTINUE = new Exception("forEach Continue"); | |
static { | |
CONTINUE.setStackTrace(new StackTraceElement[0]); | |
} // Delete irrelevant stack trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.concurrent.*; | |
public class Parallel { | |
public static abstract class ForEach<O, K, I> { | |
protected static final Exception CONTINUE = new Exception("forEach Continue"); | |
static { | |
CONTINUE.setStackTrace(new StackTraceElement[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface StreamingProvider extends ContentProvider { | |
void write(OutputStream out) throws IOException; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: contribs/jersey-simple-server/src/main/java/com/sun/jersey/simple/impl/container/SimpleContainer.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- contribs/jersey-simple-server/src/main/java/com/sun/jersey/simple/impl/container/SimpleContainer.java (revision 5823) | |
+++ contribs/jersey-simple-server/src/main/java/com/sun/jersey/simple/impl/container/SimpleContainer.java (revision ) | |
@@ -65,7 +65,7 @@ | |
* This is the container that handles all HTTP requests. Requests are adapted | |
* for the enclosed {@link WebApplication} instances. This container can |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//based on code from http://www.arcfn.com/2009/03/y-combinator-in-arc-and-java.html and the generic version https://gist.github.com/2571928 | |
class YFact { | |
// T function returning a T | |
// T -> T | |
public static interface Func<T> { | |
T apply(T n); | |
} | |
// Higher-order function returning a T function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run with -Xbootclasspath/p:target/classes as ReferencePipeline access is now package local, so use this trick | |
List<Tweet> googleTweets3 = tweets.stream().filter(tweet -> (new MyList<>(google).stream().exists(tweet.text::contains))).collect(toList()); | |
List<Tweet> appleTweets3 = tweets.stream().filter(tweet -> (new MyList<>(apple).stream().exists(tweet.text::contains))).collect(toList()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> google = Arrays.asList("android", "Android", "galaxy", "Galaxy", "nexus", "Nexus"); | |
List<String> apple = Arrays.asList("ios", "iOS", "iphone", "iPhone", "ipad", "iPad"); | |
List<Tweet> tweets = TweetReader.fromTweetSet(TweetReader.allTweets); | |
// Using anyMatch and method reference | |
List<Tweet> googleTweets = tweets.stream().filter(t -> (google.stream().anyMatch(t.text::contains))).collect(toList()); | |
List<Tweet> appleTweets = tweets.stream().filter(t -> (apple.stream().anyMatch(t.text::contains))).collect(toList()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package java.util.stream; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collection; | |
public class MyList<E> extends ArrayList<E> { | |
public MyList(int initialCapacity) { | |
super(initialCapacity); |