package edu.mit.streamjit.util.affinity;

import com.google.common.collect.ImmutableSet;
import java.util.Set;

/**
 * Provides static methods for getting and setting the CPU affinity of the
 * current thread.
 * @author Jeffrey Bosboom <jeffreybosboom@gmail.com>
 * @since 1/29/2014
 */
public final class Affinity {
	private static final AffinityStrategy STRATEGY;
	static {
		if (System.getProperty("os.name").contains("Windows"))
			STRATEGY = new NullAffinityStrategy();
		else
			STRATEGY = new LinuxAffinityStrategy();
	}

	public static ImmutableSet<Integer> get() {
		return expand(STRATEGY.get());
	}
	public static void set(Set<Integer> cpus) {
		STRATEGY.set(contract(cpus));
	}

	private static ImmutableSet<Integer> expand(long mask) {
		ImmutableSet.Builder<Integer> builder = ImmutableSet.builder();
		for (int i = 0; i < Long.SIZE && mask != 0; ++i) {
			if ((mask & 1) != 0)
				builder.add(i);
			mask >>>= 1;
		}
		return builder.build();
	}

	private static long contract(Set<Integer> cpus) {
		long mask = 0;
		for (int c : cpus)
			mask |= (1L << c);
		return mask;
	}

	public static void main(String[] args) {
		System.out.println(get());
		set(ImmutableSet.of(2));
		System.out.println(get());
	}
}

@@ -103,16 +103,43 @@
 til.Set;
+%0Aimport org.bridj.Platform;
 %0A%0A/**%0A *
@@ -407,56 +407,27 @@
 if (
-System.getProperty(%22os.name%22).contains(%22
+Platform.is
 Windows
-%22
+(
 ))%0A%09
@@ -473,16 +473,39 @@
 ;%0A%09%09else
+ if (Platform.isUnix())
 %0A%09%09%09STRA
@@ -536,24 +536,73 @@
 Strategy();%0A
+%09%09else%0A%09%09%09STRATEGY = new NullAffinityStrategy();%0A
 %09%7D%0A%0A%09public 

Use BridJ OS detection