1 package net.bmahe.genetics4j.gpu.spec; 2 3 import java.util.List; 4 import java.util.Optional; 5 import java.util.Set; 6 7 import org.apache.commons.lang3.Validate; 8 import org.immutables.value.Value; 9 10 @Value.Immutable 11 public abstract class Program { 12 13 @Value.Parameter 14 public abstract List<String> content(); 15 16 @Value.Parameter 17 public abstract Set<String> resources(); 18 19 @Value.Parameter 20 public abstract Set<String> kernelNames(); 21 22 public abstract Optional<String> buildOptions(); 23 24 @Value.Check 25 protected void check() { 26 Validate.notNull(kernelNames()); 27 Validate.isTrue(kernelNames().isEmpty() == false); 28 } 29 30 public static Program ofContent(final String content, final String kernelName) { 31 Validate.notBlank(content); 32 Validate.notBlank(kernelName); 33 34 return ImmutableProgram.builder() 35 .addContent(content) 36 .addKernelNames(kernelName) 37 .build(); 38 } 39 40 public static Program ofResource(final String resource, final String kernelName) { 41 Validate.notBlank(resource); 42 Validate.notBlank(kernelName); 43 44 return ImmutableProgram.builder() 45 .addResources(resource) 46 .addKernelNames(kernelName) 47 .build(); 48 } 49 50 public static Program ofResource(final String resource, final String kernelName, final String buildOptions) { 51 Validate.notBlank(resource); 52 Validate.notBlank(kernelName); 53 54 return ImmutableProgram.builder() 55 .addResources(resource) 56 .addKernelNames(kernelName) 57 .buildOptions(buildOptions) 58 .build(); 59 } 60 61 public static ImmutableProgram.Builder builder() { 62 return ImmutableProgram.builder(); 63 } 64 }