repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
polarcoral/monica | monica-registry/src/main/java/monica/registry/Registration.java | // Path: monica-registry/src/main/java/monica/registry/base/RegistryType.java
// public enum RegistryType {
// SERVER, CLIENT
// }
//
// Path: monica-registry/src/main/java/monica/registry/base/UriSpec.java
// public class UriSpec {
// private String scheme;
// private String ip;
// private String port;
//
// public String getScheme() {
// return scheme;
// }
//
// public void setScheme(String scheme) {
// this.scheme = scheme;
// }
//
// public String getIp() {
// return ip;
// }
//
// public void setIp(String ip) {
// this.ip = ip;
// }
//
// public String getPort() {
// return port;
// }
//
// public void setPort(String port) {
// this.port = port;
// }
//
// public String toString() {
// StringBuilder sb = new StringBuilder();
// if (null == scheme || scheme.equals("")) {
// sb.append("monica://");
// } else {
// sb.append(scheme);
// }
// if (null != ip && !ip.equals("")) {
// sb.append(ip);
// }
// sb.append(":");
// if (null != port && !port.equals("")) {
// sb.append(port);
// }
// return sb.toString();
// }
//
// }
//
// Path: monica-registry/src/main/java/monica/registry/service/ZookeeperRegistration.java
// public class ZookeeperRegistration implements Registration {
// public final static String NAME = "zookeeper";
// public final String ZK_NAMESPACE = "monica";
//
// public void register(UriSpec uri, RegistryType type) throws Exception {
// CuratorFramework client = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
// try {
// CuratorWatcher watcher = new CuratorWatcher() {
// public void process(WatchedEvent event) {
// handleChildrenChange("", event.getPath());
// }
// };
// String s = URLEncoder.encode(uri.toString(), "UTF-8");
// if (null == client.checkExists().forPath("/" + type.toString())) {
// client.create().forPath("/" + type.toString());
// }
// client.getChildren().usingWatcher(watcher).forPath("/SERVER");
// if (null == client.checkExists().forPath("/SERVER/" + s)) {
// client.create().withMode(CreateMode.EPHEMERAL).forPath("/SERVER/" + s);
// }
//
// /*
// * List<String> batch = batchCreate(); for (String ss : batch) { if
// * (null == client.checkExists().forPath("/SERVER/" + ss)) {
// * client.create().forPath("/SERVER/" + ss); } }
// */
//
// client.getChildren().usingWatcher(new CuratorWatcher() {
//
// public void process(WatchedEvent event) throws Exception {
//
// handleRoutersChildrenChange("", event.getType());
// }
//
// }).forPath("/SERVER");
//
// // Assert.assertEquals("", "/SERVER");
// } finally {
// // CloseableUtils.closeQuietly(client);
//
// }
// }
//
// private void handleChildrenChange(String name, Object value) {
// log.info("/socket/SERVER NodeChildren changed !");
// // ServiceContext.hashmap.put(name, value);
// }
//
// private void handleRoutersChildrenChange(String name, Object value) {
//
// }
//
// public boolean done() {
// return true;
// }
//
// public List<String> batchCreate() {
// List<String> batchUri = new ArrayList();
// for (int i = 0; i < 2; i++) {
// String b = "monica://192.168.1.10";
// String e = ":8023";
// try {
// batchUri.add(URLEncoder.encode(b + i + e, "UTF-8"));
// System.out.println("batchString[" + i + "] ---- " + (b + i + e));
// } catch (UnsupportedEncodingException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// }
// return batchUri;
// }
// }
| import org.apache.log4j.Logger;
import monica.framework.SPI;
import monica.registry.base.RegistryType;
import monica.registry.base.UriSpec;
import monica.registry.service.ZookeeperRegistration;
| package monica.registry;
/**
*
* plugin point for user to extend the registry-discovery way using the
* different tech framework.
*
* @author [email protected]
*
* 2017-08-29
*/
@SPI(ZookeeperRegistration.NAME)
public interface Registration {
final Logger log = Logger.getLogger(Registration.class);
| // Path: monica-registry/src/main/java/monica/registry/base/RegistryType.java
// public enum RegistryType {
// SERVER, CLIENT
// }
//
// Path: monica-registry/src/main/java/monica/registry/base/UriSpec.java
// public class UriSpec {
// private String scheme;
// private String ip;
// private String port;
//
// public String getScheme() {
// return scheme;
// }
//
// public void setScheme(String scheme) {
// this.scheme = scheme;
// }
//
// public String getIp() {
// return ip;
// }
//
// public void setIp(String ip) {
// this.ip = ip;
// }
//
// public String getPort() {
// return port;
// }
//
// public void setPort(String port) {
// this.port = port;
// }
//
// public String toString() {
// StringBuilder sb = new StringBuilder();
// if (null == scheme || scheme.equals("")) {
// sb.append("monica://");
// } else {
// sb.append(scheme);
// }
// if (null != ip && !ip.equals("")) {
// sb.append(ip);
// }
// sb.append(":");
// if (null != port && !port.equals("")) {
// sb.append(port);
// }
// return sb.toString();
// }
//
// }
//
// Path: monica-registry/src/main/java/monica/registry/service/ZookeeperRegistration.java
// public class ZookeeperRegistration implements Registration {
// public final static String NAME = "zookeeper";
// public final String ZK_NAMESPACE = "monica";
//
// public void register(UriSpec uri, RegistryType type) throws Exception {
// CuratorFramework client = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
// try {
// CuratorWatcher watcher = new CuratorWatcher() {
// public void process(WatchedEvent event) {
// handleChildrenChange("", event.getPath());
// }
// };
// String s = URLEncoder.encode(uri.toString(), "UTF-8");
// if (null == client.checkExists().forPath("/" + type.toString())) {
// client.create().forPath("/" + type.toString());
// }
// client.getChildren().usingWatcher(watcher).forPath("/SERVER");
// if (null == client.checkExists().forPath("/SERVER/" + s)) {
// client.create().withMode(CreateMode.EPHEMERAL).forPath("/SERVER/" + s);
// }
//
// /*
// * List<String> batch = batchCreate(); for (String ss : batch) { if
// * (null == client.checkExists().forPath("/SERVER/" + ss)) {
// * client.create().forPath("/SERVER/" + ss); } }
// */
//
// client.getChildren().usingWatcher(new CuratorWatcher() {
//
// public void process(WatchedEvent event) throws Exception {
//
// handleRoutersChildrenChange("", event.getType());
// }
//
// }).forPath("/SERVER");
//
// // Assert.assertEquals("", "/SERVER");
// } finally {
// // CloseableUtils.closeQuietly(client);
//
// }
// }
//
// private void handleChildrenChange(String name, Object value) {
// log.info("/socket/SERVER NodeChildren changed !");
// // ServiceContext.hashmap.put(name, value);
// }
//
// private void handleRoutersChildrenChange(String name, Object value) {
//
// }
//
// public boolean done() {
// return true;
// }
//
// public List<String> batchCreate() {
// List<String> batchUri = new ArrayList();
// for (int i = 0; i < 2; i++) {
// String b = "monica://192.168.1.10";
// String e = ":8023";
// try {
// batchUri.add(URLEncoder.encode(b + i + e, "UTF-8"));
// System.out.println("batchString[" + i + "] ---- " + (b + i + e));
// } catch (UnsupportedEncodingException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// }
// return batchUri;
// }
// }
// Path: monica-registry/src/main/java/monica/registry/Registration.java
import org.apache.log4j.Logger;
import monica.framework.SPI;
import monica.registry.base.RegistryType;
import monica.registry.base.UriSpec;
import monica.registry.service.ZookeeperRegistration;
package monica.registry;
/**
*
* plugin point for user to extend the registry-discovery way using the
* different tech framework.
*
* @author [email protected]
*
* 2017-08-29
*/
@SPI(ZookeeperRegistration.NAME)
public interface Registration {
final Logger log = Logger.getLogger(Registration.class);
| public void register(UriSpec uri, RegistryType type) throws Exception;
|
polarcoral/monica | monica-cluster/src/main/java/monica/cluster/router/main/UpdateRulesMain.java | // Path: monica-configuration/src/main/java/monica/configuration/context/ConfigurationContext.java
// public class ConfigurationContext {
// private static String yamlBaseFilePath = "yaml";
//
// public static ConcurrentHashMap<String, Object> propMap = new ConcurrentHashMap<String, Object>();
//
// /**
// * need to adapt to different registry framework. below just be customized to zookeeper
// * @throws FileNotFoundException
// * @throws IOException
// */
// public static void loadYamlServerConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("yaml\\monica.yaml");
// //YamlMonica yamlMonica = yaml.loadAs(new FileInputStream(path), YamlMonica.class);
// YamlMonica yamlMonica = yaml.loadAs(Utils.loadResources("yaml/monica.yaml").openStream(), YamlMonica.class);
// propMap.putIfAbsent("yamlMonica", yamlMonica);
// propMap.putIfAbsent("serverString", yamlMonica.toServerString());
// propMap.putIfAbsent("storage", yamlMonica.getStorage());
// }
//
//
// public static void loadYamlClientConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\client.yaml");
// //YamlClient yamlClient = yaml.loadAs(new FileInputStream(path), YamlClient.class);
// YamlClient yamlClient = yaml.loadAs(Utils.loadResources("yaml/client.yaml").openStream(), YamlClient.class);
// propMap.putIfAbsent("client", yamlClient);
// propMap.putIfAbsent("serverString", yamlClient.toServerString());
// }
//
// public static List<String> loadYamlRouterConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\router.yaml");
// //YamlRouter yamlRouter = yaml.loadAs(new FileInputStream(path), YamlRouter.class);
// YamlRouter yamlRouter = yaml.loadAs(Utils.loadResources("yaml/router.yaml").openStream(), YamlRouter.class);
// return yamlRouter.toStringList();
// }
//
//
// private static ClassLoader getClassLoader(){
// return ConfigurationContext.class.getClassLoader();
// }
//
// public static void main(String args[]){
// try {
// //loadYamlServerConfig();
// //YamlMonica monica = (YamlMonica)propMap.get("yamlMonica");
// List<String> rules = loadYamlRouterConfig();
// System.out.println("zk -------- "+rules.get(0));
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
//
// }
//
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
//
// Path: monica-registry/src/main/java/monica/registry/service/ZookeeperMonicaClient.java
// public class ZookeeperMonicaClient {
// private final String ZK_NAMESPACE = "monica";
// private CuratorFramework zkClient;
//
// public void start() {
// CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
// zkClient = builder.connectString(getServerConnectionString()).namespace(ZK_NAMESPACE)
// .retryPolicy(new RetryOneTime(1)).connectionTimeoutMs(1).sessionTimeoutMs(140).build();
// zkClient.start();
// RegistryContext.clientCache.putIfAbsent("curatorClient", zkClient);
// }
//
// private String getServerConnectionString() {
// return String.valueOf(ConfigurationContext.propMap.get("serverString"));
// }
//
// public CuratorFramework getZookeeperClient() throws KeeperException.ConnectionLossException {
// if (zkClient.getZookeeperClient().isConnected()) {
// return this.zkClient;
// } else {
// throw new KeeperException.ConnectionLossException();
// }
//
// }
//
// }
| import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import monica.configuration.context.ConfigurationContext;
import monica.registry.context.RegistryContext;
import monica.registry.service.ZookeeperMonicaClient;
| package monica.cluster.router.main;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class UpdateRulesMain {
private final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
private final String RULE_PATH = "/routers";
/**
* The only entrance for update routing rules step 1) delete all rule nodes
* from zk step 2) create all rule nodes on zk
*/
public static void main(String args[]) {
try {
| // Path: monica-configuration/src/main/java/monica/configuration/context/ConfigurationContext.java
// public class ConfigurationContext {
// private static String yamlBaseFilePath = "yaml";
//
// public static ConcurrentHashMap<String, Object> propMap = new ConcurrentHashMap<String, Object>();
//
// /**
// * need to adapt to different registry framework. below just be customized to zookeeper
// * @throws FileNotFoundException
// * @throws IOException
// */
// public static void loadYamlServerConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("yaml\\monica.yaml");
// //YamlMonica yamlMonica = yaml.loadAs(new FileInputStream(path), YamlMonica.class);
// YamlMonica yamlMonica = yaml.loadAs(Utils.loadResources("yaml/monica.yaml").openStream(), YamlMonica.class);
// propMap.putIfAbsent("yamlMonica", yamlMonica);
// propMap.putIfAbsent("serverString", yamlMonica.toServerString());
// propMap.putIfAbsent("storage", yamlMonica.getStorage());
// }
//
//
// public static void loadYamlClientConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\client.yaml");
// //YamlClient yamlClient = yaml.loadAs(new FileInputStream(path), YamlClient.class);
// YamlClient yamlClient = yaml.loadAs(Utils.loadResources("yaml/client.yaml").openStream(), YamlClient.class);
// propMap.putIfAbsent("client", yamlClient);
// propMap.putIfAbsent("serverString", yamlClient.toServerString());
// }
//
// public static List<String> loadYamlRouterConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\router.yaml");
// //YamlRouter yamlRouter = yaml.loadAs(new FileInputStream(path), YamlRouter.class);
// YamlRouter yamlRouter = yaml.loadAs(Utils.loadResources("yaml/router.yaml").openStream(), YamlRouter.class);
// return yamlRouter.toStringList();
// }
//
//
// private static ClassLoader getClassLoader(){
// return ConfigurationContext.class.getClassLoader();
// }
//
// public static void main(String args[]){
// try {
// //loadYamlServerConfig();
// //YamlMonica monica = (YamlMonica)propMap.get("yamlMonica");
// List<String> rules = loadYamlRouterConfig();
// System.out.println("zk -------- "+rules.get(0));
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
//
// }
//
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
//
// Path: monica-registry/src/main/java/monica/registry/service/ZookeeperMonicaClient.java
// public class ZookeeperMonicaClient {
// private final String ZK_NAMESPACE = "monica";
// private CuratorFramework zkClient;
//
// public void start() {
// CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
// zkClient = builder.connectString(getServerConnectionString()).namespace(ZK_NAMESPACE)
// .retryPolicy(new RetryOneTime(1)).connectionTimeoutMs(1).sessionTimeoutMs(140).build();
// zkClient.start();
// RegistryContext.clientCache.putIfAbsent("curatorClient", zkClient);
// }
//
// private String getServerConnectionString() {
// return String.valueOf(ConfigurationContext.propMap.get("serverString"));
// }
//
// public CuratorFramework getZookeeperClient() throws KeeperException.ConnectionLossException {
// if (zkClient.getZookeeperClient().isConnected()) {
// return this.zkClient;
// } else {
// throw new KeeperException.ConnectionLossException();
// }
//
// }
//
// }
// Path: monica-cluster/src/main/java/monica/cluster/router/main/UpdateRulesMain.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import monica.configuration.context.ConfigurationContext;
import monica.registry.context.RegistryContext;
import monica.registry.service.ZookeeperMonicaClient;
package monica.cluster.router.main;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class UpdateRulesMain {
private final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
private final String RULE_PATH = "/routers";
/**
* The only entrance for update routing rules step 1) delete all rule nodes
* from zk step 2) create all rule nodes on zk
*/
public static void main(String args[]) {
try {
| ConfigurationContext.loadYamlClientConfig();
|
polarcoral/monica | monica-cluster/src/main/java/monica/cluster/router/main/UpdateRulesMain.java | // Path: monica-configuration/src/main/java/monica/configuration/context/ConfigurationContext.java
// public class ConfigurationContext {
// private static String yamlBaseFilePath = "yaml";
//
// public static ConcurrentHashMap<String, Object> propMap = new ConcurrentHashMap<String, Object>();
//
// /**
// * need to adapt to different registry framework. below just be customized to zookeeper
// * @throws FileNotFoundException
// * @throws IOException
// */
// public static void loadYamlServerConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("yaml\\monica.yaml");
// //YamlMonica yamlMonica = yaml.loadAs(new FileInputStream(path), YamlMonica.class);
// YamlMonica yamlMonica = yaml.loadAs(Utils.loadResources("yaml/monica.yaml").openStream(), YamlMonica.class);
// propMap.putIfAbsent("yamlMonica", yamlMonica);
// propMap.putIfAbsent("serverString", yamlMonica.toServerString());
// propMap.putIfAbsent("storage", yamlMonica.getStorage());
// }
//
//
// public static void loadYamlClientConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\client.yaml");
// //YamlClient yamlClient = yaml.loadAs(new FileInputStream(path), YamlClient.class);
// YamlClient yamlClient = yaml.loadAs(Utils.loadResources("yaml/client.yaml").openStream(), YamlClient.class);
// propMap.putIfAbsent("client", yamlClient);
// propMap.putIfAbsent("serverString", yamlClient.toServerString());
// }
//
// public static List<String> loadYamlRouterConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\router.yaml");
// //YamlRouter yamlRouter = yaml.loadAs(new FileInputStream(path), YamlRouter.class);
// YamlRouter yamlRouter = yaml.loadAs(Utils.loadResources("yaml/router.yaml").openStream(), YamlRouter.class);
// return yamlRouter.toStringList();
// }
//
//
// private static ClassLoader getClassLoader(){
// return ConfigurationContext.class.getClassLoader();
// }
//
// public static void main(String args[]){
// try {
// //loadYamlServerConfig();
// //YamlMonica monica = (YamlMonica)propMap.get("yamlMonica");
// List<String> rules = loadYamlRouterConfig();
// System.out.println("zk -------- "+rules.get(0));
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
//
// }
//
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
//
// Path: monica-registry/src/main/java/monica/registry/service/ZookeeperMonicaClient.java
// public class ZookeeperMonicaClient {
// private final String ZK_NAMESPACE = "monica";
// private CuratorFramework zkClient;
//
// public void start() {
// CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
// zkClient = builder.connectString(getServerConnectionString()).namespace(ZK_NAMESPACE)
// .retryPolicy(new RetryOneTime(1)).connectionTimeoutMs(1).sessionTimeoutMs(140).build();
// zkClient.start();
// RegistryContext.clientCache.putIfAbsent("curatorClient", zkClient);
// }
//
// private String getServerConnectionString() {
// return String.valueOf(ConfigurationContext.propMap.get("serverString"));
// }
//
// public CuratorFramework getZookeeperClient() throws KeeperException.ConnectionLossException {
// if (zkClient.getZookeeperClient().isConnected()) {
// return this.zkClient;
// } else {
// throw new KeeperException.ConnectionLossException();
// }
//
// }
//
// }
| import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import monica.configuration.context.ConfigurationContext;
import monica.registry.context.RegistryContext;
import monica.registry.service.ZookeeperMonicaClient;
| package monica.cluster.router.main;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class UpdateRulesMain {
private final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
private final String RULE_PATH = "/routers";
/**
* The only entrance for update routing rules step 1) delete all rule nodes
* from zk step 2) create all rule nodes on zk
*/
public static void main(String args[]) {
try {
ConfigurationContext.loadYamlClientConfig();
| // Path: monica-configuration/src/main/java/monica/configuration/context/ConfigurationContext.java
// public class ConfigurationContext {
// private static String yamlBaseFilePath = "yaml";
//
// public static ConcurrentHashMap<String, Object> propMap = new ConcurrentHashMap<String, Object>();
//
// /**
// * need to adapt to different registry framework. below just be customized to zookeeper
// * @throws FileNotFoundException
// * @throws IOException
// */
// public static void loadYamlServerConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("yaml\\monica.yaml");
// //YamlMonica yamlMonica = yaml.loadAs(new FileInputStream(path), YamlMonica.class);
// YamlMonica yamlMonica = yaml.loadAs(Utils.loadResources("yaml/monica.yaml").openStream(), YamlMonica.class);
// propMap.putIfAbsent("yamlMonica", yamlMonica);
// propMap.putIfAbsent("serverString", yamlMonica.toServerString());
// propMap.putIfAbsent("storage", yamlMonica.getStorage());
// }
//
//
// public static void loadYamlClientConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\client.yaml");
// //YamlClient yamlClient = yaml.loadAs(new FileInputStream(path), YamlClient.class);
// YamlClient yamlClient = yaml.loadAs(Utils.loadResources("yaml/client.yaml").openStream(), YamlClient.class);
// propMap.putIfAbsent("client", yamlClient);
// propMap.putIfAbsent("serverString", yamlClient.toServerString());
// }
//
// public static List<String> loadYamlRouterConfig() throws FileNotFoundException, IOException{
// Yaml yaml = new Yaml();
// File path = Utils.getPropertiesPath("\\yaml\\router.yaml");
// //YamlRouter yamlRouter = yaml.loadAs(new FileInputStream(path), YamlRouter.class);
// YamlRouter yamlRouter = yaml.loadAs(Utils.loadResources("yaml/router.yaml").openStream(), YamlRouter.class);
// return yamlRouter.toStringList();
// }
//
//
// private static ClassLoader getClassLoader(){
// return ConfigurationContext.class.getClassLoader();
// }
//
// public static void main(String args[]){
// try {
// //loadYamlServerConfig();
// //YamlMonica monica = (YamlMonica)propMap.get("yamlMonica");
// List<String> rules = loadYamlRouterConfig();
// System.out.println("zk -------- "+rules.get(0));
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// }
//
// }
//
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
//
// Path: monica-registry/src/main/java/monica/registry/service/ZookeeperMonicaClient.java
// public class ZookeeperMonicaClient {
// private final String ZK_NAMESPACE = "monica";
// private CuratorFramework zkClient;
//
// public void start() {
// CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
// zkClient = builder.connectString(getServerConnectionString()).namespace(ZK_NAMESPACE)
// .retryPolicy(new RetryOneTime(1)).connectionTimeoutMs(1).sessionTimeoutMs(140).build();
// zkClient.start();
// RegistryContext.clientCache.putIfAbsent("curatorClient", zkClient);
// }
//
// private String getServerConnectionString() {
// return String.valueOf(ConfigurationContext.propMap.get("serverString"));
// }
//
// public CuratorFramework getZookeeperClient() throws KeeperException.ConnectionLossException {
// if (zkClient.getZookeeperClient().isConnected()) {
// return this.zkClient;
// } else {
// throw new KeeperException.ConnectionLossException();
// }
//
// }
//
// }
// Path: monica-cluster/src/main/java/monica/cluster/router/main/UpdateRulesMain.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import monica.configuration.context.ConfigurationContext;
import monica.registry.context.RegistryContext;
import monica.registry.service.ZookeeperMonicaClient;
package monica.cluster.router.main;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class UpdateRulesMain {
private final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
private final String RULE_PATH = "/routers";
/**
* The only entrance for update routing rules step 1) delete all rule nodes
* from zk step 2) create all rule nodes on zk
*/
public static void main(String args[]) {
try {
ConfigurationContext.loadYamlClientConfig();
| new ZookeeperMonicaClient().start();
|
polarcoral/monica | monica-files/monica-files-socket/src/main/java/monica/files/socket/FileClientInitializer.java | // Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
| import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import io.netty.handler.ssl.SslContext;
import monica.registry.context.RegistryContext;
| package monica.files.socket;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class FileClientInitializer extends ChannelInitializer<SocketChannel> {
private final String SERVER_IP_CACHE = "server_ip";
private final String SERVER_PORT_CACHE = "server_port";
| // Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
// Path: monica-files/monica-files-socket/src/main/java/monica/files/socket/FileClientInitializer.java
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import io.netty.handler.ssl.SslContext;
import monica.registry.context.RegistryContext;
package monica.files.socket;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class FileClientInitializer extends ChannelInitializer<SocketChannel> {
private final String SERVER_IP_CACHE = "server_ip";
private final String SERVER_PORT_CACHE = "server_port";
| private String ip = (String) RegistryContext.clientCache.get(SERVER_IP_CACHE);
|
polarcoral/monica | monica-coordinator/src/main/java/monica/coordinator/impl/ServiceBuilder.java | // Path: monica-cluster/src/main/java/monica/cluster/loadbalance/LoadBalanceHandler.java
// public class LoadBalanceHandler {
// private String TEMP_PROVIDER_CACHE = "temp_providers";
// private String SERVER_STRING = "server_string";
//
// private LoadBalance defaultAlgorithm() {
// return new RandomLoadBalance();
// }
//
// public void handle() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
// List<String> providers = (List) RegistryContext.clientCache.get(TEMP_PROVIDER_CACHE);
// final String CLIENT_KEY = "client";
// YamlClient client = (YamlClient) ConfigurationContext.propMap.get(CLIENT_KEY);
// String loadBalanceName = client.getLoadbalance();
// LoadBalance balance = (LoadBalance) this.getClass().getClassLoader().loadClass(loadBalanceName).newInstance();
// int index = balance.doSelect(providers);
// String selectedString = providers.get(index);
// // providers.clear();
// // providers.add(selectedString);
// }
// }
//
// Path: monica-cluster/src/main/java/monica/cluster/router/RouteHandler.java
// public class RouteHandler {
// private List<Rule> rulesList = new CopyOnWriteArrayList<Rule>();
// private final String RULES_PATH = "/routers";
//
// public RouteHandler() {
// super();
// rulesInit();
// }
//
// private void rulesInit() {
// final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
// try {
// if (null != zkClient.checkExists().forPath(RULES_PATH)) {
// List<String> childList = zkClient.getChildren().forPath(RULES_PATH);
// for (String rule : childList) {
// StringToObjectParser stringParser = new StringToObjectParser();
// rulesList.add(stringParser.parseRuleStringToRule(URLDecoder.decode(rule, "UTF-8")));
// }
// }
// filterRulesForConsumer();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public void handle() {
// rulesList.sort(new Comparator() {
// public int compare(Object o1, Object o2) {
// return ((Rule) o1).compareTo(((Rule) o2));
// }
//
// });
// for (Rule s : rulesList) {
// try {
// IpParser.class.getMethod(s.getSource().getOps().name().toLowerCase() + "Consumer", s.getClass());
// } catch (NoSuchMethodException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// /**
// * conditions: localhost.IP, localhost.ip.net.* , , 127.0.0.1
// */
//
// private void filterRulesForConsumer() throws UnknownHostException {
// for (Rule rule : rulesList) {
// if (!isMatched(rule)) {
// rulesList.remove(rule);
// }
// }
// }
//
// private boolean isMatched(Rule rule) throws UnknownHostException {
// String localIp = InetAddress.getLocalHost().getHostAddress();
// String netSegment = localIp.substring(0, localIp.lastIndexOf(".")) + ".*";
// // not allowed loopback address
// String loopbackIp = "127.0.0.1";
// String emptyIsAll = " ";
// if (null != rule) {
// String srcString = rule.getSource().toString();// .substring(rule.indexOf("'")+1,rule.indexOf("=>"));
// // System.out.println("srcString ------------ "+srcString+"
// // "+netSegment);
// if (srcString.contains(localIp) || srcString.contains(netSegment) || srcString.contains(loopbackIp)
// || srcString.contains(emptyIsAll)) {
// return true;
// }
// }
// return false;
// }
//
// public static void main(String args[]) {
// try {
// ConfigurationContext.loadYamlClientConfig();
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// new ZookeeperMonicaClient().start();
// RouteHandler router = new RouteHandler();
// router.handle();
// System.out.println("rules.size ------------ " + router.rulesList.size());
// }
// }
//
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
| import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import monica.cluster.loadbalance.LoadBalanceHandler;
import monica.cluster.router.RouteHandler;
import monica.registry.context.RegistryContext;
| package monica.coordinator.impl;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class ServiceBuilder {
private final String TEMP_PROVIDERS = "temp_providers";
private final String PROVIDER_CACHE = "providers";
private final String SERVER_IP_CACHE = "server_ip";
private final String SERVER_PORT_CACHE = "server_port";
public ServiceBuilder servicesInit() throws Exception {
| // Path: monica-cluster/src/main/java/monica/cluster/loadbalance/LoadBalanceHandler.java
// public class LoadBalanceHandler {
// private String TEMP_PROVIDER_CACHE = "temp_providers";
// private String SERVER_STRING = "server_string";
//
// private LoadBalance defaultAlgorithm() {
// return new RandomLoadBalance();
// }
//
// public void handle() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
// List<String> providers = (List) RegistryContext.clientCache.get(TEMP_PROVIDER_CACHE);
// final String CLIENT_KEY = "client";
// YamlClient client = (YamlClient) ConfigurationContext.propMap.get(CLIENT_KEY);
// String loadBalanceName = client.getLoadbalance();
// LoadBalance balance = (LoadBalance) this.getClass().getClassLoader().loadClass(loadBalanceName).newInstance();
// int index = balance.doSelect(providers);
// String selectedString = providers.get(index);
// // providers.clear();
// // providers.add(selectedString);
// }
// }
//
// Path: monica-cluster/src/main/java/monica/cluster/router/RouteHandler.java
// public class RouteHandler {
// private List<Rule> rulesList = new CopyOnWriteArrayList<Rule>();
// private final String RULES_PATH = "/routers";
//
// public RouteHandler() {
// super();
// rulesInit();
// }
//
// private void rulesInit() {
// final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
// try {
// if (null != zkClient.checkExists().forPath(RULES_PATH)) {
// List<String> childList = zkClient.getChildren().forPath(RULES_PATH);
// for (String rule : childList) {
// StringToObjectParser stringParser = new StringToObjectParser();
// rulesList.add(stringParser.parseRuleStringToRule(URLDecoder.decode(rule, "UTF-8")));
// }
// }
// filterRulesForConsumer();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public void handle() {
// rulesList.sort(new Comparator() {
// public int compare(Object o1, Object o2) {
// return ((Rule) o1).compareTo(((Rule) o2));
// }
//
// });
// for (Rule s : rulesList) {
// try {
// IpParser.class.getMethod(s.getSource().getOps().name().toLowerCase() + "Consumer", s.getClass());
// } catch (NoSuchMethodException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
//
// }
//
// /**
// * conditions: localhost.IP, localhost.ip.net.* , , 127.0.0.1
// */
//
// private void filterRulesForConsumer() throws UnknownHostException {
// for (Rule rule : rulesList) {
// if (!isMatched(rule)) {
// rulesList.remove(rule);
// }
// }
// }
//
// private boolean isMatched(Rule rule) throws UnknownHostException {
// String localIp = InetAddress.getLocalHost().getHostAddress();
// String netSegment = localIp.substring(0, localIp.lastIndexOf(".")) + ".*";
// // not allowed loopback address
// String loopbackIp = "127.0.0.1";
// String emptyIsAll = " ";
// if (null != rule) {
// String srcString = rule.getSource().toString();// .substring(rule.indexOf("'")+1,rule.indexOf("=>"));
// // System.out.println("srcString ------------ "+srcString+"
// // "+netSegment);
// if (srcString.contains(localIp) || srcString.contains(netSegment) || srcString.contains(loopbackIp)
// || srcString.contains(emptyIsAll)) {
// return true;
// }
// }
// return false;
// }
//
// public static void main(String args[]) {
// try {
// ConfigurationContext.loadYamlClientConfig();
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// new ZookeeperMonicaClient().start();
// RouteHandler router = new RouteHandler();
// router.handle();
// System.out.println("rules.size ------------ " + router.rulesList.size());
// }
// }
//
// Path: monica-registry/src/main/java/monica/registry/context/RegistryContext.java
// public class RegistryContext {
// // caheKey: curatorClient providers server usefulProviders
// public static ConcurrentHashMap<String, Object> clientCache = new ConcurrentHashMap<String, Object>();
// }
// Path: monica-coordinator/src/main/java/monica/coordinator/impl/ServiceBuilder.java
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import monica.cluster.loadbalance.LoadBalanceHandler;
import monica.cluster.router.RouteHandler;
import monica.registry.context.RegistryContext;
package monica.coordinator.impl;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class ServiceBuilder {
private final String TEMP_PROVIDERS = "temp_providers";
private final String PROVIDER_CACHE = "providers";
private final String SERVER_IP_CACHE = "server_ip";
private final String SERVER_PORT_CACHE = "server_port";
public ServiceBuilder servicesInit() throws Exception {
| final CuratorFramework zkClient = (CuratorFramework) RegistryContext.clientCache.get("curatorClient");
|
polarcoral/monica | monica-examples/src/main/java/monica/examples/MonicaServer.java | // Path: monica-starter/src/main/java/monica/starter/server/ServerStarter.java
// public class ServerStarter {
//
// private final Logger log = LoggerFactory.getLogger(ServerStarter.class);
// private final String protocolPrefix = "monica.files";
//
// public void start() throws Exception {
// // take note of the number arg for CountDownLatch() constructor.
// // CountDownLatch instance will wait the countDown number which is
// // specified here.
// final CountDownLatch zkSignal = new CountDownLatch(1);
// final CountDownLatch nettySignal = new CountDownLatch(1);
// ConfigurationContext.loadYamlServerConfig();
// YamlMonica monica = (YamlMonica) ConfigurationContext.propMap.get("yamlMonica");
// String protocolString = monica.getProtocol();
// String className = protocolString.substring(0, 1).toUpperCase()
// + protocolString.substring(1, protocolString.length()) + "Server";
// String protocolPackageName = protocolPrefix + "." + monica.getProtocol();
// ClassPool pool = ClassPool.getDefault();
// CtClass cc = pool.get(protocolPackageName + "." + className);
// Object o = cc.toClass().newInstance();
// final Server server = (Server) o;
// Executors.newSingleThreadExecutor().execute(new NettyRunnable(zkSignal, server));
// Executors.newSingleThreadExecutor().execute(new ZookeeperRunnable(zkSignal));
// for (;;) {
// // the Server isStrated field is visible to multi-thread by volatile
// // modifier
// if (server.isStarted()) {
// nettySignal.countDown();
// break;
// }
// }
// nettySignal.await();
// ConfigServiceInit.init();
// new RegistryCentre().setUri(createUri(server)).setType(RegistryType.SERVER).start();
//
// if (RegistryCentre.registryFinished()) {
// log.info("monica server start successfully!");
// }
// log.warn("monica server start successfully!");
// }
//
// private UriSpec createUri(Server server) throws Exception {
// UriSpec uriSpec = new UriSpec();
// uriSpec.setIp(server.getHostIp());
// uriSpec.setPort(server.getPort() + "");
// return uriSpec;
// }
//
// public static void main(String args[]) {
// try {
// ServerStarter container = new ServerStarter();
// container.start();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
//
// class ZookeeperRunnable implements Runnable {
// private CountDownLatch zkCountDown;
//
// public ZookeeperRunnable(CountDownLatch latch) {
// this.zkCountDown = latch;
// }
//
// public void run() {
// new ZookeeperMonicaClient().start();
// zkCountDown.countDown();
// }
// }
//
// class NettyRunnable implements Runnable {
// private final CountDownLatch zkSignal;
// private Server server;
//
// public NettyRunnable(CountDownLatch zkLatch, Server monicaServer) {
// this.zkSignal = zkLatch;
// server = monicaServer;
// }
//
// public void run() {
// try {
// zkSignal.await();
// server.start();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
//
// }
//
// }
| import monica.starter.server.ServerStarter;
| /*
* Copyright 2017 The Monica Project
*
* The Monica Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package monica.examples;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class MonicaServer {
public static void main(String args[]) {
| // Path: monica-starter/src/main/java/monica/starter/server/ServerStarter.java
// public class ServerStarter {
//
// private final Logger log = LoggerFactory.getLogger(ServerStarter.class);
// private final String protocolPrefix = "monica.files";
//
// public void start() throws Exception {
// // take note of the number arg for CountDownLatch() constructor.
// // CountDownLatch instance will wait the countDown number which is
// // specified here.
// final CountDownLatch zkSignal = new CountDownLatch(1);
// final CountDownLatch nettySignal = new CountDownLatch(1);
// ConfigurationContext.loadYamlServerConfig();
// YamlMonica monica = (YamlMonica) ConfigurationContext.propMap.get("yamlMonica");
// String protocolString = monica.getProtocol();
// String className = protocolString.substring(0, 1).toUpperCase()
// + protocolString.substring(1, protocolString.length()) + "Server";
// String protocolPackageName = protocolPrefix + "." + monica.getProtocol();
// ClassPool pool = ClassPool.getDefault();
// CtClass cc = pool.get(protocolPackageName + "." + className);
// Object o = cc.toClass().newInstance();
// final Server server = (Server) o;
// Executors.newSingleThreadExecutor().execute(new NettyRunnable(zkSignal, server));
// Executors.newSingleThreadExecutor().execute(new ZookeeperRunnable(zkSignal));
// for (;;) {
// // the Server isStrated field is visible to multi-thread by volatile
// // modifier
// if (server.isStarted()) {
// nettySignal.countDown();
// break;
// }
// }
// nettySignal.await();
// ConfigServiceInit.init();
// new RegistryCentre().setUri(createUri(server)).setType(RegistryType.SERVER).start();
//
// if (RegistryCentre.registryFinished()) {
// log.info("monica server start successfully!");
// }
// log.warn("monica server start successfully!");
// }
//
// private UriSpec createUri(Server server) throws Exception {
// UriSpec uriSpec = new UriSpec();
// uriSpec.setIp(server.getHostIp());
// uriSpec.setPort(server.getPort() + "");
// return uriSpec;
// }
//
// public static void main(String args[]) {
// try {
// ServerStarter container = new ServerStarter();
// container.start();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
//
// class ZookeeperRunnable implements Runnable {
// private CountDownLatch zkCountDown;
//
// public ZookeeperRunnable(CountDownLatch latch) {
// this.zkCountDown = latch;
// }
//
// public void run() {
// new ZookeeperMonicaClient().start();
// zkCountDown.countDown();
// }
// }
//
// class NettyRunnable implements Runnable {
// private final CountDownLatch zkSignal;
// private Server server;
//
// public NettyRunnable(CountDownLatch zkLatch, Server monicaServer) {
// this.zkSignal = zkLatch;
// server = monicaServer;
// }
//
// public void run() {
// try {
// zkSignal.await();
// server.start();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// }
//
// }
//
// }
// Path: monica-examples/src/main/java/monica/examples/MonicaServer.java
import monica.starter.server.ServerStarter;
/*
* Copyright 2017 The Monica Project
*
* The Monica Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package monica.examples;
/**
*
* @author [email protected]
*
* 2017-08-29
*/
public class MonicaServer {
public static void main(String args[]) {
| ServerStarter container = new ServerStarter();
|
dtboy1995/android-sex-http | http/src/main/java/org/ithot/android/transmit/http/Res.java | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// public static JSONSerializer json() {
// return _json;
// }
| import android.content.Context;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req.ihttpHook;
import static org.ithot.android.transmit.http.Req.json; | package org.ithot.android.transmit.http;
/**
* 响应
*/
public abstract class Res<T> implements IHTTPResult {
public abstract void ok(Header[] headers, T response);
public abstract void no(Header[] headers, String error);
private Type getType() {
Type type = getClass().getGenericSuperclass();
ParameterizedType parameter = (ParameterizedType) type;
return parameter.getActualTypeArguments()[0];
}
@Override
public void cache(String response) {
Type type;
try {
type = getType();
} catch (Exception e) {
type = null;
}
if (type != null && type == String.class) {
ok(null, (T) response);
return;
} | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// public static JSONSerializer json() {
// return _json;
// }
// Path: http/src/main/java/org/ithot/android/transmit/http/Res.java
import android.content.Context;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req.ihttpHook;
import static org.ithot.android.transmit.http.Req.json;
package org.ithot.android.transmit.http;
/**
* 响应
*/
public abstract class Res<T> implements IHTTPResult {
public abstract void ok(Header[] headers, T response);
public abstract void no(Header[] headers, String error);
private Type getType() {
Type type = getClass().getGenericSuperclass();
ParameterizedType parameter = (ParameterizedType) type;
return parameter.getActualTypeArguments()[0];
}
@Override
public void cache(String response) {
Type type;
try {
type = getType();
} catch (Exception e) {
type = null;
}
if (type != null && type == String.class) {
ok(null, (T) response);
return;
} | T t = (T) json().parse(response, type); |
dtboy1995/android-sex-http | http/src/main/java/org/ithot/android/transmit/http/Res.java | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// public static JSONSerializer json() {
// return _json;
// }
| import android.content.Context;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req.ihttpHook;
import static org.ithot.android.transmit.http.Req.json; | package org.ithot.android.transmit.http;
/**
* 响应
*/
public abstract class Res<T> implements IHTTPResult {
public abstract void ok(Header[] headers, T response);
public abstract void no(Header[] headers, String error);
private Type getType() {
Type type = getClass().getGenericSuperclass();
ParameterizedType parameter = (ParameterizedType) type;
return parameter.getActualTypeArguments()[0];
}
@Override
public void cache(String response) {
Type type;
try {
type = getType();
} catch (Exception e) {
type = null;
}
if (type != null && type == String.class) {
ok(null, (T) response);
return;
}
T t = (T) json().parse(response, type);
ok(null, t);
}
@Override
public void disconnected(Context context) { | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// public static JSONSerializer json() {
// return _json;
// }
// Path: http/src/main/java/org/ithot/android/transmit/http/Res.java
import android.content.Context;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req.ihttpHook;
import static org.ithot.android.transmit.http.Req.json;
package org.ithot.android.transmit.http;
/**
* 响应
*/
public abstract class Res<T> implements IHTTPResult {
public abstract void ok(Header[] headers, T response);
public abstract void no(Header[] headers, String error);
private Type getType() {
Type type = getClass().getGenericSuperclass();
ParameterizedType parameter = (ParameterizedType) type;
return parameter.getActualTypeArguments()[0];
}
@Override
public void cache(String response) {
Type type;
try {
type = getType();
} catch (Exception e) {
type = null;
}
if (type != null && type == String.class) {
ok(null, (T) response);
return;
}
T t = (T) json().parse(response, type);
ok(null, t);
}
@Override
public void disconnected(Context context) { | if (ihttpHook != null) { |
dtboy1995/android-sex-http | http/src/main/java/org/ithot/android/transmit/http/HTTPHandler.java | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static DualCache<String> _cache;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static AsyncHttpClient client;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
| import com.loopj.android.http.TextHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req._cache;
import static org.ithot.android.transmit.http.Req.client;
import static org.ithot.android.transmit.http.Req.ihttpHook; | package org.ithot.android.transmit.http;
/**
* 请求处理器
*/
public class HTTPHandler extends TextHttpResponseHandler {
Req req;
public HTTPHandler(Req req) {
this.req = req;
}
@Override
public void onSuccess(int status, Header[] headers, final String response) {
Utils.Logger.debug(response); | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static DualCache<String> _cache;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static AsyncHttpClient client;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
// Path: http/src/main/java/org/ithot/android/transmit/http/HTTPHandler.java
import com.loopj.android.http.TextHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req._cache;
import static org.ithot.android.transmit.http.Req.client;
import static org.ithot.android.transmit.http.Req.ihttpHook;
package org.ithot.android.transmit.http;
/**
* 请求处理器
*/
public class HTTPHandler extends TextHttpResponseHandler {
Req req;
public HTTPHandler(Req req) {
this.req = req;
}
@Override
public void onSuccess(int status, Header[] headers, final String response) {
Utils.Logger.debug(response); | if (ihttpHook != null) { |
dtboy1995/android-sex-http | http/src/main/java/org/ithot/android/transmit/http/HTTPHandler.java | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static DualCache<String> _cache;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static AsyncHttpClient client;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
| import com.loopj.android.http.TextHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req._cache;
import static org.ithot.android.transmit.http.Req.client;
import static org.ithot.android.transmit.http.Req.ihttpHook; | package org.ithot.android.transmit.http;
/**
* 请求处理器
*/
public class HTTPHandler extends TextHttpResponseHandler {
Req req;
public HTTPHandler(Req req) {
this.req = req;
}
@Override
public void onSuccess(int status, Header[] headers, final String response) {
Utils.Logger.debug(response);
if (ihttpHook != null) {
ihttpHook.post(req._context);
}
if (req._method == Method.GET) {
switch (req._cachePolicy) {
case NoCache:
req._res.success(status, headers, response);
break;
case CacheAndRemote:
case IgnoreCache:
case CacheOnly:
case CacheOrRemote:
req._res.success(status, headers, response);
// write cache | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static DualCache<String> _cache;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static AsyncHttpClient client;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
// Path: http/src/main/java/org/ithot/android/transmit/http/HTTPHandler.java
import com.loopj.android.http.TextHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req._cache;
import static org.ithot.android.transmit.http.Req.client;
import static org.ithot.android.transmit.http.Req.ihttpHook;
package org.ithot.android.transmit.http;
/**
* 请求处理器
*/
public class HTTPHandler extends TextHttpResponseHandler {
Req req;
public HTTPHandler(Req req) {
this.req = req;
}
@Override
public void onSuccess(int status, Header[] headers, final String response) {
Utils.Logger.debug(response);
if (ihttpHook != null) {
ihttpHook.post(req._context);
}
if (req._method == Method.GET) {
switch (req._cachePolicy) {
case NoCache:
req._res.success(status, headers, response);
break;
case CacheAndRemote:
case IgnoreCache:
case CacheOnly:
case CacheOrRemote:
req._res.success(status, headers, response);
// write cache | client.getThreadPool().execute(new Runnable() { |
dtboy1995/android-sex-http | http/src/main/java/org/ithot/android/transmit/http/HTTPHandler.java | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static DualCache<String> _cache;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static AsyncHttpClient client;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
| import com.loopj.android.http.TextHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req._cache;
import static org.ithot.android.transmit.http.Req.client;
import static org.ithot.android.transmit.http.Req.ihttpHook; | package org.ithot.android.transmit.http;
/**
* 请求处理器
*/
public class HTTPHandler extends TextHttpResponseHandler {
Req req;
public HTTPHandler(Req req) {
this.req = req;
}
@Override
public void onSuccess(int status, Header[] headers, final String response) {
Utils.Logger.debug(response);
if (ihttpHook != null) {
ihttpHook.post(req._context);
}
if (req._method == Method.GET) {
switch (req._cachePolicy) {
case NoCache:
req._res.success(status, headers, response);
break;
case CacheAndRemote:
case IgnoreCache:
case CacheOnly:
case CacheOrRemote:
req._res.success(status, headers, response);
// write cache
client.getThreadPool().execute(new Runnable() {
@Override
public void run() { | // Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static DualCache<String> _cache;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static AsyncHttpClient client;
//
// Path: http/src/main/java/org/ithot/android/transmit/http/Req.java
// static IHTTPHook ihttpHook;
// Path: http/src/main/java/org/ithot/android/transmit/http/HTTPHandler.java
import com.loopj.android.http.TextHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
import static org.ithot.android.transmit.http.Req._cache;
import static org.ithot.android.transmit.http.Req.client;
import static org.ithot.android.transmit.http.Req.ihttpHook;
package org.ithot.android.transmit.http;
/**
* 请求处理器
*/
public class HTTPHandler extends TextHttpResponseHandler {
Req req;
public HTTPHandler(Req req) {
this.req = req;
}
@Override
public void onSuccess(int status, Header[] headers, final String response) {
Utils.Logger.debug(response);
if (ihttpHook != null) {
ihttpHook.post(req._context);
}
if (req._method == Method.GET) {
switch (req._cachePolicy) {
case NoCache:
req._res.success(status, headers, response);
break;
case CacheAndRemote:
case IgnoreCache:
case CacheOnly:
case CacheOrRemote:
req._res.success(status, headers, response);
// write cache
client.getThreadPool().execute(new Runnable() {
@Override
public void run() { | _cache.put(req.key(), response); |
tomwhite/set-game | src/test/java/com/tom_e_white/set_game/model/CardTest.java | // Path: src/main/java/com/tom_e_white/set_game/model/Card.java
// public class Card {
// // The ordinal values follow "The Joy of Set"
// public enum Number {
// THREE, ONE, TWO; // so that the ordinals make sense (mod 3)
//
// public static Number parseDescription(String description) {
// int num = Integer.parseInt(description.split(" ")[0]);
// return values()[num % 3];
// }
// public static Number parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Color {
// GREEN, PURPLE, RED;
//
// public static Color parseDescription(String description) {
// return valueOf(description.split(" ")[1].toUpperCase());
// }
// public static Color parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shading {
// EMPTY, STRIPED, SOLID;
//
// public static Shading parseDescription(String description) {
// return valueOf(description.split(" ")[2].toUpperCase());
// }
// public static Shading parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shape {
// DIAMOND, OVAL, SQUIGGLE;
//
// public static Shape parseDescription(String description) {
// return valueOf(description.split(" ")[3].toUpperCase().replaceFirst("S$", ""));
// }
// public static Shape parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
//
// private static String toDescription(File file) {
// String reg = "([^-]+)-([^-]+).*(\\d)\\.jpg";
// Pattern pattern = Pattern.compile(reg);
// Matcher matcher = pattern.matcher(file.getName());
// if (matcher.matches()) {
// String colour = matcher.group(1);
// String number = matcher.group(2);
// String index = matcher.group(3);
// return toDescription(Integer.parseInt(number), colour, Integer.parseInt(index));
// }
// throw new IllegalArgumentException("Unrecognized file: " + file);
// }
//
// private static String toDescription(int number, String colour, int index) {
// // order signifies how v1 training data cards were laid out
// // solid, striped, empty
// // oval, diamond, squiggle
// switch (index) {
// case 1: return toDescription(number, colour, Shading.SOLID, Shape.OVAL);
// case 2: return toDescription(number, colour, Shading.SOLID, Shape.DIAMOND);
// case 3: return toDescription(number, colour, Shading.SOLID, Shape.SQUIGGLE);
// case 4: return toDescription(number, colour, Shading.STRIPED, Shape.OVAL);
// case 5: return toDescription(number, colour, Shading.STRIPED, Shape.DIAMOND);
// case 6: return toDescription(number, colour, Shading.STRIPED, Shape.SQUIGGLE);
// case 7: return toDescription(number, colour, Shading.EMPTY, Shape.OVAL);
// case 8: return toDescription(number, colour, Shading.EMPTY, Shape.DIAMOND);
// case 9: return toDescription(number, colour, Shading.EMPTY, Shape.SQUIGGLE);
// default: throw new IllegalArgumentException("Unrecognized index " + index);
// }
// }
//
// private static String toDescription(int number, String colour, Shading shading, Shape shape) {
// String s = number == 1 ? "" : "s";
// return number + " " + colour + " " + shading.name().toLowerCase() + " " + shape.name().toLowerCase() + s;
// }
//
// private final Number number;
// private final Color color;
// private final Shading shading;
// private final Shape shape;
//
// public Card(String description) {
// this.number = Number.parseDescription(description);
// this.color = Color.parseDescription(description);
// this.shading = Shading.parseDescription(description);
// this.shape = Shape.parseDescription(description);
// }
//
// public Card(int numberLabel, int colorLabel, int shadingLabel, int shapeLabel) {
// this.number = Number.values()[numberLabel];
// this.color = Color.values()[colorLabel];
// this.shading = Shading.values()[shadingLabel];
// this.shape = Shape.values()[shapeLabel];
// }
//
// public Number number() { return number; }
// public Color color() { return color; }
// public Shading shading() { return shading; }
// public Shape shape() { return shape; }
//
// public String getDescription() {
// int num = number.ordinal() == 0 ? 3 : number.ordinal();
// return toDescription(num, color.name().toLowerCase(), shading, shape);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Card card = (Card) o;
//
// if (number != card.number) return false;
// if (color != card.color) return false;
// if (shading != card.shading) return false;
// return shape == card.shape;
// }
//
// @Override
// public int hashCode() {
// int result = number.hashCode();
// result = 31 * result + color.hashCode();
// result = 31 * result + shading.hashCode();
// result = 31 * result + shape.hashCode();
// return result;
// }
//
// @Override
// public String toString() {
// return getDescription();
// }
// }
| import com.tom_e_white.set_game.model.Card;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertEquals; | package com.tom_e_white.set_game.model;
public class CardTest {
@Test
public void testParseDescription() {
String description = "3 red solid squiggles"; | // Path: src/main/java/com/tom_e_white/set_game/model/Card.java
// public class Card {
// // The ordinal values follow "The Joy of Set"
// public enum Number {
// THREE, ONE, TWO; // so that the ordinals make sense (mod 3)
//
// public static Number parseDescription(String description) {
// int num = Integer.parseInt(description.split(" ")[0]);
// return values()[num % 3];
// }
// public static Number parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Color {
// GREEN, PURPLE, RED;
//
// public static Color parseDescription(String description) {
// return valueOf(description.split(" ")[1].toUpperCase());
// }
// public static Color parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shading {
// EMPTY, STRIPED, SOLID;
//
// public static Shading parseDescription(String description) {
// return valueOf(description.split(" ")[2].toUpperCase());
// }
// public static Shading parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shape {
// DIAMOND, OVAL, SQUIGGLE;
//
// public static Shape parseDescription(String description) {
// return valueOf(description.split(" ")[3].toUpperCase().replaceFirst("S$", ""));
// }
// public static Shape parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
//
// private static String toDescription(File file) {
// String reg = "([^-]+)-([^-]+).*(\\d)\\.jpg";
// Pattern pattern = Pattern.compile(reg);
// Matcher matcher = pattern.matcher(file.getName());
// if (matcher.matches()) {
// String colour = matcher.group(1);
// String number = matcher.group(2);
// String index = matcher.group(3);
// return toDescription(Integer.parseInt(number), colour, Integer.parseInt(index));
// }
// throw new IllegalArgumentException("Unrecognized file: " + file);
// }
//
// private static String toDescription(int number, String colour, int index) {
// // order signifies how v1 training data cards were laid out
// // solid, striped, empty
// // oval, diamond, squiggle
// switch (index) {
// case 1: return toDescription(number, colour, Shading.SOLID, Shape.OVAL);
// case 2: return toDescription(number, colour, Shading.SOLID, Shape.DIAMOND);
// case 3: return toDescription(number, colour, Shading.SOLID, Shape.SQUIGGLE);
// case 4: return toDescription(number, colour, Shading.STRIPED, Shape.OVAL);
// case 5: return toDescription(number, colour, Shading.STRIPED, Shape.DIAMOND);
// case 6: return toDescription(number, colour, Shading.STRIPED, Shape.SQUIGGLE);
// case 7: return toDescription(number, colour, Shading.EMPTY, Shape.OVAL);
// case 8: return toDescription(number, colour, Shading.EMPTY, Shape.DIAMOND);
// case 9: return toDescription(number, colour, Shading.EMPTY, Shape.SQUIGGLE);
// default: throw new IllegalArgumentException("Unrecognized index " + index);
// }
// }
//
// private static String toDescription(int number, String colour, Shading shading, Shape shape) {
// String s = number == 1 ? "" : "s";
// return number + " " + colour + " " + shading.name().toLowerCase() + " " + shape.name().toLowerCase() + s;
// }
//
// private final Number number;
// private final Color color;
// private final Shading shading;
// private final Shape shape;
//
// public Card(String description) {
// this.number = Number.parseDescription(description);
// this.color = Color.parseDescription(description);
// this.shading = Shading.parseDescription(description);
// this.shape = Shape.parseDescription(description);
// }
//
// public Card(int numberLabel, int colorLabel, int shadingLabel, int shapeLabel) {
// this.number = Number.values()[numberLabel];
// this.color = Color.values()[colorLabel];
// this.shading = Shading.values()[shadingLabel];
// this.shape = Shape.values()[shapeLabel];
// }
//
// public Number number() { return number; }
// public Color color() { return color; }
// public Shading shading() { return shading; }
// public Shape shape() { return shape; }
//
// public String getDescription() {
// int num = number.ordinal() == 0 ? 3 : number.ordinal();
// return toDescription(num, color.name().toLowerCase(), shading, shape);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Card card = (Card) o;
//
// if (number != card.number) return false;
// if (color != card.color) return false;
// if (shading != card.shading) return false;
// return shape == card.shape;
// }
//
// @Override
// public int hashCode() {
// int result = number.hashCode();
// result = 31 * result + color.hashCode();
// result = 31 * result + shading.hashCode();
// result = 31 * result + shape.hashCode();
// return result;
// }
//
// @Override
// public String toString() {
// return getDescription();
// }
// }
// Path: src/test/java/com/tom_e_white/set_game/model/CardTest.java
import com.tom_e_white.set_game.model.Card;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertEquals;
package com.tom_e_white.set_game.model;
public class CardTest {
@Test
public void testParseDescription() {
String description = "3 red solid squiggles"; | assertEquals(Card.Number.THREE, Card.Number.parseDescription(description)); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/predict/PredictCards.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
| import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.List; | package com.tom_e_white.set_game.predict;
/**
* Use {@link CardPredictor} to predict cards (with no descriptions).
*/
public class PredictCards {
public static void predict(File testFile, CardPredictor cardPredictor) throws IOException, ParseException { | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
// Path: src/main/java/com/tom_e_white/set_game/predict/PredictCards.java
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
package com.tom_e_white.set_game.predict;
/**
* Use {@link CardPredictor} to predict cards (with no descriptions).
*/
public class PredictCards {
public static void predict(File testFile, CardPredictor cardPredictor) throws IOException, ParseException { | CardDetector cardDetector = new CardDetector(); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/predict/PredictCards.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
| import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.List; | package com.tom_e_white.set_game.predict;
/**
* Use {@link CardPredictor} to predict cards (with no descriptions).
*/
public class PredictCards {
public static void predict(File testFile, CardPredictor cardPredictor) throws IOException, ParseException {
CardDetector cardDetector = new CardDetector(); | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
// Path: src/main/java/com/tom_e_white/set_game/predict/PredictCards.java
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
package com.tom_e_white.set_game.predict;
/**
* Use {@link CardPredictor} to predict cards (with no descriptions).
*/
public class PredictCards {
public static void predict(File testFile, CardPredictor cardPredictor) throws IOException, ParseException {
CardDetector cardDetector = new CardDetector(); | List<CardImage> images = cardDetector.detect(testFile.getAbsolutePath(), false, true); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/preprocess/CreateTestSetV1.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
| import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.util.List; | package com.tom_e_white.set_game.preprocess;
/**
* Use {@link CardDetector} to create a test set of cards.
*/
public class CreateTestSetV1 {
public static void main(String[] args) { | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTestSetV1.java
import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
package com.tom_e_white.set_game.preprocess;
/**
* Use {@link CardDetector} to create a test set of cards.
*/
public class CreateTestSetV1 {
public static void main(String[] args) { | CardDetector cardDetector = new CardDetector(); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/preprocess/CreateTestSetV1.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
| import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.util.List; | package com.tom_e_white.set_game.preprocess;
/**
* Use {@link CardDetector} to create a test set of cards.
*/
public class CreateTestSetV1 {
public static void main(String[] args) {
CardDetector cardDetector = new CardDetector();
File outDir = new File("data/test-out");
outDir.mkdirs();
File file = new File("data/20170106_205743.jpg");
try {
System.out.println(file); | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTestSetV1.java
import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
package com.tom_e_white.set_game.preprocess;
/**
* Use {@link CardDetector} to create a test set of cards.
*/
public class CreateTestSetV1 {
public static void main(String[] args) {
CardDetector cardDetector = new CardDetector();
File outDir = new File("data/test-out");
outDir.mkdirs();
File file = new File("data/20170106_205743.jpg");
try {
System.out.println(file); | List<CardImage> images = cardDetector.detect(file.getAbsolutePath()); |
tomwhite/set-game | src/test/java/com/tom_e_white/set_game/preprocess/CardDetectorTest.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
| import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; | package com.tom_e_white.set_game.preprocess;
public class CardDetectorTest {
private CardDetector cardDetector = new CardDetector();
@Test
public void testNoCards() throws IOException { | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
// Path: src/test/java/com/tom_e_white/set_game/preprocess/CardDetectorTest.java
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
package com.tom_e_white.set_game.preprocess;
public class CardDetectorTest {
private CardDetector cardDetector = new CardDetector();
@Test
public void testNoCards() throws IOException { | List<CardImage> images = cardDetector.detect("src/test/resources/data/egg.jpg"); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/predict/PredictCardNumberOnTrainingData.java | // Path: src/main/java/com/tom_e_white/set_game/train/FindCardNumberFeatures.java
// public class FindCardNumberFeatures extends FeatureFinder {
//
// @Override
// public int getLabelFromFilename(String filename) {
// return Card.Number.parseFilename(new File(filename)).ordinal();
// }
//
// @Override
// public int getLabelFromDescription(String description) {
// return Card.Number.parseDescription(description).ordinal();
// }
//
// @Override
// public double[] find(BufferedImage image, boolean debug) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Shape> shapes = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(3) // this is fairly critical
// .edges()
// .dilate()
// .contours()
// .polygons(0.05, 0.05)
// .getExternalShapes();
//
// int expectedWidth = 40 * 3; // 40mm
// int expectedHeight = 20 * 3; // 20mm
// int tolerancePct = 40;
// List<Shape> filtered = GeometryUtils.filterByArea(shapes, expectedWidth, expectedHeight, tolerancePct);
// List<Shape> nonOverlapping = GeometryUtils.filterNonOverlappingBoundingBoxes(filtered);
//
// if (debug) {
// System.out.println(shapes);
// System.out.println(filtered);
// System.out.println(nonOverlapping);
// ShowImages.showWindow(panel, "Binary Operations", true);
// }
// return new double[] { nonOverlapping.size() % 3 }; // just return as an int mod 3
// }
//
// @Override
// public String getFileSuffix() {
// return "number.csv";
// }
//
// @Override
// public Classifier<double[]> getClassifier() throws IOException, ParseException {
// return doubles -> ((int) doubles[0]) % 3; // just return as an int mod 3
// }
//
// public static void main(String[] args) throws IOException {
// BufferedImage image = UtilImageIO.loadImage(args[0]);
// FindCardNumberFeatures featureFinder = new FindCardNumberFeatures();
// double[] features = featureFinder.find(image, true);
// System.out.println(featureFinder.getSummaryLine(args[0], features));
// }
//
// }
| import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.train.FindCardNumberFeatures;
import java.io.File;
import java.io.IOException; | package com.tom_e_white.set_game.predict;
/**
* Use {@link FindCardNumberFeatures} to predict the number of shapes on each card in the training set.
* This is OK since we don't actually train a model for number - we just do clever image processing.
*/
public class PredictCardNumberOnTrainingData {
public static double computeAccuracyOnTrainingData() throws IOException { | // Path: src/main/java/com/tom_e_white/set_game/train/FindCardNumberFeatures.java
// public class FindCardNumberFeatures extends FeatureFinder {
//
// @Override
// public int getLabelFromFilename(String filename) {
// return Card.Number.parseFilename(new File(filename)).ordinal();
// }
//
// @Override
// public int getLabelFromDescription(String description) {
// return Card.Number.parseDescription(description).ordinal();
// }
//
// @Override
// public double[] find(BufferedImage image, boolean debug) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Shape> shapes = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(3) // this is fairly critical
// .edges()
// .dilate()
// .contours()
// .polygons(0.05, 0.05)
// .getExternalShapes();
//
// int expectedWidth = 40 * 3; // 40mm
// int expectedHeight = 20 * 3; // 20mm
// int tolerancePct = 40;
// List<Shape> filtered = GeometryUtils.filterByArea(shapes, expectedWidth, expectedHeight, tolerancePct);
// List<Shape> nonOverlapping = GeometryUtils.filterNonOverlappingBoundingBoxes(filtered);
//
// if (debug) {
// System.out.println(shapes);
// System.out.println(filtered);
// System.out.println(nonOverlapping);
// ShowImages.showWindow(panel, "Binary Operations", true);
// }
// return new double[] { nonOverlapping.size() % 3 }; // just return as an int mod 3
// }
//
// @Override
// public String getFileSuffix() {
// return "number.csv";
// }
//
// @Override
// public Classifier<double[]> getClassifier() throws IOException, ParseException {
// return doubles -> ((int) doubles[0]) % 3; // just return as an int mod 3
// }
//
// public static void main(String[] args) throws IOException {
// BufferedImage image = UtilImageIO.loadImage(args[0]);
// FindCardNumberFeatures featureFinder = new FindCardNumberFeatures();
// double[] features = featureFinder.find(image, true);
// System.out.println(featureFinder.getSummaryLine(args[0], features));
// }
//
// }
// Path: src/main/java/com/tom_e_white/set_game/predict/PredictCardNumberOnTrainingData.java
import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.train.FindCardNumberFeatures;
import java.io.File;
import java.io.IOException;
package com.tom_e_white.set_game.predict;
/**
* Use {@link FindCardNumberFeatures} to predict the number of shapes on each card in the training set.
* This is OK since we don't actually train a model for number - we just do clever image processing.
*/
public class PredictCardNumberOnTrainingData {
public static double computeAccuracyOnTrainingData() throws IOException { | FindCardNumberFeatures cardFeatureCounter = new FindCardNumberFeatures(); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/train/CreateTrainingDataV2.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTrainingSetV2.java
// public class CreateTrainingSetV2 {
// public static void main(String[] args) throws IOException {
// if (!RAW_LABELLED_DIRECTORY.exists()) {
// CardDetector cardDetector = new CardDetector(4, 66);
// File outDir = RAW_LABELLED_DIRECTORY;
// outDir.mkdirs();
// for (File d : RAW_SORTED_DIRECTORY.listFiles((dir, name) -> name.matches("\\d"))) {
// int numberLabel = Integer.valueOf(d.getName());
// for (File file : d.listFiles((dir, name) -> name.matches(".*\\.jpg"))) {
// System.out.println(file);
// List<CardImage> images = cardDetector.detect(file.getAbsolutePath(), false, true, 3, 9);
// int i = 0;
// for (CardImage image : images) {
// Card card = new Card(numberLabel, (i % 9) / 3, i / 9, i % 3);
// File labelledDirectory = new File(outDir, card.getDescription().replace(" ", "-"));
// labelledDirectory.mkdirs();
// File newFile = new File(labelledDirectory, file.getName().replace(".jpg", "_" + numberLabel + "_" + i + ".jpg"));
// UtilImageIO.saveImage(image.getImage(), newFile.getAbsolutePath());
// i++;
// }
// }
// }
// }
//
// ViewLabelledImagesV2.view(RAW_LABELLED_DIRECTORY);
// }
//
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/TrainingDataV2.java
// public interface TrainingDataV2 {
// File RAW_NEW_DIRECTORY = new File("data/train-v2/raw-new");
// File RAW_SORTED_DIRECTORY = new File("data/train-v2/raw-sorted");
// File RAW_LABELLED_DIRECTORY = new File("data/train-v2/raw-labelled");
// File LABELLED_DIRECTORY = new File("data/train-v2/labelled");
// }
| import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CreateTrainingSetV2;
import com.tom_e_white.set_game.preprocess.TrainingDataV2;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List; | package com.tom_e_white.set_game.train;
/**
* Take the images created by {@link CreateTrainingSetV2} and extract useful features from them.
* The resulting data can be used to train a model for predicting the shapes on a card.
*/
public class CreateTrainingDataV2 {
public static void main(String[] args) throws IOException {
FeatureFinder[] finders = new FeatureFinder[] {
new FindCardColourFeatures(2),
// new FindCardShadingFeatures(),
// new FindCardShapeFeatures()
};
for (FeatureFinder finder : finders) {
List<String> summaries = new ArrayList<>(); | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTrainingSetV2.java
// public class CreateTrainingSetV2 {
// public static void main(String[] args) throws IOException {
// if (!RAW_LABELLED_DIRECTORY.exists()) {
// CardDetector cardDetector = new CardDetector(4, 66);
// File outDir = RAW_LABELLED_DIRECTORY;
// outDir.mkdirs();
// for (File d : RAW_SORTED_DIRECTORY.listFiles((dir, name) -> name.matches("\\d"))) {
// int numberLabel = Integer.valueOf(d.getName());
// for (File file : d.listFiles((dir, name) -> name.matches(".*\\.jpg"))) {
// System.out.println(file);
// List<CardImage> images = cardDetector.detect(file.getAbsolutePath(), false, true, 3, 9);
// int i = 0;
// for (CardImage image : images) {
// Card card = new Card(numberLabel, (i % 9) / 3, i / 9, i % 3);
// File labelledDirectory = new File(outDir, card.getDescription().replace(" ", "-"));
// labelledDirectory.mkdirs();
// File newFile = new File(labelledDirectory, file.getName().replace(".jpg", "_" + numberLabel + "_" + i + ".jpg"));
// UtilImageIO.saveImage(image.getImage(), newFile.getAbsolutePath());
// i++;
// }
// }
// }
// }
//
// ViewLabelledImagesV2.view(RAW_LABELLED_DIRECTORY);
// }
//
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/TrainingDataV2.java
// public interface TrainingDataV2 {
// File RAW_NEW_DIRECTORY = new File("data/train-v2/raw-new");
// File RAW_SORTED_DIRECTORY = new File("data/train-v2/raw-sorted");
// File RAW_LABELLED_DIRECTORY = new File("data/train-v2/raw-labelled");
// File LABELLED_DIRECTORY = new File("data/train-v2/labelled");
// }
// Path: src/main/java/com/tom_e_white/set_game/train/CreateTrainingDataV2.java
import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.preprocess.CreateTrainingSetV2;
import com.tom_e_white.set_game.preprocess.TrainingDataV2;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
package com.tom_e_white.set_game.train;
/**
* Take the images created by {@link CreateTrainingSetV2} and extract useful features from them.
* The resulting data can be used to train a model for predicting the shapes on a card.
*/
public class CreateTrainingDataV2 {
public static void main(String[] args) throws IOException {
FeatureFinder[] finders = new FeatureFinder[] {
new FindCardColourFeatures(2),
// new FindCardShadingFeatures(),
// new FindCardShapeFeatures()
};
for (FeatureFinder finder : finders) {
List<String> summaries = new ArrayList<>(); | for (File d : TrainingDataV2.LABELLED_DIRECTORY.listFiles((dir, name) -> !name.matches("\\..*"))) { |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/preprocess/SortRawTrainingImagesV2.java | // Path: src/main/java/com/tom_e_white/set_game/train/FindCardNumberFeatures.java
// public class FindCardNumberFeatures extends FeatureFinder {
//
// @Override
// public int getLabelFromFilename(String filename) {
// return Card.Number.parseFilename(new File(filename)).ordinal();
// }
//
// @Override
// public int getLabelFromDescription(String description) {
// return Card.Number.parseDescription(description).ordinal();
// }
//
// @Override
// public double[] find(BufferedImage image, boolean debug) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Shape> shapes = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(3) // this is fairly critical
// .edges()
// .dilate()
// .contours()
// .polygons(0.05, 0.05)
// .getExternalShapes();
//
// int expectedWidth = 40 * 3; // 40mm
// int expectedHeight = 20 * 3; // 20mm
// int tolerancePct = 40;
// List<Shape> filtered = GeometryUtils.filterByArea(shapes, expectedWidth, expectedHeight, tolerancePct);
// List<Shape> nonOverlapping = GeometryUtils.filterNonOverlappingBoundingBoxes(filtered);
//
// if (debug) {
// System.out.println(shapes);
// System.out.println(filtered);
// System.out.println(nonOverlapping);
// ShowImages.showWindow(panel, "Binary Operations", true);
// }
// return new double[] { nonOverlapping.size() % 3 }; // just return as an int mod 3
// }
//
// @Override
// public String getFileSuffix() {
// return "number.csv";
// }
//
// @Override
// public Classifier<double[]> getClassifier() throws IOException, ParseException {
// return doubles -> ((int) doubles[0]) % 3; // just return as an int mod 3
// }
//
// public static void main(String[] args) throws IOException {
// BufferedImage image = UtilImageIO.loadImage(args[0]);
// FindCardNumberFeatures featureFinder = new FindCardNumberFeatures();
// double[] features = featureFinder.find(image, true);
// System.out.println(featureFinder.getSummaryLine(args[0], features));
// }
//
// }
| import com.tom_e_white.set_game.train.FindCardNumberFeatures;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import static com.tom_e_white.set_game.preprocess.TrainingDataV2.RAW_NEW_DIRECTORY;
import static com.tom_e_white.set_game.preprocess.TrainingDataV2.RAW_SORTED_DIRECTORY; | package com.tom_e_white.set_game.preprocess;
/**
* Uses {@link FindCardNumberFeatures} to sort the raw training images by the number of shapes on each card (board).
* Images are moved to <i>raw-sorted/<num<gt;</i> directories, where they can be visually checked by a human.
*/
public class SortRawTrainingImagesV2 {
public static void main(String[] args) throws IOException {
RAW_SORTED_DIRECTORY.mkdirs(); | // Path: src/main/java/com/tom_e_white/set_game/train/FindCardNumberFeatures.java
// public class FindCardNumberFeatures extends FeatureFinder {
//
// @Override
// public int getLabelFromFilename(String filename) {
// return Card.Number.parseFilename(new File(filename)).ordinal();
// }
//
// @Override
// public int getLabelFromDescription(String description) {
// return Card.Number.parseDescription(description).ordinal();
// }
//
// @Override
// public double[] find(BufferedImage image, boolean debug) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Shape> shapes = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(3) // this is fairly critical
// .edges()
// .dilate()
// .contours()
// .polygons(0.05, 0.05)
// .getExternalShapes();
//
// int expectedWidth = 40 * 3; // 40mm
// int expectedHeight = 20 * 3; // 20mm
// int tolerancePct = 40;
// List<Shape> filtered = GeometryUtils.filterByArea(shapes, expectedWidth, expectedHeight, tolerancePct);
// List<Shape> nonOverlapping = GeometryUtils.filterNonOverlappingBoundingBoxes(filtered);
//
// if (debug) {
// System.out.println(shapes);
// System.out.println(filtered);
// System.out.println(nonOverlapping);
// ShowImages.showWindow(panel, "Binary Operations", true);
// }
// return new double[] { nonOverlapping.size() % 3 }; // just return as an int mod 3
// }
//
// @Override
// public String getFileSuffix() {
// return "number.csv";
// }
//
// @Override
// public Classifier<double[]> getClassifier() throws IOException, ParseException {
// return doubles -> ((int) doubles[0]) % 3; // just return as an int mod 3
// }
//
// public static void main(String[] args) throws IOException {
// BufferedImage image = UtilImageIO.loadImage(args[0]);
// FindCardNumberFeatures featureFinder = new FindCardNumberFeatures();
// double[] features = featureFinder.find(image, true);
// System.out.println(featureFinder.getSummaryLine(args[0], features));
// }
//
// }
// Path: src/main/java/com/tom_e_white/set_game/preprocess/SortRawTrainingImagesV2.java
import com.tom_e_white.set_game.train.FindCardNumberFeatures;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.*;
import static com.tom_e_white.set_game.preprocess.TrainingDataV2.RAW_NEW_DIRECTORY;
import static com.tom_e_white.set_game.preprocess.TrainingDataV2.RAW_SORTED_DIRECTORY;
package com.tom_e_white.set_game.preprocess;
/**
* Uses {@link FindCardNumberFeatures} to sort the raw training images by the number of shapes on each card (board).
* Images are moved to <i>raw-sorted/<num<gt;</i> directories, where they can be visually checked by a human.
*/
public class SortRawTrainingImagesV2 {
public static void main(String[] args) throws IOException {
RAW_SORTED_DIRECTORY.mkdirs(); | FindCardNumberFeatures cardFeatureCounter = new FindCardNumberFeatures(); |
tomwhite/set-game | src/test/java/com/tom_e_white/set_game/predict/PredictCardFeaturesOnTestDataTest.java | // Path: src/main/java/com/tom_e_white/set_game/predict/PredictCardFeaturesOnTestData.java
// public class PredictCardFeaturesOnTestData {
//
// public static double[] predict(File testFile) throws IOException, ParseException {
// return predict(testFile, 1);
// }
//
// public static double[] predict(File testFile, int version) throws IOException, ParseException {
//
// FeatureFinder[] finders = new FeatureFinder[] {
// new FindCardNumberFeatures(),
// new FindCardColourFeatures(version),
// new FindCardShadingFeatures(),
// new FindCardShapeFeatures()
// };
// double[] accuracies = new double[finders.length];
// int index = 0;
// for (FeatureFinder finder : finders) {
// System.out.println(finder.getClass().getSimpleName());
//
// Classifier<double[]> classifier = finder.getClassifier();
//
// CardDetector cardDetector = new CardDetector();
// List<CardImage> images = cardDetector.detect(testFile.getAbsolutePath(), false);
// List<String> testDescriptions = Files.lines(Paths.get(testFile.getAbsolutePath().replace(".jpg", ".txt"))).collect(Collectors.toList());
//
// int correct = 0;
// int total = 0;
// for (int i = 0; i < testDescriptions.size(); i++) {
// double[] features = finder.find(images.get(i).getImage(), false);
// int predictedLabel = classifier.predict(features);
// int actualLabel = finder.getLabelFromDescription(testDescriptions.get(i));
// if (predictedLabel == actualLabel) {
// correct++;
// } else {
// System.out.println("Incorrect, predicted " + predictedLabel + " but was " + actualLabel + " for card " + (i + 1));
// }
// total++;
// }
// System.out.println("Correct: " + correct);
// System.out.println("Total: " + total);
// double accuracy = ((double) correct)/total * 100;
// accuracies[index++] = accuracy;
// System.out.println("Accuracy: " + ((int) accuracy) + " percent");
// System.out.println("------------------------------------------");
// }
// return accuracies;
// }
//
// public static void main(String[] args) throws Exception {
// int version = args.length > 1 ? Integer.parseInt(args[1]) : 1;
// predict(new File(args[0]), version);
//
// }
// }
| import com.tom_e_white.set_game.predict.PredictCardFeaturesOnTestData;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import static org.junit.Assert.assertArrayEquals; | package com.tom_e_white.set_game.predict;
public class PredictCardFeaturesOnTestDataTest {
@Test
public void testV1() throws IOException, ParseException { | // Path: src/main/java/com/tom_e_white/set_game/predict/PredictCardFeaturesOnTestData.java
// public class PredictCardFeaturesOnTestData {
//
// public static double[] predict(File testFile) throws IOException, ParseException {
// return predict(testFile, 1);
// }
//
// public static double[] predict(File testFile, int version) throws IOException, ParseException {
//
// FeatureFinder[] finders = new FeatureFinder[] {
// new FindCardNumberFeatures(),
// new FindCardColourFeatures(version),
// new FindCardShadingFeatures(),
// new FindCardShapeFeatures()
// };
// double[] accuracies = new double[finders.length];
// int index = 0;
// for (FeatureFinder finder : finders) {
// System.out.println(finder.getClass().getSimpleName());
//
// Classifier<double[]> classifier = finder.getClassifier();
//
// CardDetector cardDetector = new CardDetector();
// List<CardImage> images = cardDetector.detect(testFile.getAbsolutePath(), false);
// List<String> testDescriptions = Files.lines(Paths.get(testFile.getAbsolutePath().replace(".jpg", ".txt"))).collect(Collectors.toList());
//
// int correct = 0;
// int total = 0;
// for (int i = 0; i < testDescriptions.size(); i++) {
// double[] features = finder.find(images.get(i).getImage(), false);
// int predictedLabel = classifier.predict(features);
// int actualLabel = finder.getLabelFromDescription(testDescriptions.get(i));
// if (predictedLabel == actualLabel) {
// correct++;
// } else {
// System.out.println("Incorrect, predicted " + predictedLabel + " but was " + actualLabel + " for card " + (i + 1));
// }
// total++;
// }
// System.out.println("Correct: " + correct);
// System.out.println("Total: " + total);
// double accuracy = ((double) correct)/total * 100;
// accuracies[index++] = accuracy;
// System.out.println("Accuracy: " + ((int) accuracy) + " percent");
// System.out.println("------------------------------------------");
// }
// return accuracies;
// }
//
// public static void main(String[] args) throws Exception {
// int version = args.length > 1 ? Integer.parseInt(args[1]) : 1;
// predict(new File(args[0]), version);
//
// }
// }
// Path: src/test/java/com/tom_e_white/set_game/predict/PredictCardFeaturesOnTestDataTest.java
import com.tom_e_white.set_game.predict.PredictCardFeaturesOnTestData;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import static org.junit.Assert.assertArrayEquals;
package com.tom_e_white.set_game.predict;
public class PredictCardFeaturesOnTestDataTest {
@Test
public void testV1() throws IOException, ParseException { | double[] accuracies = PredictCardFeaturesOnTestData.predict(new File("data/20170106_205743.jpg")); |
tomwhite/set-game | src/test/java/com/tom_e_white/set_game/predict/PredictCardNumberOnTrainingDataTest.java | // Path: src/main/java/com/tom_e_white/set_game/predict/PredictCardNumberOnTrainingData.java
// public class PredictCardNumberOnTrainingData {
//
// public static double computeAccuracyOnTrainingData() throws IOException {
// FindCardNumberFeatures cardFeatureCounter = new FindCardNumberFeatures();
// int correct = 0;
// int total = 0;
// for (File file : new File("data/train-out").listFiles((dir, name) -> name.matches(".*\\.jpg"))) {
// System.out.println(file);
// int predictedNumber = (int) cardFeatureCounter.find(UtilImageIO.loadImage(file.getAbsolutePath()), false)[0];
// int actualNumber = cardFeatureCounter.getLabelFromFilename(file.getName());
// if (predictedNumber == actualNumber) {
// correct++;
// } else {
// System.out.println("Incorrect, predicted " + predictedNumber);
// }
// total++;
// }
// System.out.println("Correct: " + correct);
// System.out.println("Total: " + total);
// double accuracy = ((double) correct)/total * 100;
// System.out.println("Accuracy: " + ((int) accuracy) + " percent");
// return accuracy;
// }
// public static void main(String[] args) throws IOException {
// computeAccuracyOnTrainingData();
// }
// }
| import com.tom_e_white.set_game.predict.PredictCardNumberOnTrainingData;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertTrue; | package com.tom_e_white.set_game.predict;
public class PredictCardNumberOnTrainingDataTest {
@Test
public void test() throws IOException { | // Path: src/main/java/com/tom_e_white/set_game/predict/PredictCardNumberOnTrainingData.java
// public class PredictCardNumberOnTrainingData {
//
// public static double computeAccuracyOnTrainingData() throws IOException {
// FindCardNumberFeatures cardFeatureCounter = new FindCardNumberFeatures();
// int correct = 0;
// int total = 0;
// for (File file : new File("data/train-out").listFiles((dir, name) -> name.matches(".*\\.jpg"))) {
// System.out.println(file);
// int predictedNumber = (int) cardFeatureCounter.find(UtilImageIO.loadImage(file.getAbsolutePath()), false)[0];
// int actualNumber = cardFeatureCounter.getLabelFromFilename(file.getName());
// if (predictedNumber == actualNumber) {
// correct++;
// } else {
// System.out.println("Incorrect, predicted " + predictedNumber);
// }
// total++;
// }
// System.out.println("Correct: " + correct);
// System.out.println("Total: " + total);
// double accuracy = ((double) correct)/total * 100;
// System.out.println("Accuracy: " + ((int) accuracy) + " percent");
// return accuracy;
// }
// public static void main(String[] args) throws IOException {
// computeAccuracyOnTrainingData();
// }
// }
// Path: src/test/java/com/tom_e_white/set_game/predict/PredictCardNumberOnTrainingDataTest.java
import com.tom_e_white.set_game.predict.PredictCardNumberOnTrainingData;
import org.junit.Test;
import java.io.IOException;
import static org.junit.Assert.assertTrue;
package com.tom_e_white.set_game.predict;
public class PredictCardNumberOnTrainingDataTest {
@Test
public void test() throws IOException { | double accuracy = PredictCardNumberOnTrainingData.computeAccuracyOnTrainingData(); |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/preprocess/CreateTestSetV2.java | // Path: src/main/java/com/tom_e_white/set_game/model/Card.java
// public class Card {
// // The ordinal values follow "The Joy of Set"
// public enum Number {
// THREE, ONE, TWO; // so that the ordinals make sense (mod 3)
//
// public static Number parseDescription(String description) {
// int num = Integer.parseInt(description.split(" ")[0]);
// return values()[num % 3];
// }
// public static Number parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Color {
// GREEN, PURPLE, RED;
//
// public static Color parseDescription(String description) {
// return valueOf(description.split(" ")[1].toUpperCase());
// }
// public static Color parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shading {
// EMPTY, STRIPED, SOLID;
//
// public static Shading parseDescription(String description) {
// return valueOf(description.split(" ")[2].toUpperCase());
// }
// public static Shading parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shape {
// DIAMOND, OVAL, SQUIGGLE;
//
// public static Shape parseDescription(String description) {
// return valueOf(description.split(" ")[3].toUpperCase().replaceFirst("S$", ""));
// }
// public static Shape parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
//
// private static String toDescription(File file) {
// String reg = "([^-]+)-([^-]+).*(\\d)\\.jpg";
// Pattern pattern = Pattern.compile(reg);
// Matcher matcher = pattern.matcher(file.getName());
// if (matcher.matches()) {
// String colour = matcher.group(1);
// String number = matcher.group(2);
// String index = matcher.group(3);
// return toDescription(Integer.parseInt(number), colour, Integer.parseInt(index));
// }
// throw new IllegalArgumentException("Unrecognized file: " + file);
// }
//
// private static String toDescription(int number, String colour, int index) {
// // order signifies how v1 training data cards were laid out
// // solid, striped, empty
// // oval, diamond, squiggle
// switch (index) {
// case 1: return toDescription(number, colour, Shading.SOLID, Shape.OVAL);
// case 2: return toDescription(number, colour, Shading.SOLID, Shape.DIAMOND);
// case 3: return toDescription(number, colour, Shading.SOLID, Shape.SQUIGGLE);
// case 4: return toDescription(number, colour, Shading.STRIPED, Shape.OVAL);
// case 5: return toDescription(number, colour, Shading.STRIPED, Shape.DIAMOND);
// case 6: return toDescription(number, colour, Shading.STRIPED, Shape.SQUIGGLE);
// case 7: return toDescription(number, colour, Shading.EMPTY, Shape.OVAL);
// case 8: return toDescription(number, colour, Shading.EMPTY, Shape.DIAMOND);
// case 9: return toDescription(number, colour, Shading.EMPTY, Shape.SQUIGGLE);
// default: throw new IllegalArgumentException("Unrecognized index " + index);
// }
// }
//
// private static String toDescription(int number, String colour, Shading shading, Shape shape) {
// String s = number == 1 ? "" : "s";
// return number + " " + colour + " " + shading.name().toLowerCase() + " " + shape.name().toLowerCase() + s;
// }
//
// private final Number number;
// private final Color color;
// private final Shading shading;
// private final Shape shape;
//
// public Card(String description) {
// this.number = Number.parseDescription(description);
// this.color = Color.parseDescription(description);
// this.shading = Shading.parseDescription(description);
// this.shape = Shape.parseDescription(description);
// }
//
// public Card(int numberLabel, int colorLabel, int shadingLabel, int shapeLabel) {
// this.number = Number.values()[numberLabel];
// this.color = Color.values()[colorLabel];
// this.shading = Shading.values()[shadingLabel];
// this.shape = Shape.values()[shapeLabel];
// }
//
// public Number number() { return number; }
// public Color color() { return color; }
// public Shading shading() { return shading; }
// public Shape shape() { return shape; }
//
// public String getDescription() {
// int num = number.ordinal() == 0 ? 3 : number.ordinal();
// return toDescription(num, color.name().toLowerCase(), shading, shape);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Card card = (Card) o;
//
// if (number != card.number) return false;
// if (color != card.color) return false;
// if (shading != card.shading) return false;
// return shape == card.shape;
// }
//
// @Override
// public int hashCode() {
// int result = number.hashCode();
// result = 31 * result + color.hashCode();
// result = 31 * result + shading.hashCode();
// result = 31 * result + shape.hashCode();
// return result;
// }
//
// @Override
// public String toString() {
// return getDescription();
// }
// }
| import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.model.Card;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors; | package com.tom_e_white.set_game.preprocess;
/**
* Takes a test image and a label file (ending in .txt) and creates a directory of test images with the
* corresponding labels.
*/
public class CreateTestSetV2 {
public static void main(String[] args) throws IOException {
File testFile = new File("data/20170106_205743.jpg");
CardDetector cardDetector = new CardDetector();
List<CardImage> images = cardDetector.detect(testFile.getAbsolutePath(), false); | // Path: src/main/java/com/tom_e_white/set_game/model/Card.java
// public class Card {
// // The ordinal values follow "The Joy of Set"
// public enum Number {
// THREE, ONE, TWO; // so that the ordinals make sense (mod 3)
//
// public static Number parseDescription(String description) {
// int num = Integer.parseInt(description.split(" ")[0]);
// return values()[num % 3];
// }
// public static Number parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Color {
// GREEN, PURPLE, RED;
//
// public static Color parseDescription(String description) {
// return valueOf(description.split(" ")[1].toUpperCase());
// }
// public static Color parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shading {
// EMPTY, STRIPED, SOLID;
//
// public static Shading parseDescription(String description) {
// return valueOf(description.split(" ")[2].toUpperCase());
// }
// public static Shading parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
// public enum Shape {
// DIAMOND, OVAL, SQUIGGLE;
//
// public static Shape parseDescription(String description) {
// return valueOf(description.split(" ")[3].toUpperCase().replaceFirst("S$", ""));
// }
// public static Shape parseFilename(File file) {
// return parseDescription(toDescription(file));
// }
// }
//
// private static String toDescription(File file) {
// String reg = "([^-]+)-([^-]+).*(\\d)\\.jpg";
// Pattern pattern = Pattern.compile(reg);
// Matcher matcher = pattern.matcher(file.getName());
// if (matcher.matches()) {
// String colour = matcher.group(1);
// String number = matcher.group(2);
// String index = matcher.group(3);
// return toDescription(Integer.parseInt(number), colour, Integer.parseInt(index));
// }
// throw new IllegalArgumentException("Unrecognized file: " + file);
// }
//
// private static String toDescription(int number, String colour, int index) {
// // order signifies how v1 training data cards were laid out
// // solid, striped, empty
// // oval, diamond, squiggle
// switch (index) {
// case 1: return toDescription(number, colour, Shading.SOLID, Shape.OVAL);
// case 2: return toDescription(number, colour, Shading.SOLID, Shape.DIAMOND);
// case 3: return toDescription(number, colour, Shading.SOLID, Shape.SQUIGGLE);
// case 4: return toDescription(number, colour, Shading.STRIPED, Shape.OVAL);
// case 5: return toDescription(number, colour, Shading.STRIPED, Shape.DIAMOND);
// case 6: return toDescription(number, colour, Shading.STRIPED, Shape.SQUIGGLE);
// case 7: return toDescription(number, colour, Shading.EMPTY, Shape.OVAL);
// case 8: return toDescription(number, colour, Shading.EMPTY, Shape.DIAMOND);
// case 9: return toDescription(number, colour, Shading.EMPTY, Shape.SQUIGGLE);
// default: throw new IllegalArgumentException("Unrecognized index " + index);
// }
// }
//
// private static String toDescription(int number, String colour, Shading shading, Shape shape) {
// String s = number == 1 ? "" : "s";
// return number + " " + colour + " " + shading.name().toLowerCase() + " " + shape.name().toLowerCase() + s;
// }
//
// private final Number number;
// private final Color color;
// private final Shading shading;
// private final Shape shape;
//
// public Card(String description) {
// this.number = Number.parseDescription(description);
// this.color = Color.parseDescription(description);
// this.shading = Shading.parseDescription(description);
// this.shape = Shape.parseDescription(description);
// }
//
// public Card(int numberLabel, int colorLabel, int shadingLabel, int shapeLabel) {
// this.number = Number.values()[numberLabel];
// this.color = Color.values()[colorLabel];
// this.shading = Shading.values()[shadingLabel];
// this.shape = Shape.values()[shapeLabel];
// }
//
// public Number number() { return number; }
// public Color color() { return color; }
// public Shading shading() { return shading; }
// public Shape shape() { return shape; }
//
// public String getDescription() {
// int num = number.ordinal() == 0 ? 3 : number.ordinal();
// return toDescription(num, color.name().toLowerCase(), shading, shape);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Card card = (Card) o;
//
// if (number != card.number) return false;
// if (color != card.color) return false;
// if (shading != card.shading) return false;
// return shape == card.shape;
// }
//
// @Override
// public int hashCode() {
// int result = number.hashCode();
// result = 31 * result + color.hashCode();
// result = 31 * result + shading.hashCode();
// result = 31 * result + shape.hashCode();
// return result;
// }
//
// @Override
// public String toString() {
// return getDescription();
// }
// }
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CreateTestSetV2.java
import boofcv.io.image.UtilImageIO;
import com.tom_e_white.set_game.model.Card;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
package com.tom_e_white.set_game.preprocess;
/**
* Takes a test image and a label file (ending in .txt) and creates a directory of test images with the
* corresponding labels.
*/
public class CreateTestSetV2 {
public static void main(String[] args) throws IOException {
File testFile = new File("data/20170106_205743.jpg");
CardDetector cardDetector = new CardDetector();
List<CardImage> images = cardDetector.detect(testFile.getAbsolutePath(), false); | List<Card> cards = Files.lines(Paths.get(testFile.getAbsolutePath().replace(".jpg", ".txt"))) |
tomwhite/set-game | src/main/java/com/tom_e_white/set_game/predict/PredictCardFeaturesOnTestData.java | // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
| import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import com.tom_e_white.set_game.train.*;
import smile.classification.Classifier;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.List;
import java.util.stream.Collectors; | package com.tom_e_white.set_game.predict;
/**
* Use feature finders to predict the features of each card in the test set.
*/
public class PredictCardFeaturesOnTestData {
public static double[] predict(File testFile) throws IOException, ParseException {
return predict(testFile, 1);
}
public static double[] predict(File testFile, int version) throws IOException, ParseException {
FeatureFinder[] finders = new FeatureFinder[] {
new FindCardNumberFeatures(),
new FindCardColourFeatures(version),
new FindCardShadingFeatures(),
new FindCardShapeFeatures()
};
double[] accuracies = new double[finders.length];
int index = 0;
for (FeatureFinder finder : finders) {
System.out.println(finder.getClass().getSimpleName());
Classifier<double[]> classifier = finder.getClassifier();
| // Path: src/main/java/com/tom_e_white/set_game/preprocess/CardDetector.java
// public class CardDetector {
//
// private final int medianBlur;
// private final int areaTolerancePct;
//
// public CardDetector() {
// this(16, 25);
// }
//
// public CardDetector(int areaTolerancePct) {
// this(-1, areaTolerancePct);
// }
//
// public CardDetector(int medianBlur, int areaTolerancePct) {
// this.medianBlur = medianBlur;
// this.areaTolerancePct = areaTolerancePct;
// }
//
// public List<CardImage> detect(String filename) throws IOException {
// return detect(filename, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug) throws IOException {
// return detect(filename, debug, false);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// return detect(UtilImageIO.loadImage(filename), filename, debug, allowRotated, expectedRows, expectedColumns);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated) throws IOException {
// return detect(image, filename, debug, allowRotated, -1, -1);
// }
//
// public List<CardImage> detect(BufferedImage image, String filename, boolean debug, boolean allowRotated, int expectedRows, int expectedColumns) throws IOException {
// // Based on code from http://boofcv.org/index.php?title=Example_Binary_Image
//
// String imageInfo = filename == null ? image.toString() : filename;
//
// if (!allowRotated && image.getWidth() > image.getHeight()) {
// throw new IllegalArgumentException("Image height must be greater than width: " + imageInfo);
// }
// int medianBlur = this.medianBlur != -1 ? this.medianBlur : Math.max(image.getHeight(), image.getWidth()) / 200; // heuristic
//
// ListDisplayPanel panel = debug ? new ListDisplayPanel() : null;
//
// List<Quadrilateral_F64> quads = ImageProcessingPipeline.fromBufferedImage(image, panel)
// .gray()
// .medianBlur(medianBlur)
// .binarize(0, 255)
// .erode()
// .dilate()
// .contours()
// .polygons(0.05, 0.1)
// .getExternalQuadrilaterals();
//
// // Only include shapes that are within given percentage of the mean area. This filters out image artifacts that
// // happen to be quadrilaterals that are not cards (since they are usually a different size).
// List<Quadrilateral_F64> cards = GeometryUtils.filterByArea(quads, areaTolerancePct);
// List<List<Quadrilateral_F64>> rows = GeometryUtils.sortRowWise(cards);// sort into a stable order
// if (expectedRows != -1 && rows.size() != expectedRows) {
// throw new IllegalArgumentException(String.format("Expected %s rows, but detected %s: %s", expectedRows, rows.size(), imageInfo));
// }
// if (expectedColumns != -1) {
// rows.forEach(row -> {
// if (row.size() != expectedColumns) {
// throw new IllegalArgumentException(String.format("Expected %s columns, but detected %s: %s", expectedColumns, row.size(), imageInfo));
// }
// });
// }
// List<CardImage> cardImages = rows.stream()
// .flatMap(List::stream)
// .map(q -> {
// // Remove perspective distortion
// Planar<GrayF32> output = GeometryUtils.removePerspectiveDistortion(image, q, 57 * 3, 89 * 3); // actual cards measure 57 mm x 89 mm
// BufferedImage im = ConvertBufferedImage.convertTo_F32(output, null, true);
// return new CardImage(im, q);
// }
// ).collect(Collectors.toList());
//
// if (debug) {
// int i = 1;
// for (CardImage card : cardImages) {
// panel.addImage(card.getImage(), "Card " + i++);
// }
// ShowImages.showWindow(panel, getClass().getSimpleName(), true);
// }
//
// return cardImages;
//
// }
//
// public static void main(String[] args) throws IOException {
// new CardDetector(66).detect(args[0], true, true);
// }
// }
//
// Path: src/main/java/com/tom_e_white/set_game/preprocess/CardImage.java
// public class CardImage {
// private final BufferedImage image;
// private final Quadrilateral_F64 externalQuadrilateral;
//
// public CardImage(BufferedImage image, Quadrilateral_F64 externalQuadrilateral) {
// this.image = image;
// this.externalQuadrilateral = externalQuadrilateral;
// }
//
// public BufferedImage getImage() {
// return image;
// }
//
// public Quadrilateral_F64 getExternalQuadrilateral() {
// return externalQuadrilateral;
// }
// }
// Path: src/main/java/com/tom_e_white/set_game/predict/PredictCardFeaturesOnTestData.java
import com.tom_e_white.set_game.preprocess.CardDetector;
import com.tom_e_white.set_game.preprocess.CardImage;
import com.tom_e_white.set_game.train.*;
import smile.classification.Classifier;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.ParseException;
import java.util.List;
import java.util.stream.Collectors;
package com.tom_e_white.set_game.predict;
/**
* Use feature finders to predict the features of each card in the test set.
*/
public class PredictCardFeaturesOnTestData {
public static double[] predict(File testFile) throws IOException, ParseException {
return predict(testFile, 1);
}
public static double[] predict(File testFile, int version) throws IOException, ParseException {
FeatureFinder[] finders = new FeatureFinder[] {
new FindCardNumberFeatures(),
new FindCardColourFeatures(version),
new FindCardShadingFeatures(),
new FindCardShapeFeatures()
};
double[] accuracies = new double[finders.length];
int index = 0;
for (FeatureFinder finder : finders) {
System.out.println(finder.getClass().getSimpleName());
Classifier<double[]> classifier = finder.getClassifier();
| CardDetector cardDetector = new CardDetector(); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/InterpolatorValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.TypeException;
import javafx.animation.Interpolator; | package com.annimon.hotarufx.lib;
public class InterpolatorValue implements Value {
private final Interpolator interpolator;
public InterpolatorValue(Interpolator interpolator) {
this.interpolator = interpolator;
}
public Interpolator getInterpolator() {
return interpolator;
}
@Override
public int type() {
return Types.INTERPOLATOR;
}
@Override
public Object raw() {
return interpolator;
}
@Override
public Number asNumber() { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/InterpolatorValue.java
import com.annimon.hotarufx.exceptions.TypeException;
import javafx.animation.Interpolator;
package com.annimon.hotarufx.lib;
public class InterpolatorValue implements Value {
private final Interpolator interpolator;
public InterpolatorValue(Interpolator interpolator) {
this.interpolator = interpolator;
}
public Interpolator getInterpolator() {
return interpolator;
}
@Override
public int type() {
return Types.INTERPOLATOR;
}
@Override
public Object raw() {
return interpolator;
}
@Override
public Number asNumber() { | throw new TypeException("Cannot cast interpolator to number"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ParseError.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition; | package com.annimon.hotarufx.parser;
public class ParseError {
private final Exception exception; | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ParseError.java
import com.annimon.hotarufx.lexer.SourcePosition;
package com.annimon.hotarufx.parser;
public class ParseError {
private final Exception exception; | private final SourcePosition pos; |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/AssignNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor; | package com.annimon.hotarufx.parser.ast;
public class AssignNode extends ASTNode {
public final Accessible target;
public final Node value;
public AssignNode(Accessible target, Node value) {
this.target = target;
this.value = value;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/AssignNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
package com.annimon.hotarufx.parser.ast;
public class AssignNode extends ASTNode {
public final Accessible target;
public final Node value;
public AssignNode(Accessible target, Node value) {
this.target = target;
this.value = value;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/Parser.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ParseException.java
// public class ParseException extends RuntimeException {
//
// public ParseException() {
// super();
// }
//
// public ParseException(String string) {
// super(string);
// }
//
// public ParseException(String string, SourcePosition pos) {
// super(string + " at " + pos.toString());
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/HotaruTokenId.java
// public enum HotaruTokenId {
//
// NUMBER(Category.NUMBER),
// WORD(Category.IDENTIFIER),
// TEXT(Category.STRING),
//
// TRUE(Category.KEYWORD),
// FALSE(Category.KEYWORD),
// MS(Category.KEYWORD),
// SEC(Category.KEYWORD),
//
// EQ(Category.OPERATOR),
// PLUS(Category.OPERATOR),
// MINUS(Category.OPERATOR),
// LPAREN(Category.OPERATOR),
// RPAREN(Category.OPERATOR),
// LBRACE(Category.OPERATOR),
// RBRACE(Category.OPERATOR),
// LBRACKET(Category.OPERATOR),
// RBRACKET(Category.OPERATOR),
// COLON(Category.OPERATOR),
// COMMA(Category.OPERATOR),
// DOT(Category.OPERATOR),
// AT(Category.OPERATOR),
//
// SINGLE_LINE_COMMENT(Category.COMMENT),
// MULTI_LINE_COMMENT(Category.COMMENT),
//
// WS(Category.WHITESPACE),
// EOF(Category.WHITESPACE);
//
// private enum Category {
// NUMBER, IDENTIFIER, STRING, KEYWORD, OPERATOR, COMMENT, WHITESPACE
// }
//
// private final Category category;
//
// HotaruTokenId(Category category) {
// this.category = category;
// }
//
// public String getPrimaryCategory() {
// return category.name().toLowerCase();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/Token.java
// public class Token {
//
// private final HotaruTokenId type;
// private final String text;
// private final int length;
// private final SourcePosition position;
//
// public Token(HotaruTokenId type, String text, int length, SourcePosition position) {
// this.type = type;
// this.text = text;
// this.length = length;
// this.position = position;
// }
//
// public HotaruTokenId getType() {
// return type;
// }
//
// public String getText() {
// return text;
// }
//
// public int getLength() {
// return length;
// }
//
// public SourcePosition getPosition() {
// return position;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// Token token = (Token) o;
// return length == token.length &&
// type == token.type &&
// Objects.equals(text, token.text) &&
// Objects.equals(position, token.position);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(type, text, length, position);
// }
//
// @Override
// public String toString() {
// return type.name() + " " + position + " " + text;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/BlockNode.java
// public class BlockNode extends ASTNode {
//
// public final List<Node> statements = new ArrayList<>();
//
// public void add(Node node) {
// statements.add(node);
// }
//
// @Override
// public <R, T> R accept(ResultVisitor<R, T> visitor, T t) {
// return visitor.visit(this, t);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/Node.java
// public interface Node {
//
// <R, T> R accept(ResultVisitor<R, T> visitor, T input);
// }
| import com.annimon.hotarufx.exceptions.ParseException;
import com.annimon.hotarufx.lexer.HotaruTokenId;
import com.annimon.hotarufx.lexer.SourcePosition;
import com.annimon.hotarufx.lexer.Token;
import com.annimon.hotarufx.parser.ast.BlockNode;
import com.annimon.hotarufx.parser.ast.Node;
import java.util.List; | package com.annimon.hotarufx.parser;
public abstract class Parser {
private static final Token EOF = new Token(HotaruTokenId.EOF, "", | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ParseException.java
// public class ParseException extends RuntimeException {
//
// public ParseException() {
// super();
// }
//
// public ParseException(String string) {
// super(string);
// }
//
// public ParseException(String string, SourcePosition pos) {
// super(string + " at " + pos.toString());
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/HotaruTokenId.java
// public enum HotaruTokenId {
//
// NUMBER(Category.NUMBER),
// WORD(Category.IDENTIFIER),
// TEXT(Category.STRING),
//
// TRUE(Category.KEYWORD),
// FALSE(Category.KEYWORD),
// MS(Category.KEYWORD),
// SEC(Category.KEYWORD),
//
// EQ(Category.OPERATOR),
// PLUS(Category.OPERATOR),
// MINUS(Category.OPERATOR),
// LPAREN(Category.OPERATOR),
// RPAREN(Category.OPERATOR),
// LBRACE(Category.OPERATOR),
// RBRACE(Category.OPERATOR),
// LBRACKET(Category.OPERATOR),
// RBRACKET(Category.OPERATOR),
// COLON(Category.OPERATOR),
// COMMA(Category.OPERATOR),
// DOT(Category.OPERATOR),
// AT(Category.OPERATOR),
//
// SINGLE_LINE_COMMENT(Category.COMMENT),
// MULTI_LINE_COMMENT(Category.COMMENT),
//
// WS(Category.WHITESPACE),
// EOF(Category.WHITESPACE);
//
// private enum Category {
// NUMBER, IDENTIFIER, STRING, KEYWORD, OPERATOR, COMMENT, WHITESPACE
// }
//
// private final Category category;
//
// HotaruTokenId(Category category) {
// this.category = category;
// }
//
// public String getPrimaryCategory() {
// return category.name().toLowerCase();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/Token.java
// public class Token {
//
// private final HotaruTokenId type;
// private final String text;
// private final int length;
// private final SourcePosition position;
//
// public Token(HotaruTokenId type, String text, int length, SourcePosition position) {
// this.type = type;
// this.text = text;
// this.length = length;
// this.position = position;
// }
//
// public HotaruTokenId getType() {
// return type;
// }
//
// public String getText() {
// return text;
// }
//
// public int getLength() {
// return length;
// }
//
// public SourcePosition getPosition() {
// return position;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// Token token = (Token) o;
// return length == token.length &&
// type == token.type &&
// Objects.equals(text, token.text) &&
// Objects.equals(position, token.position);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(type, text, length, position);
// }
//
// @Override
// public String toString() {
// return type.name() + " " + position + " " + text;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/BlockNode.java
// public class BlockNode extends ASTNode {
//
// public final List<Node> statements = new ArrayList<>();
//
// public void add(Node node) {
// statements.add(node);
// }
//
// @Override
// public <R, T> R accept(ResultVisitor<R, T> visitor, T t) {
// return visitor.visit(this, t);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/Node.java
// public interface Node {
//
// <R, T> R accept(ResultVisitor<R, T> visitor, T input);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/Parser.java
import com.annimon.hotarufx.exceptions.ParseException;
import com.annimon.hotarufx.lexer.HotaruTokenId;
import com.annimon.hotarufx.lexer.SourcePosition;
import com.annimon.hotarufx.lexer.Token;
import com.annimon.hotarufx.parser.ast.BlockNode;
import com.annimon.hotarufx.parser.ast.Node;
import java.util.List;
package com.annimon.hotarufx.parser;
public abstract class Parser {
private static final Token EOF = new Token(HotaruTokenId.EOF, "", | 0, new SourcePosition(-1, -1, -1)); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/Parser.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ParseException.java
// public class ParseException extends RuntimeException {
//
// public ParseException() {
// super();
// }
//
// public ParseException(String string) {
// super(string);
// }
//
// public ParseException(String string, SourcePosition pos) {
// super(string + " at " + pos.toString());
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/HotaruTokenId.java
// public enum HotaruTokenId {
//
// NUMBER(Category.NUMBER),
// WORD(Category.IDENTIFIER),
// TEXT(Category.STRING),
//
// TRUE(Category.KEYWORD),
// FALSE(Category.KEYWORD),
// MS(Category.KEYWORD),
// SEC(Category.KEYWORD),
//
// EQ(Category.OPERATOR),
// PLUS(Category.OPERATOR),
// MINUS(Category.OPERATOR),
// LPAREN(Category.OPERATOR),
// RPAREN(Category.OPERATOR),
// LBRACE(Category.OPERATOR),
// RBRACE(Category.OPERATOR),
// LBRACKET(Category.OPERATOR),
// RBRACKET(Category.OPERATOR),
// COLON(Category.OPERATOR),
// COMMA(Category.OPERATOR),
// DOT(Category.OPERATOR),
// AT(Category.OPERATOR),
//
// SINGLE_LINE_COMMENT(Category.COMMENT),
// MULTI_LINE_COMMENT(Category.COMMENT),
//
// WS(Category.WHITESPACE),
// EOF(Category.WHITESPACE);
//
// private enum Category {
// NUMBER, IDENTIFIER, STRING, KEYWORD, OPERATOR, COMMENT, WHITESPACE
// }
//
// private final Category category;
//
// HotaruTokenId(Category category) {
// this.category = category;
// }
//
// public String getPrimaryCategory() {
// return category.name().toLowerCase();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/Token.java
// public class Token {
//
// private final HotaruTokenId type;
// private final String text;
// private final int length;
// private final SourcePosition position;
//
// public Token(HotaruTokenId type, String text, int length, SourcePosition position) {
// this.type = type;
// this.text = text;
// this.length = length;
// this.position = position;
// }
//
// public HotaruTokenId getType() {
// return type;
// }
//
// public String getText() {
// return text;
// }
//
// public int getLength() {
// return length;
// }
//
// public SourcePosition getPosition() {
// return position;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// Token token = (Token) o;
// return length == token.length &&
// type == token.type &&
// Objects.equals(text, token.text) &&
// Objects.equals(position, token.position);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(type, text, length, position);
// }
//
// @Override
// public String toString() {
// return type.name() + " " + position + " " + text;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/BlockNode.java
// public class BlockNode extends ASTNode {
//
// public final List<Node> statements = new ArrayList<>();
//
// public void add(Node node) {
// statements.add(node);
// }
//
// @Override
// public <R, T> R accept(ResultVisitor<R, T> visitor, T t) {
// return visitor.visit(this, t);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/Node.java
// public interface Node {
//
// <R, T> R accept(ResultVisitor<R, T> visitor, T input);
// }
| import com.annimon.hotarufx.exceptions.ParseException;
import com.annimon.hotarufx.lexer.HotaruTokenId;
import com.annimon.hotarufx.lexer.SourcePosition;
import com.annimon.hotarufx.lexer.Token;
import com.annimon.hotarufx.parser.ast.BlockNode;
import com.annimon.hotarufx.parser.ast.Node;
import java.util.List; | package com.annimon.hotarufx.parser;
public abstract class Parser {
private static final Token EOF = new Token(HotaruTokenId.EOF, "",
0, new SourcePosition(-1, -1, -1));
private final List<Token> tokens;
private final int size;
private final ParseErrors parseErrors; | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ParseException.java
// public class ParseException extends RuntimeException {
//
// public ParseException() {
// super();
// }
//
// public ParseException(String string) {
// super(string);
// }
//
// public ParseException(String string, SourcePosition pos) {
// super(string + " at " + pos.toString());
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/HotaruTokenId.java
// public enum HotaruTokenId {
//
// NUMBER(Category.NUMBER),
// WORD(Category.IDENTIFIER),
// TEXT(Category.STRING),
//
// TRUE(Category.KEYWORD),
// FALSE(Category.KEYWORD),
// MS(Category.KEYWORD),
// SEC(Category.KEYWORD),
//
// EQ(Category.OPERATOR),
// PLUS(Category.OPERATOR),
// MINUS(Category.OPERATOR),
// LPAREN(Category.OPERATOR),
// RPAREN(Category.OPERATOR),
// LBRACE(Category.OPERATOR),
// RBRACE(Category.OPERATOR),
// LBRACKET(Category.OPERATOR),
// RBRACKET(Category.OPERATOR),
// COLON(Category.OPERATOR),
// COMMA(Category.OPERATOR),
// DOT(Category.OPERATOR),
// AT(Category.OPERATOR),
//
// SINGLE_LINE_COMMENT(Category.COMMENT),
// MULTI_LINE_COMMENT(Category.COMMENT),
//
// WS(Category.WHITESPACE),
// EOF(Category.WHITESPACE);
//
// private enum Category {
// NUMBER, IDENTIFIER, STRING, KEYWORD, OPERATOR, COMMENT, WHITESPACE
// }
//
// private final Category category;
//
// HotaruTokenId(Category category) {
// this.category = category;
// }
//
// public String getPrimaryCategory() {
// return category.name().toLowerCase();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lexer/Token.java
// public class Token {
//
// private final HotaruTokenId type;
// private final String text;
// private final int length;
// private final SourcePosition position;
//
// public Token(HotaruTokenId type, String text, int length, SourcePosition position) {
// this.type = type;
// this.text = text;
// this.length = length;
// this.position = position;
// }
//
// public HotaruTokenId getType() {
// return type;
// }
//
// public String getText() {
// return text;
// }
//
// public int getLength() {
// return length;
// }
//
// public SourcePosition getPosition() {
// return position;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// Token token = (Token) o;
// return length == token.length &&
// type == token.type &&
// Objects.equals(text, token.text) &&
// Objects.equals(position, token.position);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(type, text, length, position);
// }
//
// @Override
// public String toString() {
// return type.name() + " " + position + " " + text;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/BlockNode.java
// public class BlockNode extends ASTNode {
//
// public final List<Node> statements = new ArrayList<>();
//
// public void add(Node node) {
// statements.add(node);
// }
//
// @Override
// public <R, T> R accept(ResultVisitor<R, T> visitor, T t) {
// return visitor.visit(this, t);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/Node.java
// public interface Node {
//
// <R, T> R accept(ResultVisitor<R, T> visitor, T input);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/Parser.java
import com.annimon.hotarufx.exceptions.ParseException;
import com.annimon.hotarufx.lexer.HotaruTokenId;
import com.annimon.hotarufx.lexer.SourcePosition;
import com.annimon.hotarufx.lexer.Token;
import com.annimon.hotarufx.parser.ast.BlockNode;
import com.annimon.hotarufx.parser.ast.Node;
import java.util.List;
package com.annimon.hotarufx.parser;
public abstract class Parser {
private static final Token EOF = new Token(HotaruTokenId.EOF, "",
0, new SourcePosition(-1, -1, -1));
private final List<Token> tokens;
private final int size;
private final ParseErrors parseErrors; | private Node parsedNode; |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/VariableNode.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor; | package com.annimon.hotarufx.parser.ast;
public class VariableNode extends ASTNode implements Accessible {
public final String name;
public VariableNode(String name) {
this.name = name;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/VariableNode.java
import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
package com.annimon.hotarufx.parser.ast;
public class VariableNode extends ASTNode implements Accessible {
public final String name;
public VariableNode(String name) {
this.name = name;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/VariableNode.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor; | package com.annimon.hotarufx.parser.ast;
public class VariableNode extends ASTNode implements Accessible {
public final String name;
public VariableNode(String name) {
this.name = name;
}
@Override
public <R, T> R accept(ResultVisitor<R, T> visitor, T input) {
return visitor.visit(this, input);
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/VariableNode.java
import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
package com.annimon.hotarufx.parser.ast;
public class VariableNode extends ASTNode implements Accessible {
public final String name;
public VariableNode(String name) {
this.name = name;
}
@Override
public <R, T> R accept(ResultVisitor<R, T> visitor, T input) {
return visitor.visit(this, input);
}
@Override | public <T> Value get(ResultVisitor<Value, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/visitors/InterpreterVisitor.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/FunctionNotFoundException.java
// public class FunctionNotFoundException extends HotaruRuntimeException {
//
// public FunctionNotFoundException(String name, SourcePosition start, SourcePosition end) {
// super("Function " + name + " does not exists", start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/VariableNotFoundException.java
// public class VariableNotFoundException extends HotaruRuntimeException {
//
// public VariableNotFoundException(String variable, SourcePosition start, SourcePosition end) {
// super("Variable " + variable + " does not exists", start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.FunctionNotFoundException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.exceptions.VariableNotFoundException;
import com.annimon.hotarufx.lib.*;
import com.annimon.hotarufx.parser.ast.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier; | return new ArrayValue(elements);
}
@Override
public Value visit(AssignNode node, Context context) {
final var value = node.value.accept(this, context);
return node.target.set(this, value, context);
}
@Override
public Value visit(BlockNode node, Context context) {
Value last = NumberValue.ZERO;
for (Node statement : node.statements) {
last = statement.accept(this, context);
}
return last;
}
@Override
public Value visit(FunctionNode node, Context context) {
final var value = node.functionNode.accept(this, context);
final Function function;
switch (value.type()) {
case Types.FUNCTION:
function = ((FunctionValue) value).getValue();
break;
default:
final var functionName = value.asString();
function = context.functions().get(functionName);
if (function == null) | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/FunctionNotFoundException.java
// public class FunctionNotFoundException extends HotaruRuntimeException {
//
// public FunctionNotFoundException(String name, SourcePosition start, SourcePosition end) {
// super("Function " + name + " does not exists", start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/VariableNotFoundException.java
// public class VariableNotFoundException extends HotaruRuntimeException {
//
// public VariableNotFoundException(String variable, SourcePosition start, SourcePosition end) {
// super("Variable " + variable + " does not exists", start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/InterpreterVisitor.java
import com.annimon.hotarufx.exceptions.FunctionNotFoundException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.exceptions.VariableNotFoundException;
import com.annimon.hotarufx.lib.*;
import com.annimon.hotarufx.parser.ast.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
return new ArrayValue(elements);
}
@Override
public Value visit(AssignNode node, Context context) {
final var value = node.value.accept(this, context);
return node.target.set(this, value, context);
}
@Override
public Value visit(BlockNode node, Context context) {
Value last = NumberValue.ZERO;
for (Node statement : node.statements) {
last = statement.accept(this, context);
}
return last;
}
@Override
public Value visit(FunctionNode node, Context context) {
final var value = node.functionNode.accept(this, context);
final Function function;
switch (value.type()) {
case Types.FUNCTION:
function = ((FunctionValue) value).getValue();
break;
default:
final var functionName = value.asString();
function = context.functions().get(functionName);
if (function == null) | throw new FunctionNotFoundException(functionName, node.start(), node.end()); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/visitors/InterpreterVisitor.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/FunctionNotFoundException.java
// public class FunctionNotFoundException extends HotaruRuntimeException {
//
// public FunctionNotFoundException(String name, SourcePosition start, SourcePosition end) {
// super("Function " + name + " does not exists", start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/VariableNotFoundException.java
// public class VariableNotFoundException extends HotaruRuntimeException {
//
// public VariableNotFoundException(String variable, SourcePosition start, SourcePosition end) {
// super("Variable " + variable + " does not exists", start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.FunctionNotFoundException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.exceptions.VariableNotFoundException;
import com.annimon.hotarufx.lib.*;
import com.annimon.hotarufx.parser.ast.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier; | switch (value.type()) {
case Types.FUNCTION:
function = ((FunctionValue) value).getValue();
break;
default:
final var functionName = value.asString();
function = context.functions().get(functionName);
if (function == null)
throw new FunctionNotFoundException(functionName, node.start(), node.end());
break;
}
final var args = node.arguments.stream()
.map(n -> n.accept(this, context))
.toArray(Value[]::new);
return function.execute(args);
}
@Override
public Value visit(MapNode node, Context context) {
Map<String, Value> map = new HashMap<>(node.elements.size());
for (Map.Entry<String, Node> entry : node.elements.entrySet()) {
map.put(entry.getKey(), entry.getValue().accept(this, context));
}
return new MapValue(map);
}
@Override
public Value visit(PropertyNode node, Context context) {
final var value = node.node.accept(this, context);
if (value.type() != Types.NODE) { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/FunctionNotFoundException.java
// public class FunctionNotFoundException extends HotaruRuntimeException {
//
// public FunctionNotFoundException(String name, SourcePosition start, SourcePosition end) {
// super("Function " + name + " does not exists", start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/VariableNotFoundException.java
// public class VariableNotFoundException extends HotaruRuntimeException {
//
// public VariableNotFoundException(String variable, SourcePosition start, SourcePosition end) {
// super("Variable " + variable + " does not exists", start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/InterpreterVisitor.java
import com.annimon.hotarufx.exceptions.FunctionNotFoundException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.exceptions.VariableNotFoundException;
import com.annimon.hotarufx.lib.*;
import com.annimon.hotarufx.parser.ast.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
switch (value.type()) {
case Types.FUNCTION:
function = ((FunctionValue) value).getValue();
break;
default:
final var functionName = value.asString();
function = context.functions().get(functionName);
if (function == null)
throw new FunctionNotFoundException(functionName, node.start(), node.end());
break;
}
final var args = node.arguments.stream()
.map(n -> n.accept(this, context))
.toArray(Value[]::new);
return function.execute(args);
}
@Override
public Value visit(MapNode node, Context context) {
Map<String, Value> map = new HashMap<>(node.elements.size());
for (Map.Entry<String, Node> entry : node.elements.entrySet()) {
map.put(entry.getKey(), entry.getValue().accept(this, context));
}
return new MapValue(map);
}
@Override
public Value visit(PropertyNode node, Context context) {
final var value = node.node.accept(this, context);
if (value.type() != Types.NODE) { | throw new TypeException("Node value expected"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/visitors/InterpreterVisitor.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/FunctionNotFoundException.java
// public class FunctionNotFoundException extends HotaruRuntimeException {
//
// public FunctionNotFoundException(String name, SourcePosition start, SourcePosition end) {
// super("Function " + name + " does not exists", start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/VariableNotFoundException.java
// public class VariableNotFoundException extends HotaruRuntimeException {
//
// public VariableNotFoundException(String variable, SourcePosition start, SourcePosition end) {
// super("Variable " + variable + " does not exists", start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.FunctionNotFoundException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.exceptions.VariableNotFoundException;
import com.annimon.hotarufx.lib.*;
import com.annimon.hotarufx.parser.ast.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier; | private Optional<Value> getContainer(List<Node> nodes, Context context, Value container) {
for (Node index : nodes) {
switch (container.type()) {
case Types.MAP: {
final var key = index.accept(this, context).asString();
container = ((MapValue) container).getMap().get(key);
} break;
case Types.NODE: {
final var key = index.accept(this, context).asString();
container = ((NodeValue) container).get(key);
} break;
case Types.PROPERTY: {
final var key = index.accept(this, context).asString();
final var propertyValue = (PropertyValue) container;
container = propertyValue.getField(key);
} break;
default:
return Optional.empty();
}
}
return Optional.of(container);
}
@Override
public Value get(VariableNode node, Context context) {
final var result = context.variables().get(node.name);
if (result == null) | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/FunctionNotFoundException.java
// public class FunctionNotFoundException extends HotaruRuntimeException {
//
// public FunctionNotFoundException(String name, SourcePosition start, SourcePosition end) {
// super("Function " + name + " does not exists", start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/VariableNotFoundException.java
// public class VariableNotFoundException extends HotaruRuntimeException {
//
// public VariableNotFoundException(String variable, SourcePosition start, SourcePosition end) {
// super("Variable " + variable + " does not exists", start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/InterpreterVisitor.java
import com.annimon.hotarufx.exceptions.FunctionNotFoundException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.exceptions.VariableNotFoundException;
import com.annimon.hotarufx.lib.*;
import com.annimon.hotarufx.parser.ast.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
private Optional<Value> getContainer(List<Node> nodes, Context context, Value container) {
for (Node index : nodes) {
switch (container.type()) {
case Types.MAP: {
final var key = index.accept(this, context).asString();
container = ((MapValue) container).getMap().get(key);
} break;
case Types.NODE: {
final var key = index.accept(this, context).asString();
container = ((NodeValue) container).get(key);
} break;
case Types.PROPERTY: {
final var key = index.accept(this, context).asString();
final var propertyValue = (PropertyValue) container;
container = propertyValue.getField(key);
} break;
default:
return Optional.empty();
}
}
return Optional.of(container);
}
@Override
public Value get(VariableNode node, Context context) {
final var result = context.variables().get(node.name);
if (result == null) | throw new VariableNotFoundException(node.name, node.start(), node.end()); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ParseErrors.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream; | package com.annimon.hotarufx.parser;
public class ParseErrors implements Iterable<ParseError> {
private final List<ParseError> errors;
public ParseErrors() {
errors = new ArrayList<>();
}
public void clear() {
errors.clear();
}
| // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ParseErrors.java
import com.annimon.hotarufx.lexer.SourcePosition;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Stream;
package com.annimon.hotarufx.parser;
public class ParseErrors implements Iterable<ParseError> {
private final List<ParseError> errors;
public ParseErrors() {
errors = new ArrayList<>();
}
public void clear() {
errors.clear();
}
| public void add(Exception ex, SourcePosition pos) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/exceptions/LexerException.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition; | package com.annimon.hotarufx.exceptions;
public class LexerException extends RuntimeException {
public LexerException(String message) {
super(message);
}
| // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/LexerException.java
import com.annimon.hotarufx.lexer.SourcePosition;
package com.annimon.hotarufx.exceptions;
public class LexerException extends RuntimeException {
public LexerException(String message) {
super(message);
}
| public LexerException(SourcePosition position, String message) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/exceptions/ArgumentsMismatchException.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition; | package com.annimon.hotarufx.exceptions;
public class ArgumentsMismatchException extends HotaruRuntimeException {
public ArgumentsMismatchException(String message) {
super(message);
}
| // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/ArgumentsMismatchException.java
import com.annimon.hotarufx.lexer.SourcePosition;
package com.annimon.hotarufx.exceptions;
public class ArgumentsMismatchException extends HotaruRuntimeException {
public ArgumentsMismatchException(String message) {
super(message);
}
| public ArgumentsMismatchException(String message, SourcePosition start, SourcePosition end) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/MapNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.Map; | package com.annimon.hotarufx.parser.ast;
public class MapNode extends ASTNode {
public final Map<String, Node> elements;
public MapNode(Map<String, Node> elements) {
this.elements = elements;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/MapNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.Map;
package com.annimon.hotarufx.parser.ast;
public class MapNode extends ASTNode {
public final Map<String, Node> elements;
public MapNode(Map<String, Node> elements) {
this.elements = elements;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/UnitNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor; | package com.annimon.hotarufx.parser.ast;
public class UnitNode extends ASTNode {
public enum Unit {MILLISECONDS, SECONDS};
public final Node value;
public final Unit operator;
public UnitNode(Node value, Unit operator) {
this.value = value;
this.operator = operator;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/UnitNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
package com.annimon.hotarufx.parser.ast;
public class UnitNode extends ASTNode {
public enum Unit {MILLISECONDS, SECONDS};
public final Node value;
public final Unit operator;
public UnitNode(Node value, Unit operator) {
this.value = value;
this.operator = operator;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/AccessNode.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.List; | package com.annimon.hotarufx.parser.ast;
public class AccessNode extends ASTNode implements Accessible {
public final Node root;
public final List<Node> indices;
public AccessNode(Node root, List<Node> indices) {
this.root = root;
this.indices = indices;
}
public AccessNode(String variable, List<Node> indices) {
this(new VariableNode(variable), indices);
}
public Node getRoot() {
return root;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/AccessNode.java
import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.List;
package com.annimon.hotarufx.parser.ast;
public class AccessNode extends ASTNode implements Accessible {
public final Node root;
public final List<Node> indices;
public AccessNode(Node root, List<Node> indices) {
this.root = root;
this.indices = indices;
}
public AccessNode(String variable, List<Node> indices) {
this(new VariableNode(variable), indices);
}
public Node getRoot() {
return root;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/AccessNode.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.List; | package com.annimon.hotarufx.parser.ast;
public class AccessNode extends ASTNode implements Accessible {
public final Node root;
public final List<Node> indices;
public AccessNode(Node root, List<Node> indices) {
this.root = root;
this.indices = indices;
}
public AccessNode(String variable, List<Node> indices) {
this(new VariableNode(variable), indices);
}
public Node getRoot() {
return root;
}
@Override
public <R, T> R accept(ResultVisitor<R, T> visitor, T input) {
return visitor.visit(this, input);
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/AccessNode.java
import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.List;
package com.annimon.hotarufx.parser.ast;
public class AccessNode extends ASTNode implements Accessible {
public final Node root;
public final List<Node> indices;
public AccessNode(Node root, List<Node> indices) {
this.root = root;
this.indices = indices;
}
public AccessNode(String variable, List<Node> indices) {
this(new VariableNode(variable), indices);
}
public Node getRoot() {
return root;
}
@Override
public <R, T> R accept(ResultVisitor<R, T> visitor, T input) {
return visitor.visit(this, input);
}
@Override | public <T> Value get(ResultVisitor<Value, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/Validator.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ArgumentsMismatchException.java
// public class ArgumentsMismatchException extends HotaruRuntimeException {
//
// public ArgumentsMismatchException(String message) {
// super(message);
// }
//
// public ArgumentsMismatchException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.ArgumentsMismatchException;
import com.annimon.hotarufx.exceptions.TypeException; | package com.annimon.hotarufx.lib;
public class Validator {
public static Validator with(Value[] args) {
return new Validator(args);
}
private final Value[] args;
private Validator(Value[] args) {
this.args = args;
}
public Validator check(int expected) { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ArgumentsMismatchException.java
// public class ArgumentsMismatchException extends HotaruRuntimeException {
//
// public ArgumentsMismatchException(String message) {
// super(message);
// }
//
// public ArgumentsMismatchException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/Validator.java
import com.annimon.hotarufx.exceptions.ArgumentsMismatchException;
import com.annimon.hotarufx.exceptions.TypeException;
package com.annimon.hotarufx.lib;
public class Validator {
public static Validator with(Value[] args) {
return new Validator(args);
}
private final Value[] args;
private Validator(Value[] args) {
this.args = args;
}
public Validator check(int expected) { | if (args.length != expected) throw new ArgumentsMismatchException(String.format( |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/Validator.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ArgumentsMismatchException.java
// public class ArgumentsMismatchException extends HotaruRuntimeException {
//
// public ArgumentsMismatchException(String message) {
// super(message);
// }
//
// public ArgumentsMismatchException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.ArgumentsMismatchException;
import com.annimon.hotarufx.exceptions.TypeException; | public Validator check(int expected) {
if (args.length != expected) throw new ArgumentsMismatchException(String.format(
"%d %s expected, got %d", expected, pluralize(expected), args.length));
return this;
}
public Validator checkAtLeast(int expected) {
if (args.length < expected) throw new ArgumentsMismatchException(String.format(
"At least %d %s expected, got %d", expected, pluralize(expected), args.length));
return this;
}
public Validator checkOrOr(int expectedOne, int expectedTwo) {
if (expectedOne != args.length && expectedTwo != args.length)
throw new ArgumentsMismatchException(String.format(
"%d or %d arguments expected, got %d", expectedOne, expectedTwo, args.length));
return this;
}
public Validator checkRange(int from, int to) {
if (from > args.length || args.length > to)
throw new ArgumentsMismatchException(String.format(
"From %d to %d arguments expected, got %d", from, to, args.length));
return this;
}
public ArrayValue requireArrayAt(int index) {
checkAtLeast(index + 1);
final var value = args[index];
if (value.type() != Types.ARRAY) { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/ArgumentsMismatchException.java
// public class ArgumentsMismatchException extends HotaruRuntimeException {
//
// public ArgumentsMismatchException(String message) {
// super(message);
// }
//
// public ArgumentsMismatchException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/Validator.java
import com.annimon.hotarufx.exceptions.ArgumentsMismatchException;
import com.annimon.hotarufx.exceptions.TypeException;
public Validator check(int expected) {
if (args.length != expected) throw new ArgumentsMismatchException(String.format(
"%d %s expected, got %d", expected, pluralize(expected), args.length));
return this;
}
public Validator checkAtLeast(int expected) {
if (args.length < expected) throw new ArgumentsMismatchException(String.format(
"At least %d %s expected, got %d", expected, pluralize(expected), args.length));
return this;
}
public Validator checkOrOr(int expectedOne, int expectedTwo) {
if (expectedOne != args.length && expectedTwo != args.length)
throw new ArgumentsMismatchException(String.format(
"%d or %d arguments expected, got %d", expectedOne, expectedTwo, args.length));
return this;
}
public Validator checkRange(int from, int to) {
if (from > args.length || args.length > to)
throw new ArgumentsMismatchException(String.format(
"From %d to %d arguments expected, got %d", from, to, args.length));
return this;
}
public ArrayValue requireArrayAt(int index) {
checkAtLeast(index + 1);
final var value = args[index];
if (value.type() != Types.ARRAY) { | throw new TypeException(String.format("Array required at %d argument", index)); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/visual/objects/PolygonNode.java | // Path: app/src/main/java/com/annimon/hotarufx/visual/visitors/NodeVisitor.java
// public interface NodeVisitor<R, T> {
//
// R visit(ArcNode node, T input);
// R visit(CircleNode node, T input);
// R visit(EllipseNode node, T input);
// R visit(GroupNode node, T input);
// R visit(ImageNode node, T input);
// R visit(LineNode node, T input);
// R visit(PolygonNode node, T input);
// R visit(PolylineNode node, T input);
// R visit(RectangleNode node, T input);
// R visit(SVGPathNode node, T input);
// R visit(TextNode node, T input);
// }
| import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import java.util.List;
import javafx.scene.shape.Polygon; | package com.annimon.hotarufx.visual.objects;
public class PolygonNode extends ShapeNode {
public final Polygon polygon;
public PolygonNode(List<Double> points) {
this(new Polygon(), points);
}
private PolygonNode(Polygon polygon, List<Double> points) {
super(polygon);
this.polygon = polygon;
polygon.getPoints().addAll(points);
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/visual/visitors/NodeVisitor.java
// public interface NodeVisitor<R, T> {
//
// R visit(ArcNode node, T input);
// R visit(CircleNode node, T input);
// R visit(EllipseNode node, T input);
// R visit(GroupNode node, T input);
// R visit(ImageNode node, T input);
// R visit(LineNode node, T input);
// R visit(PolygonNode node, T input);
// R visit(PolylineNode node, T input);
// R visit(RectangleNode node, T input);
// R visit(SVGPathNode node, T input);
// R visit(TextNode node, T input);
// }
// Path: app/src/main/java/com/annimon/hotarufx/visual/objects/PolygonNode.java
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import java.util.List;
import javafx.scene.shape.Polygon;
package com.annimon.hotarufx.visual.objects;
public class PolygonNode extends ShapeNode {
public final Polygon polygon;
public PolygonNode(List<Double> points) {
this(new Polygon(), points);
}
private PolygonNode(Polygon polygon, List<Double> points) {
super(polygon);
this.polygon = polygon;
polygon.getPoints().addAll(points);
}
@Override | public <R, T> R accept(NodeVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function; | package com.annimon.hotarufx.bundles;
public class FunctionInfo {
public static FunctionInfo of(FunctionType type, Function function) { | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
package com.annimon.hotarufx.bundles;
public class FunctionInfo {
public static FunctionInfo of(FunctionType type, Function function) { | return of(type, (Context c) -> function); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/visual/objects/PolylineNode.java | // Path: app/src/main/java/com/annimon/hotarufx/visual/visitors/NodeVisitor.java
// public interface NodeVisitor<R, T> {
//
// R visit(ArcNode node, T input);
// R visit(CircleNode node, T input);
// R visit(EllipseNode node, T input);
// R visit(GroupNode node, T input);
// R visit(ImageNode node, T input);
// R visit(LineNode node, T input);
// R visit(PolygonNode node, T input);
// R visit(PolylineNode node, T input);
// R visit(RectangleNode node, T input);
// R visit(SVGPathNode node, T input);
// R visit(TextNode node, T input);
// }
| import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import java.util.List;
import javafx.scene.shape.Polyline; | package com.annimon.hotarufx.visual.objects;
public class PolylineNode extends ShapeNode {
public final Polyline polyline;
public PolylineNode(List<Double> points) {
this(new Polyline(), points);
}
private PolylineNode(Polyline polyline, List<Double> points) {
super(polyline);
this.polyline = polyline;
polyline.getPoints().addAll(points);
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/visual/visitors/NodeVisitor.java
// public interface NodeVisitor<R, T> {
//
// R visit(ArcNode node, T input);
// R visit(CircleNode node, T input);
// R visit(EllipseNode node, T input);
// R visit(GroupNode node, T input);
// R visit(ImageNode node, T input);
// R visit(LineNode node, T input);
// R visit(PolygonNode node, T input);
// R visit(PolylineNode node, T input);
// R visit(RectangleNode node, T input);
// R visit(SVGPathNode node, T input);
// R visit(TextNode node, T input);
// }
// Path: app/src/main/java/com/annimon/hotarufx/visual/objects/PolylineNode.java
import com.annimon.hotarufx.visual.visitors.NodeVisitor;
import java.util.List;
import javafx.scene.shape.Polyline;
package com.annimon.hotarufx.visual.objects;
public class PolylineNode extends ShapeNode {
public final Polyline polyline;
public PolylineNode(List<Double> points) {
this(new Polyline(), points);
}
private PolylineNode(Polyline polyline, List<Double> points) {
super(polyline);
this.polyline = polyline;
polyline.getPoints().addAll(points);
}
@Override | public <R, T> R accept(NodeVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/BlockNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.ArrayList;
import java.util.List; | package com.annimon.hotarufx.parser.ast;
public class BlockNode extends ASTNode {
public final List<Node> statements = new ArrayList<>();
public void add(Node node) {
statements.add(node);
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/BlockNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.ArrayList;
import java.util.List;
package com.annimon.hotarufx.parser.ast;
public class BlockNode extends ASTNode {
public final List<Node> statements = new ArrayList<>();
public void add(Node node) {
statements.add(node);
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T t) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/visual/Composition.java | // Path: app/src/main/java/com/annimon/hotarufx/ui/control/NodesGroup.java
// public class NodesGroup extends Group {
//
// private final double width, height;
//
// public NodesGroup(double width, double height) {
// this.width = width;
// this.height = height;
// setAutoSizeChildren(false);
// setManaged(false);
// }
//
// @Override
// public ObservableList<Node> getChildren() {
// return super.getChildren();
// }
//
// @Override
// public double prefWidth(double unused) {
// return width;
// }
//
// @Override
// public double prefHeight(double unused) {
// return height;
// }
//
// @Override
// protected double computePrefWidth(double unused) {
// return width;
// }
//
// @Override
// protected double computePrefHeight(double unused) {
// return height;
// }
//
// @Override
// public boolean isResizable() {
// return false;
// }
// }
| import com.annimon.hotarufx.ui.control.NodesGroup;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint; |
public int getVirtualHeight() {
return virtualHeight;
}
public int getSceneWidth() {
return sceneWidth;
}
public int getSceneHeight() {
return sceneHeight;
}
public double getFactor() {
return factor;
}
public TimeLine getTimeline() {
return timeline;
}
public VirtualScene getScene() {
return scene;
}
public Paint getBackground() {
return background;
}
private VirtualScene newScene() { | // Path: app/src/main/java/com/annimon/hotarufx/ui/control/NodesGroup.java
// public class NodesGroup extends Group {
//
// private final double width, height;
//
// public NodesGroup(double width, double height) {
// this.width = width;
// this.height = height;
// setAutoSizeChildren(false);
// setManaged(false);
// }
//
// @Override
// public ObservableList<Node> getChildren() {
// return super.getChildren();
// }
//
// @Override
// public double prefWidth(double unused) {
// return width;
// }
//
// @Override
// public double prefHeight(double unused) {
// return height;
// }
//
// @Override
// protected double computePrefWidth(double unused) {
// return width;
// }
//
// @Override
// protected double computePrefHeight(double unused) {
// return height;
// }
//
// @Override
// public boolean isResizable() {
// return false;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
import com.annimon.hotarufx.ui.control.NodesGroup;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
public int getVirtualHeight() {
return virtualHeight;
}
public int getSceneWidth() {
return sceneWidth;
}
public int getSceneHeight() {
return sceneHeight;
}
public double getFactor() {
return factor;
}
public TimeLine getTimeline() {
return timeline;
}
public VirtualScene getScene() {
return scene;
}
public Paint getBackground() {
return background;
}
private VirtualScene newScene() { | final var group = new NodesGroup(sceneWidth, sceneHeight); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition; | package com.annimon.hotarufx.exceptions;
public class HotaruRuntimeException extends RuntimeException {
public HotaruRuntimeException(String s) {
super(s);
}
| // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
import com.annimon.hotarufx.lexer.SourcePosition;
package com.annimon.hotarufx.exceptions;
public class HotaruRuntimeException extends RuntimeException {
public HotaruRuntimeException(String s) {
super(s);
}
| public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/PropertyNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor; | package com.annimon.hotarufx.parser.ast;
public class PropertyNode extends ASTNode {
public final Node node;
public final String property;
public PropertyNode(Node node, String property) {
this.node = node;
this.property = property;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/PropertyNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
package com.annimon.hotarufx.parser.ast;
public class PropertyNode extends ASTNode {
public final Node node;
public final String property;
public PropertyNode(Node node, String property) {
this.node = node;
this.property = property;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/ArrayValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.TypeException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Stream; | public Value[] getCopyElements() {
final Value[] result = new Value[elements.length];
System.arraycopy(elements, 0, result, 0, elements.length);
return result;
}
@Override
public int type() {
return Types.ARRAY;
}
public int size() {
return elements.length;
}
public Value get(int index) {
return elements[index];
}
public void set(int index, Value value) {
elements[index] = value;
}
@Override
public Object raw() {
return elements;
}
@Override
public Number asNumber() { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/ArrayValue.java
import com.annimon.hotarufx.exceptions.TypeException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Stream;
public Value[] getCopyElements() {
final Value[] result = new Value[elements.length];
System.arraycopy(elements, 0, result, 0, elements.length);
return result;
}
@Override
public int type() {
return Types.ARRAY;
}
public int size() {
return elements.length;
}
public Value get(int index) {
return elements[index];
}
public void set(int index, Value value) {
elements[index] = value;
}
@Override
public Object raw() {
return elements;
}
@Override
public Number asNumber() { | throw new TypeException("Cannot cast array to number"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
| import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.ast.*; | package com.annimon.hotarufx.parser.visitors;
public interface ResultVisitor<R, T> {
R visit(AccessNode node, T t);
R visit(ArrayNode node, T t);
R visit(AssignNode node, T t);
R visit(BlockNode node, T t);
R visit(FunctionNode node, T t);
R visit(MapNode node, T t);
R visit(PropertyNode node, T t);
R visit(UnaryNode node, T t);
R visit(UnitNode node, T t);
R visit(ValueNode node, T t);
R visit(VariableNode node, T t);
| // Path: app/src/main/java/com/annimon/hotarufx/lib/Value.java
// public interface Value extends Comparable<Value> {
//
// Object raw();
//
// default boolean asBoolean() {
// return asInt() != 0;
// }
//
// default int asInt() {
// return asNumber().intValue();
// }
//
// default double asDouble() {
// return asNumber().doubleValue();
// }
//
// Number asNumber();
//
// String asString();
//
// int type();
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
import com.annimon.hotarufx.lib.Value;
import com.annimon.hotarufx.parser.ast.*;
package com.annimon.hotarufx.parser.visitors;
public interface ResultVisitor<R, T> {
R visit(AccessNode node, T t);
R visit(ArrayNode node, T t);
R visit(AssignNode node, T t);
R visit(BlockNode node, T t);
R visit(FunctionNode node, T t);
R visit(MapNode node, T t);
R visit(PropertyNode node, T t);
R visit(UnaryNode node, T t);
R visit(UnitNode node, T t);
R visit(ValueNode node, T t);
R visit(VariableNode node, T t);
| Value get(AccessNode node, T t); |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/bundles/CompositionBundleTest.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.NumberValue;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; | package com.annimon.hotarufx.bundles;
class CompositionBundleTest {
@Test
void testBundle() { | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
// Path: app/src/test/java/com/annimon/hotarufx/bundles/CompositionBundleTest.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.NumberValue;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
package com.annimon.hotarufx.bundles;
class CompositionBundleTest {
@Test
void testBundle() { | final var context = new Context(); |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/bundles/CompositionBundleTest.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.NumberValue;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*; | package com.annimon.hotarufx.bundles;
class CompositionBundleTest {
@Test
void testBundle() {
final var context = new Context();
BundleLoader.loadSingle(context, CompositionBundle.class);
assertThat(context.functions(), hasKey("composition"));
assertThat(context.composition(), nullValue());
assertThat(context.variables(), allOf(
not(hasKey("Width")),
not(hasKey("Height")),
not(hasKey("HalfWidth")),
not(hasKey("HalfHeight"))
));
context.functions().get("composition").execute();
assertThat(context.composition(), notNullValue());
assertThat(context.variables(), allOf( | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
// Path: app/src/test/java/com/annimon/hotarufx/bundles/CompositionBundleTest.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.NumberValue;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
package com.annimon.hotarufx.bundles;
class CompositionBundleTest {
@Test
void testBundle() {
final var context = new Context();
BundleLoader.loadSingle(context, CompositionBundle.class);
assertThat(context.functions(), hasKey("composition"));
assertThat(context.composition(), nullValue());
assertThat(context.variables(), allOf(
not(hasKey("Width")),
not(hasKey("Height")),
not(hasKey("HalfWidth")),
not(hasKey("HalfHeight"))
));
context.functions().get("composition").execute();
assertThat(context.composition(), notNullValue());
assertThat(context.variables(), allOf( | hasEntry("Width", NumberValue.of(1920)), |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/FunctionValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.TypeException;
import java.util.Objects; | package com.annimon.hotarufx.lib;
public class FunctionValue implements Value {
public static final FunctionValue EMPTY = new FunctionValue(args -> NumberValue.ZERO);
private final Function value;
public FunctionValue(Function value) {
this.value = value;
}
public Function getValue() {
return value;
}
@Override
public int type() {
return Types.FUNCTION;
}
@Override
public Object raw() {
return value;
}
@Override
public Number asNumber() { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/FunctionValue.java
import com.annimon.hotarufx.exceptions.TypeException;
import java.util.Objects;
package com.annimon.hotarufx.lib;
public class FunctionValue implements Value {
public static final FunctionValue EMPTY = new FunctionValue(args -> NumberValue.ZERO);
private final Function value;
public FunctionValue(Function value) {
this.value = value;
}
public Function getValue() {
return value;
}
@Override
public int type() {
return Types.FUNCTION;
}
@Override
public Object raw() {
return value;
}
@Override
public Number asNumber() { | throw new TypeException("Cannot cast function to number"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/exceptions/ParseException.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition; | package com.annimon.hotarufx.exceptions;
public class ParseException extends RuntimeException {
public ParseException() {
super();
}
public ParseException(String string) {
super(string);
}
| // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/ParseException.java
import com.annimon.hotarufx.lexer.SourcePosition;
package com.annimon.hotarufx.exceptions;
public class ParseException extends RuntimeException {
public ParseException() {
super();
}
public ParseException(String string) {
super(string);
}
| public ParseException(String string, SourcePosition pos) { |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON; | package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>(); | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
// Path: app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON;
package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>(); | FUNCTIONS.put("print", of(COMMON, PrintBundle::print)); |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON; | package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
FUNCTIONS.put("print", of(COMMON, PrintBundle::print));
FUNCTIONS.put("println", of(COMMON, PrintBundle::println));
FUNCTIONS.put("dump", of(COMMON, PrintBundle::dump));
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
| // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
// Path: app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON;
package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
FUNCTIONS.put("print", of(COMMON, PrintBundle::print));
FUNCTIONS.put("println", of(COMMON, PrintBundle::println));
FUNCTIONS.put("dump", of(COMMON, PrintBundle::dump));
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
| private static Function print(Context context) { |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON; | package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
FUNCTIONS.put("print", of(COMMON, PrintBundle::print));
FUNCTIONS.put("println", of(COMMON, PrintBundle::println));
FUNCTIONS.put("dump", of(COMMON, PrintBundle::dump));
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
| // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
// Path: app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON;
package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
FUNCTIONS.put("print", of(COMMON, PrintBundle::print));
FUNCTIONS.put("println", of(COMMON, PrintBundle::println));
FUNCTIONS.put("dump", of(COMMON, PrintBundle::dump));
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
| private static Function print(Context context) { |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON; | package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
FUNCTIONS.put("print", of(COMMON, PrintBundle::print));
FUNCTIONS.put("println", of(COMMON, PrintBundle::println));
FUNCTIONS.put("dump", of(COMMON, PrintBundle::dump));
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
private static Function print(Context context) {
return args -> {
if (args.length > 0) {
System.out.print(args[0]);
} | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/Function.java
// public interface Function {
//
// Value execute(Value... args);
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/NumberValue.java
// public class NumberValue implements Value {
//
// public static final NumberValue MINUS_ONE, ZERO, ONE;
//
// private static final int CACHE_MIN = -128, CACHE_MAX = 127;
// private static final NumberValue[] NUMBER_CACHE;
// static {
// final int length = CACHE_MAX - CACHE_MIN + 1;
// NUMBER_CACHE = new NumberValue[length];
// int value = CACHE_MIN;
// for (int i = 0; i < length; i++) {
// NUMBER_CACHE[i] = new NumberValue(value++);
// }
//
// final int zeroIndex = -CACHE_MIN;
// MINUS_ONE = NUMBER_CACHE[zeroIndex - 1];
// ZERO = NUMBER_CACHE[zeroIndex];
// ONE = NUMBER_CACHE[zeroIndex + 1];
// }
//
// public static NumberValue fromBoolean(boolean b) {
// return b ? ONE : ZERO;
// }
//
// public static NumberValue of(int value) {
// if (CACHE_MIN <= value && value <= CACHE_MAX) {
// return NUMBER_CACHE[-CACHE_MIN + value];
// }
// return new NumberValue(value);
// }
//
// public static NumberValue of(Number value) {
// return new NumberValue(value);
// }
//
// private final Number value;
//
// private NumberValue(Number value) {
// this.value = value;
// }
//
// @Override
// public int type() {
// return Types.NUMBER;
// }
//
// @Override
// public Number raw() {
// return value;
// }
//
// public boolean asBoolean() {
// return value.intValue() != 0;
// }
//
// @Override
// public Number asNumber() {
// return value;
// }
//
// @Override
// public String asString() {
// return value.toString();
// }
//
// @Override
// public int hashCode() {
// int hash = 3;
// hash = 71 * hash + value.hashCode();
// return hash;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) return true;
// if (obj == null) return false;
// if (getClass() != obj.getClass())
// return false;
// final Number other = ((NumberValue) obj).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue()) == 0;
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue()) == 0;
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue()) == 0;
// }
// return Integer.compare(value.intValue(), other.intValue()) == 0;
// }
//
// @Override
// public int compareTo(Value o) {
// if (o.type() == Types.NUMBER) {
// final Number other = ((NumberValue) o).value;
// if (value instanceof Double || other instanceof Double) {
// return Double.compare(value.doubleValue(), other.doubleValue());
// }
// if (value instanceof Float || other instanceof Float) {
// return Float.compare(value.floatValue(), other.floatValue());
// }
// if (value instanceof Long || other instanceof Long) {
// return Long.compare(value.longValue(), other.longValue());
// }
// return Integer.compare(value.intValue(), other.intValue());
// }
// return asString().compareTo(o.asString());
// }
//
// @Override
// public String toString() {
// return asString();
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/bundles/FunctionInfo.java
// public static FunctionInfo of(FunctionType type, Function function) {
// return of(type, (Context c) -> function);
// }
// Path: app/src/test/java/com/annimon/hotarufx/bundles/PrintBundle.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.Function;
import com.annimon.hotarufx.lib.NumberValue;
import java.util.HashMap;
import java.util.Map;
import static com.annimon.hotarufx.bundles.FunctionInfo.of;
import static com.annimon.hotarufx.bundles.FunctionType.COMMON;
package com.annimon.hotarufx.bundles;
public class PrintBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
FUNCTIONS.put("print", of(COMMON, PrintBundle::print));
FUNCTIONS.put("println", of(COMMON, PrintBundle::println));
FUNCTIONS.put("dump", of(COMMON, PrintBundle::dump));
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
private static Function print(Context context) {
return args -> {
if (args.length > 0) {
System.out.print(args[0]);
} | return NumberValue.ZERO; |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/bundles/Bundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
| import com.annimon.hotarufx.lib.Context;
import java.util.Map;
import java.util.stream.Collectors; | package com.annimon.hotarufx.bundles;
public interface Bundle {
Map<String, FunctionInfo> functionsInfo();
default Map<String, FunctionType> functions() {
return functionsInfo().entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().getType()));
}
| // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/bundles/Bundle.java
import com.annimon.hotarufx.lib.Context;
import java.util.Map;
import java.util.stream.Collectors;
package com.annimon.hotarufx.bundles;
public interface Bundle {
Map<String, FunctionInfo> functionsInfo();
default Map<String, FunctionType> functions() {
return functionsInfo().entrySet().stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().getType()));
}
| default void load(Context context) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/UnaryNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor; | package com.annimon.hotarufx.parser.ast;
public class UnaryNode extends ASTNode {
public enum Operator { NEGATE };
public final Operator operator;
public final Node node;
public UnaryNode(Operator operator, Node node) {
this.operator = operator;
this.node = node;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/UnaryNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
package com.annimon.hotarufx.parser.ast;
public class UnaryNode extends ASTNode {
public enum Operator { NEGATE };
public final Operator operator;
public final Node node;
public UnaryNode(Operator operator, Node node) {
this.operator = operator;
this.node = node;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lexer/Lexer.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/LexerException.java
// public class LexerException extends RuntimeException {
//
// public LexerException(String message) {
// super(message);
// }
//
// public LexerException(SourcePosition position, String message) {
// super(position.toString() + " " + message);
// }
// }
| import com.annimon.hotarufx.exceptions.LexerException;
import java.util.ArrayList;
import java.util.List; | if (position >= length) return '\0';
return input.charAt(position);
}
protected SourcePosition currentPosition() {
return new SourcePosition(pos, row, col);
}
protected Token addToken(HotaruTokenId tokenId) {
return addToken(tokenId, buffer.toString());
}
protected Token addToken(HotaruTokenId tokenId, String text) {
return addToken(tokenId, text, text.length());
}
protected Token addToken(HotaruTokenId tokenId, String text, int length) {
final var token = createToken(tokenId, text, length);
tokens.add(token);
return token;
}
protected Token createToken(HotaruTokenId tokenId) {
return createToken(tokenId, buffer.toString(), buffer.length());
}
protected Token createToken(HotaruTokenId tokenId, String text, int length) {
return new Token(tokenId, text, length, currentPosition());
}
| // Path: app/src/main/java/com/annimon/hotarufx/exceptions/LexerException.java
// public class LexerException extends RuntimeException {
//
// public LexerException(String message) {
// super(message);
// }
//
// public LexerException(SourcePosition position, String message) {
// super(position.toString() + " " + message);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lexer/Lexer.java
import com.annimon.hotarufx.exceptions.LexerException;
import java.util.ArrayList;
import java.util.List;
if (position >= length) return '\0';
return input.charAt(position);
}
protected SourcePosition currentPosition() {
return new SourcePosition(pos, row, col);
}
protected Token addToken(HotaruTokenId tokenId) {
return addToken(tokenId, buffer.toString());
}
protected Token addToken(HotaruTokenId tokenId, String text) {
return addToken(tokenId, text, text.length());
}
protected Token addToken(HotaruTokenId tokenId, String text, int length) {
final var token = createToken(tokenId, text, length);
tokens.add(token);
return token;
}
protected Token createToken(HotaruTokenId tokenId) {
return createToken(tokenId, buffer.toString(), buffer.length());
}
protected Token createToken(HotaruTokenId tokenId, String text, int length) {
return new Token(tokenId, text, length, currentPosition());
}
| protected LexerException error(String message) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java | // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
| import com.annimon.hotarufx.lexer.SourcePosition; | package com.annimon.hotarufx.exceptions;
public class TypeException extends HotaruRuntimeException {
public TypeException(String message) {
super(message);
}
| // Path: app/src/main/java/com/annimon/hotarufx/lexer/SourcePosition.java
// public class SourcePosition {
//
// private final int position;
// private final int row;
// private final int column;
//
// public SourcePosition(int position, int row, int column) {
// this.position = position;
// this.row = row;
// this.column = column;
// }
//
// public int getPosition() {
// return position;
// }
//
// public int getRow() {
// return row;
// }
//
// public int getColumn() {
// return column;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// SourcePosition that = (SourcePosition) o;
// return position == that.position &&
// row == that.row &&
// column == that.column;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(position, row, column);
// }
//
// @Override
// public String toString() {
// return "[" + row + ", " + column + "]";
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
import com.annimon.hotarufx.lexer.SourcePosition;
package com.annimon.hotarufx.exceptions;
public class TypeException extends HotaruRuntimeException {
public TypeException(String message) {
super(message);
}
| public TypeException(String message, SourcePosition start, SourcePosition end) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/Context.java | // Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
// public class Composition {
//
// private final int
// virtualWidth, virtualHeight,
// sceneWidth, sceneHeight;
// private final double factor;
//
// private final TimeLine timeline;
//
// private final VirtualScene scene;
//
// private final Paint background;
//
// public Composition() {
// this(1280, 720);
// }
//
// public Composition(double frameRate) {
// this(1280, 720, frameRate);
// }
//
// public Composition(int sceneWidth, int sceneHeight) {
// this(sceneWidth, sceneHeight, 30);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate) {
// this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
// this.sceneWidth = sceneWidth;
// this.sceneHeight = sceneHeight;
// this.background = background;
// virtualHeight = 1080;
// factor = virtualHeight / (double) sceneHeight;
// virtualWidth = (int) (sceneWidth * factor);
// timeline = new TimeLine(frameRate);
// scene = newScene();
// }
//
// public int getVirtualWidth() {
// return virtualWidth;
// }
//
// public int getVirtualHeight() {
// return virtualHeight;
// }
//
// public int getSceneWidth() {
// return sceneWidth;
// }
//
// public int getSceneHeight() {
// return sceneHeight;
// }
//
// public double getFactor() {
// return factor;
// }
//
// public TimeLine getTimeline() {
// return timeline;
// }
//
// public VirtualScene getScene() {
// return scene;
// }
//
// public Paint getBackground() {
// return background;
// }
//
// private VirtualScene newScene() {
// final var group = new NodesGroup(sceneWidth, sceneHeight);
// group.setScaleX(1d / factor);
// group.setScaleY(1d / factor);
// group.setTranslateX(sceneWidth / 2f);
// group.setTranslateY(sceneHeight / 2f);
// return new VirtualScene(group, virtualWidth, virtualHeight);
// }
//
// public Scene producePreviewScene() {
// final var fxScene = new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// fxScene.setOnKeyPressed(e -> {
// switch (e.getCode()) {
// case SPACE:
// timeline.togglePause();
// break;
// case BACK_SPACE:
// timeline.getFxTimeline().stop();
// timeline.getFxTimeline().playFromStart();
// break;
// case LEFT:
// case RIGHT:
// int sign = e.getCode() == KeyCode.LEFT ? -1 : 1;
// if (e.isShiftDown()) {
// timeline.seek(sign);
// } else if (e.isControlDown()) {
// timeline.seek(10 * sign);
// } else if (e.isAltDown()) {
// timeline.seek(30 * sign);
// } else {
// timeline.seekFrame(sign);
// }
// break;
// }
// });
// return fxScene;
// }
//
// public Scene produceRendererScene() {
// return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// }
// }
| import com.annimon.hotarufx.visual.Composition;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; | package com.annimon.hotarufx.lib;
public final class Context {
private final Map<String, Value> variables;
private final Map<String, Function> functions; | // Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
// public class Composition {
//
// private final int
// virtualWidth, virtualHeight,
// sceneWidth, sceneHeight;
// private final double factor;
//
// private final TimeLine timeline;
//
// private final VirtualScene scene;
//
// private final Paint background;
//
// public Composition() {
// this(1280, 720);
// }
//
// public Composition(double frameRate) {
// this(1280, 720, frameRate);
// }
//
// public Composition(int sceneWidth, int sceneHeight) {
// this(sceneWidth, sceneHeight, 30);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate) {
// this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
// this.sceneWidth = sceneWidth;
// this.sceneHeight = sceneHeight;
// this.background = background;
// virtualHeight = 1080;
// factor = virtualHeight / (double) sceneHeight;
// virtualWidth = (int) (sceneWidth * factor);
// timeline = new TimeLine(frameRate);
// scene = newScene();
// }
//
// public int getVirtualWidth() {
// return virtualWidth;
// }
//
// public int getVirtualHeight() {
// return virtualHeight;
// }
//
// public int getSceneWidth() {
// return sceneWidth;
// }
//
// public int getSceneHeight() {
// return sceneHeight;
// }
//
// public double getFactor() {
// return factor;
// }
//
// public TimeLine getTimeline() {
// return timeline;
// }
//
// public VirtualScene getScene() {
// return scene;
// }
//
// public Paint getBackground() {
// return background;
// }
//
// private VirtualScene newScene() {
// final var group = new NodesGroup(sceneWidth, sceneHeight);
// group.setScaleX(1d / factor);
// group.setScaleY(1d / factor);
// group.setTranslateX(sceneWidth / 2f);
// group.setTranslateY(sceneHeight / 2f);
// return new VirtualScene(group, virtualWidth, virtualHeight);
// }
//
// public Scene producePreviewScene() {
// final var fxScene = new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// fxScene.setOnKeyPressed(e -> {
// switch (e.getCode()) {
// case SPACE:
// timeline.togglePause();
// break;
// case BACK_SPACE:
// timeline.getFxTimeline().stop();
// timeline.getFxTimeline().playFromStart();
// break;
// case LEFT:
// case RIGHT:
// int sign = e.getCode() == KeyCode.LEFT ? -1 : 1;
// if (e.isShiftDown()) {
// timeline.seek(sign);
// } else if (e.isControlDown()) {
// timeline.seek(10 * sign);
// } else if (e.isAltDown()) {
// timeline.seek(30 * sign);
// } else {
// timeline.seekFrame(sign);
// }
// break;
// }
// });
// return fxScene;
// }
//
// public Scene produceRendererScene() {
// return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
import com.annimon.hotarufx.visual.Composition;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
package com.annimon.hotarufx.lib;
public final class Context {
private final Map<String, Value> variables;
private final Map<String, Function> functions; | private Composition composition; |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/FontValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.TypeException;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight; | init();
}
private void init() {
final var map = super.getMap();
map.put("family", new StringValue(font.getFamily()));
map.put("isItalic", NumberValue.fromBoolean(font.getStyle().toLowerCase().contains("italic")));
final var weight = FontWeight.findByName(font.getStyle());
map.put("weight", NumberValue.of(weight != null
? (weight.getWeight())
: FontWeight.NORMAL.getWeight()));
map.put("size", NumberValue.of(font.getSize()));
}
@Override
public int type() {
return Types.MAP;
}
public Font getFont() {
return font;
}
@Override
public Object raw() {
return font;
}
@Override
public Number asNumber() { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/FontValue.java
import com.annimon.hotarufx.exceptions.TypeException;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
init();
}
private void init() {
final var map = super.getMap();
map.put("family", new StringValue(font.getFamily()));
map.put("isItalic", NumberValue.fromBoolean(font.getStyle().toLowerCase().contains("italic")));
final var weight = FontWeight.findByName(font.getStyle());
map.put("weight", NumberValue.of(weight != null
? (weight.getWeight())
: FontWeight.NORMAL.getWeight()));
map.put("size", NumberValue.of(font.getSize()));
}
@Override
public int type() {
return Types.MAP;
}
public Font getFont() {
return font;
}
@Override
public Object raw() {
return font;
}
@Override
public Number asNumber() { | throw new TypeException("Cannot cast font to number"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/bundles/BundleLoader.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
| import com.annimon.hotarufx.lib.Context;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer; | package com.annimon.hotarufx.bundles;
public final class BundleLoader {
public static List<Class<? extends Bundle>> runtimeBundles() {
return Arrays.asList(
CompositionBundle.class,
NodesBundle.class,
NodeUtilsBundle.class,
InterpolatorsBundle.class,
FontBundle.class
);
}
| // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/bundles/BundleLoader.java
import com.annimon.hotarufx.lib.Context;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
package com.annimon.hotarufx.bundles;
public final class BundleLoader {
public static List<Class<? extends Bundle>> runtimeBundles() {
return Arrays.asList(
CompositionBundle.class,
NodesBundle.class,
NodeUtilsBundle.class,
InterpolatorsBundle.class,
FontBundle.class
);
}
| public static void loadSingle(Context context, Class<? extends Bundle> clazz) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
| import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font; | package com.annimon.hotarufx.lib;
public class PropertyValue implements Value {
private final Property property;
private final Map<String, Value> fields;
public PropertyValue(Property property) {
this.property = property;
fields = new HashMap<>();
fields.put("add", new FunctionValue(add()));
fields.put("clear", new FunctionValue(clear()));
}
public Property getProperty() {
return property;
}
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java
import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
package com.annimon.hotarufx.lib;
public class PropertyValue implements Value {
private final Property property;
private final Map<String, Value> fields;
public PropertyValue(Property property) {
this.property = property;
fields = new HashMap<>();
fields.put("add", new FunctionValue(add()));
fields.put("clear", new FunctionValue(clear()));
}
public Property getProperty() {
return property;
}
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) { | throw new HotaruRuntimeException("PropertyValue does not have " + name + " field"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
| import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font; | fields.put("add", new FunctionValue(add()));
fields.put("clear", new FunctionValue(clear()));
}
public Property getProperty() {
return property;
}
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) {
throw new HotaruRuntimeException("PropertyValue does not have " + name + " field");
}
return field;
}
@SuppressWarnings("unchecked")
private Function add() {
return args -> {
Validator.with(args).checkOrOr(2, 3);
final Interpolator interpolator;
if (args.length == 2) {
interpolator = Interpolator.LINEAR;
} else {
if (args[2].type() != Types.INTERPOLATOR) { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java
import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
fields.put("add", new FunctionValue(add()));
fields.put("clear", new FunctionValue(clear()));
}
public Property getProperty() {
return property;
}
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) {
throw new HotaruRuntimeException("PropertyValue does not have " + name + " field");
}
return field;
}
@SuppressWarnings("unchecked")
private Function add() {
return args -> {
Validator.with(args).checkOrOr(2, 3);
final Interpolator interpolator;
if (args.length == 2) {
interpolator = Interpolator.LINEAR;
} else {
if (args[2].type() != Types.INTERPOLATOR) { | throw new TypeException("Interpolator required at third argument"); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
| import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font; |
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) {
throw new HotaruRuntimeException("PropertyValue does not have " + name + " field");
}
return field;
}
@SuppressWarnings("unchecked")
private Function add() {
return args -> {
Validator.with(args).checkOrOr(2, 3);
final Interpolator interpolator;
if (args.length == 2) {
interpolator = Interpolator.LINEAR;
} else {
if (args[2].type() != Types.INTERPOLATOR) {
throw new TypeException("Interpolator required at third argument");
}
interpolator = ((InterpolatorValue) args[2]).getInterpolator();
}
final var type = property.getType();
switch (type) {
case BOOLEAN: | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java
import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) {
throw new HotaruRuntimeException("PropertyValue does not have " + name + " field");
}
return field;
}
@SuppressWarnings("unchecked")
private Function add() {
return args -> {
Validator.with(args).checkOrOr(2, 3);
final Interpolator interpolator;
if (args.length == 2) {
interpolator = Interpolator.LINEAR;
} else {
if (args[2].type() != Types.INTERPOLATOR) {
throw new TypeException("Interpolator required at third argument");
}
interpolator = ((InterpolatorValue) args[2]).getInterpolator();
}
final var type = property.getType();
switch (type) {
case BOOLEAN: | ((PropertyTimeline<Boolean>)property.getProperty().get()).add( |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
| import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font; | @Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) {
throw new HotaruRuntimeException("PropertyValue does not have " + name + " field");
}
return field;
}
@SuppressWarnings("unchecked")
private Function add() {
return args -> {
Validator.with(args).checkOrOr(2, 3);
final Interpolator interpolator;
if (args.length == 2) {
interpolator = Interpolator.LINEAR;
} else {
if (args[2].type() != Types.INTERPOLATOR) {
throw new TypeException("Interpolator required at third argument");
}
interpolator = ((InterpolatorValue) args[2]).getInterpolator();
}
final var type = property.getType();
switch (type) {
case BOOLEAN:
((PropertyTimeline<Boolean>)property.getProperty().get()).add( | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/HotaruRuntimeException.java
// public class HotaruRuntimeException extends RuntimeException {
//
// public HotaruRuntimeException(String s) {
// super(s);
// }
//
// public HotaruRuntimeException(String string, SourcePosition start, SourcePosition end) {
// super(string + " at " + start + " .. " + end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/KeyFrame.java
// public class KeyFrame implements Comparable<KeyFrame> {
//
// public static KeyFrame of(int frame) {
// return new KeyFrame(frame);
// }
//
// private KeyFrame(int frame) {
// this.frame = frame;
// }
//
// private final int frame;
//
// public int getFrame() {
// return frame;
// }
//
// @Override
// public int compareTo(KeyFrame o) {
// return Integer.compare(frame, o.frame);
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// KeyFrame keyFrame = (KeyFrame) o;
// return frame == keyFrame.frame;
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(frame);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/PropertyTimeline.java
// public class PropertyTimeline<T> {
//
// private final WritableValue<T> property;
// private final Map<KeyFrame, KeyFrameValue<T>> keyFrames;
//
// public PropertyTimeline(WritableValue<T> property) {
// this.property = property;
// keyFrames = new TreeMap<>();
// }
//
// public WritableValue<T> getProperty() {
// return property;
// }
//
// public Map<KeyFrame, KeyFrameValue<T>> getKeyFrames() {
// return keyFrames;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value));
// return this;
// }
//
// public PropertyTimeline<T> add(KeyFrame keyFrame, T value, Interpolator interpolator) {
// keyFrames.put(keyFrame, new KeyFrameValue<>(value, interpolator));
// return this;
// }
//
// public PropertyTimeline<T> clear() {
// keyFrames.clear();
// return this;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/PropertyValue.java
import com.annimon.hotarufx.exceptions.HotaruRuntimeException;
import com.annimon.hotarufx.exceptions.TypeException;
import com.annimon.hotarufx.visual.KeyFrame;
import com.annimon.hotarufx.visual.Property;
import com.annimon.hotarufx.visual.PropertyTimeline;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
import javafx.scene.Node;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
@Override
public int type() {
return Types.PROPERTY;
}
public Value getField(String name) {
final var field = fields.get(name);
if (field == null) {
throw new HotaruRuntimeException("PropertyValue does not have " + name + " field");
}
return field;
}
@SuppressWarnings("unchecked")
private Function add() {
return args -> {
Validator.with(args).checkOrOr(2, 3);
final Interpolator interpolator;
if (args.length == 2) {
interpolator = Interpolator.LINEAR;
} else {
if (args[2].type() != Types.INTERPOLATOR) {
throw new TypeException("Interpolator required at third argument");
}
interpolator = ((InterpolatorValue) args[2]).getInterpolator();
}
final var type = property.getType();
switch (type) {
case BOOLEAN:
((PropertyTimeline<Boolean>)property.getProperty().get()).add( | KeyFrame.of(args[0].asInt()), |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/ui/controller/RenderTask.java | // Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
// public class Composition {
//
// private final int
// virtualWidth, virtualHeight,
// sceneWidth, sceneHeight;
// private final double factor;
//
// private final TimeLine timeline;
//
// private final VirtualScene scene;
//
// private final Paint background;
//
// public Composition() {
// this(1280, 720);
// }
//
// public Composition(double frameRate) {
// this(1280, 720, frameRate);
// }
//
// public Composition(int sceneWidth, int sceneHeight) {
// this(sceneWidth, sceneHeight, 30);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate) {
// this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
// this.sceneWidth = sceneWidth;
// this.sceneHeight = sceneHeight;
// this.background = background;
// virtualHeight = 1080;
// factor = virtualHeight / (double) sceneHeight;
// virtualWidth = (int) (sceneWidth * factor);
// timeline = new TimeLine(frameRate);
// scene = newScene();
// }
//
// public int getVirtualWidth() {
// return virtualWidth;
// }
//
// public int getVirtualHeight() {
// return virtualHeight;
// }
//
// public int getSceneWidth() {
// return sceneWidth;
// }
//
// public int getSceneHeight() {
// return sceneHeight;
// }
//
// public double getFactor() {
// return factor;
// }
//
// public TimeLine getTimeline() {
// return timeline;
// }
//
// public VirtualScene getScene() {
// return scene;
// }
//
// public Paint getBackground() {
// return background;
// }
//
// private VirtualScene newScene() {
// final var group = new NodesGroup(sceneWidth, sceneHeight);
// group.setScaleX(1d / factor);
// group.setScaleY(1d / factor);
// group.setTranslateX(sceneWidth / 2f);
// group.setTranslateY(sceneHeight / 2f);
// return new VirtualScene(group, virtualWidth, virtualHeight);
// }
//
// public Scene producePreviewScene() {
// final var fxScene = new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// fxScene.setOnKeyPressed(e -> {
// switch (e.getCode()) {
// case SPACE:
// timeline.togglePause();
// break;
// case BACK_SPACE:
// timeline.getFxTimeline().stop();
// timeline.getFxTimeline().playFromStart();
// break;
// case LEFT:
// case RIGHT:
// int sign = e.getCode() == KeyCode.LEFT ? -1 : 1;
// if (e.isShiftDown()) {
// timeline.seek(sign);
// } else if (e.isControlDown()) {
// timeline.seek(10 * sign);
// } else if (e.isAltDown()) {
// timeline.seek(30 * sign);
// } else {
// timeline.seekFrame(sign);
// }
// break;
// }
// });
// return fxScene;
// }
//
// public Scene produceRendererScene() {
// return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/TimeLine.java
// public class TimeLine {
//
// private final double frameRate;
//
// private final Timeline fxTimeline;
//
// public TimeLine(double frameRate) {
// this.frameRate = frameRate;
// fxTimeline = new Timeline(frameRate);
// }
//
// public double getFrameRate() {
// return frameRate;
// }
//
// public Timeline getFxTimeline() {
// return fxTimeline;
// }
//
// public void addKeyFrame(KeyFrame keyFrame, KeyValue fxKeyValue) {
// fxTimeline.getKeyFrames().add(new javafx.animation.KeyFrame(
// duration(keyFrame), fxKeyValue));
// }
//
// private Duration duration(KeyFrame keyFrame) {
// return Duration.millis(1000d * keyFrame.getFrame() / frameRate);
// }
//
// public void togglePause() {
// switch (fxTimeline.getStatus()) {
// case PAUSED:
// fxTimeline.play();
// break;
// case RUNNING:
// fxTimeline.pause();
// break;
// case STOPPED:
// fxTimeline.playFromStart();
// break;
// }
// }
//
// public void seekFrame(final int value) {
// fxTimeline.pause();
// final var offset = Duration.millis(1000d * Math.abs(value) / frameRate);
// final var now = fxTimeline.getCurrentTime();
// final var newDuration = value > 0 ? now.add(offset) : now.subtract(offset);
// fxTimeline.jumpTo(newDuration);
// }
//
// public void seek(final int sec) {
// final var now = fxTimeline.getCurrentTime();
// fxTimeline.jumpTo(now.add(Duration.seconds(sec)));
// }
// }
| import com.annimon.hotarufx.visual.Composition;
import com.annimon.hotarufx.visual.TimeLine;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.image.WritableImage;
import javafx.util.Duration;
import javax.imageio.ImageIO; | package com.annimon.hotarufx.ui.controller;
public class RenderTask extends Task<Boolean> {
private final File directory; | // Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
// public class Composition {
//
// private final int
// virtualWidth, virtualHeight,
// sceneWidth, sceneHeight;
// private final double factor;
//
// private final TimeLine timeline;
//
// private final VirtualScene scene;
//
// private final Paint background;
//
// public Composition() {
// this(1280, 720);
// }
//
// public Composition(double frameRate) {
// this(1280, 720, frameRate);
// }
//
// public Composition(int sceneWidth, int sceneHeight) {
// this(sceneWidth, sceneHeight, 30);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate) {
// this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
// this.sceneWidth = sceneWidth;
// this.sceneHeight = sceneHeight;
// this.background = background;
// virtualHeight = 1080;
// factor = virtualHeight / (double) sceneHeight;
// virtualWidth = (int) (sceneWidth * factor);
// timeline = new TimeLine(frameRate);
// scene = newScene();
// }
//
// public int getVirtualWidth() {
// return virtualWidth;
// }
//
// public int getVirtualHeight() {
// return virtualHeight;
// }
//
// public int getSceneWidth() {
// return sceneWidth;
// }
//
// public int getSceneHeight() {
// return sceneHeight;
// }
//
// public double getFactor() {
// return factor;
// }
//
// public TimeLine getTimeline() {
// return timeline;
// }
//
// public VirtualScene getScene() {
// return scene;
// }
//
// public Paint getBackground() {
// return background;
// }
//
// private VirtualScene newScene() {
// final var group = new NodesGroup(sceneWidth, sceneHeight);
// group.setScaleX(1d / factor);
// group.setScaleY(1d / factor);
// group.setTranslateX(sceneWidth / 2f);
// group.setTranslateY(sceneHeight / 2f);
// return new VirtualScene(group, virtualWidth, virtualHeight);
// }
//
// public Scene producePreviewScene() {
// final var fxScene = new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// fxScene.setOnKeyPressed(e -> {
// switch (e.getCode()) {
// case SPACE:
// timeline.togglePause();
// break;
// case BACK_SPACE:
// timeline.getFxTimeline().stop();
// timeline.getFxTimeline().playFromStart();
// break;
// case LEFT:
// case RIGHT:
// int sign = e.getCode() == KeyCode.LEFT ? -1 : 1;
// if (e.isShiftDown()) {
// timeline.seek(sign);
// } else if (e.isControlDown()) {
// timeline.seek(10 * sign);
// } else if (e.isAltDown()) {
// timeline.seek(30 * sign);
// } else {
// timeline.seekFrame(sign);
// }
// break;
// }
// });
// return fxScene;
// }
//
// public Scene produceRendererScene() {
// return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/TimeLine.java
// public class TimeLine {
//
// private final double frameRate;
//
// private final Timeline fxTimeline;
//
// public TimeLine(double frameRate) {
// this.frameRate = frameRate;
// fxTimeline = new Timeline(frameRate);
// }
//
// public double getFrameRate() {
// return frameRate;
// }
//
// public Timeline getFxTimeline() {
// return fxTimeline;
// }
//
// public void addKeyFrame(KeyFrame keyFrame, KeyValue fxKeyValue) {
// fxTimeline.getKeyFrames().add(new javafx.animation.KeyFrame(
// duration(keyFrame), fxKeyValue));
// }
//
// private Duration duration(KeyFrame keyFrame) {
// return Duration.millis(1000d * keyFrame.getFrame() / frameRate);
// }
//
// public void togglePause() {
// switch (fxTimeline.getStatus()) {
// case PAUSED:
// fxTimeline.play();
// break;
// case RUNNING:
// fxTimeline.pause();
// break;
// case STOPPED:
// fxTimeline.playFromStart();
// break;
// }
// }
//
// public void seekFrame(final int value) {
// fxTimeline.pause();
// final var offset = Duration.millis(1000d * Math.abs(value) / frameRate);
// final var now = fxTimeline.getCurrentTime();
// final var newDuration = value > 0 ? now.add(offset) : now.subtract(offset);
// fxTimeline.jumpTo(newDuration);
// }
//
// public void seek(final int sec) {
// final var now = fxTimeline.getCurrentTime();
// fxTimeline.jumpTo(now.add(Duration.seconds(sec)));
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/ui/controller/RenderTask.java
import com.annimon.hotarufx.visual.Composition;
import com.annimon.hotarufx.visual.TimeLine;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.image.WritableImage;
import javafx.util.Duration;
import javax.imageio.ImageIO;
package com.annimon.hotarufx.ui.controller;
public class RenderTask extends Task<Boolean> {
private final File directory; | private final Composition composition; |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/ui/controller/RenderTask.java | // Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
// public class Composition {
//
// private final int
// virtualWidth, virtualHeight,
// sceneWidth, sceneHeight;
// private final double factor;
//
// private final TimeLine timeline;
//
// private final VirtualScene scene;
//
// private final Paint background;
//
// public Composition() {
// this(1280, 720);
// }
//
// public Composition(double frameRate) {
// this(1280, 720, frameRate);
// }
//
// public Composition(int sceneWidth, int sceneHeight) {
// this(sceneWidth, sceneHeight, 30);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate) {
// this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
// this.sceneWidth = sceneWidth;
// this.sceneHeight = sceneHeight;
// this.background = background;
// virtualHeight = 1080;
// factor = virtualHeight / (double) sceneHeight;
// virtualWidth = (int) (sceneWidth * factor);
// timeline = new TimeLine(frameRate);
// scene = newScene();
// }
//
// public int getVirtualWidth() {
// return virtualWidth;
// }
//
// public int getVirtualHeight() {
// return virtualHeight;
// }
//
// public int getSceneWidth() {
// return sceneWidth;
// }
//
// public int getSceneHeight() {
// return sceneHeight;
// }
//
// public double getFactor() {
// return factor;
// }
//
// public TimeLine getTimeline() {
// return timeline;
// }
//
// public VirtualScene getScene() {
// return scene;
// }
//
// public Paint getBackground() {
// return background;
// }
//
// private VirtualScene newScene() {
// final var group = new NodesGroup(sceneWidth, sceneHeight);
// group.setScaleX(1d / factor);
// group.setScaleY(1d / factor);
// group.setTranslateX(sceneWidth / 2f);
// group.setTranslateY(sceneHeight / 2f);
// return new VirtualScene(group, virtualWidth, virtualHeight);
// }
//
// public Scene producePreviewScene() {
// final var fxScene = new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// fxScene.setOnKeyPressed(e -> {
// switch (e.getCode()) {
// case SPACE:
// timeline.togglePause();
// break;
// case BACK_SPACE:
// timeline.getFxTimeline().stop();
// timeline.getFxTimeline().playFromStart();
// break;
// case LEFT:
// case RIGHT:
// int sign = e.getCode() == KeyCode.LEFT ? -1 : 1;
// if (e.isShiftDown()) {
// timeline.seek(sign);
// } else if (e.isControlDown()) {
// timeline.seek(10 * sign);
// } else if (e.isAltDown()) {
// timeline.seek(30 * sign);
// } else {
// timeline.seekFrame(sign);
// }
// break;
// }
// });
// return fxScene;
// }
//
// public Scene produceRendererScene() {
// return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/TimeLine.java
// public class TimeLine {
//
// private final double frameRate;
//
// private final Timeline fxTimeline;
//
// public TimeLine(double frameRate) {
// this.frameRate = frameRate;
// fxTimeline = new Timeline(frameRate);
// }
//
// public double getFrameRate() {
// return frameRate;
// }
//
// public Timeline getFxTimeline() {
// return fxTimeline;
// }
//
// public void addKeyFrame(KeyFrame keyFrame, KeyValue fxKeyValue) {
// fxTimeline.getKeyFrames().add(new javafx.animation.KeyFrame(
// duration(keyFrame), fxKeyValue));
// }
//
// private Duration duration(KeyFrame keyFrame) {
// return Duration.millis(1000d * keyFrame.getFrame() / frameRate);
// }
//
// public void togglePause() {
// switch (fxTimeline.getStatus()) {
// case PAUSED:
// fxTimeline.play();
// break;
// case RUNNING:
// fxTimeline.pause();
// break;
// case STOPPED:
// fxTimeline.playFromStart();
// break;
// }
// }
//
// public void seekFrame(final int value) {
// fxTimeline.pause();
// final var offset = Duration.millis(1000d * Math.abs(value) / frameRate);
// final var now = fxTimeline.getCurrentTime();
// final var newDuration = value > 0 ? now.add(offset) : now.subtract(offset);
// fxTimeline.jumpTo(newDuration);
// }
//
// public void seek(final int sec) {
// final var now = fxTimeline.getCurrentTime();
// fxTimeline.jumpTo(now.add(Duration.seconds(sec)));
// }
// }
| import com.annimon.hotarufx.visual.Composition;
import com.annimon.hotarufx.visual.TimeLine;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.image.WritableImage;
import javafx.util.Duration;
import javax.imageio.ImageIO; | package com.annimon.hotarufx.ui.controller;
public class RenderTask extends Task<Boolean> {
private final File directory;
private final Composition composition;
private final Scene scene; | // Path: app/src/main/java/com/annimon/hotarufx/visual/Composition.java
// public class Composition {
//
// private final int
// virtualWidth, virtualHeight,
// sceneWidth, sceneHeight;
// private final double factor;
//
// private final TimeLine timeline;
//
// private final VirtualScene scene;
//
// private final Paint background;
//
// public Composition() {
// this(1280, 720);
// }
//
// public Composition(double frameRate) {
// this(1280, 720, frameRate);
// }
//
// public Composition(int sceneWidth, int sceneHeight) {
// this(sceneWidth, sceneHeight, 30);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate) {
// this(sceneWidth, sceneHeight, frameRate, Color.WHITE);
// }
//
// public Composition(int sceneWidth, int sceneHeight, double frameRate, Paint background) {
// this.sceneWidth = sceneWidth;
// this.sceneHeight = sceneHeight;
// this.background = background;
// virtualHeight = 1080;
// factor = virtualHeight / (double) sceneHeight;
// virtualWidth = (int) (sceneWidth * factor);
// timeline = new TimeLine(frameRate);
// scene = newScene();
// }
//
// public int getVirtualWidth() {
// return virtualWidth;
// }
//
// public int getVirtualHeight() {
// return virtualHeight;
// }
//
// public int getSceneWidth() {
// return sceneWidth;
// }
//
// public int getSceneHeight() {
// return sceneHeight;
// }
//
// public double getFactor() {
// return factor;
// }
//
// public TimeLine getTimeline() {
// return timeline;
// }
//
// public VirtualScene getScene() {
// return scene;
// }
//
// public Paint getBackground() {
// return background;
// }
//
// private VirtualScene newScene() {
// final var group = new NodesGroup(sceneWidth, sceneHeight);
// group.setScaleX(1d / factor);
// group.setScaleY(1d / factor);
// group.setTranslateX(sceneWidth / 2f);
// group.setTranslateY(sceneHeight / 2f);
// return new VirtualScene(group, virtualWidth, virtualHeight);
// }
//
// public Scene producePreviewScene() {
// final var fxScene = new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// fxScene.setOnKeyPressed(e -> {
// switch (e.getCode()) {
// case SPACE:
// timeline.togglePause();
// break;
// case BACK_SPACE:
// timeline.getFxTimeline().stop();
// timeline.getFxTimeline().playFromStart();
// break;
// case LEFT:
// case RIGHT:
// int sign = e.getCode() == KeyCode.LEFT ? -1 : 1;
// if (e.isShiftDown()) {
// timeline.seek(sign);
// } else if (e.isControlDown()) {
// timeline.seek(10 * sign);
// } else if (e.isAltDown()) {
// timeline.seek(30 * sign);
// } else {
// timeline.seekFrame(sign);
// }
// break;
// }
// });
// return fxScene;
// }
//
// public Scene produceRendererScene() {
// return new Scene(scene.getGroup(), sceneWidth, sceneHeight, background);
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/visual/TimeLine.java
// public class TimeLine {
//
// private final double frameRate;
//
// private final Timeline fxTimeline;
//
// public TimeLine(double frameRate) {
// this.frameRate = frameRate;
// fxTimeline = new Timeline(frameRate);
// }
//
// public double getFrameRate() {
// return frameRate;
// }
//
// public Timeline getFxTimeline() {
// return fxTimeline;
// }
//
// public void addKeyFrame(KeyFrame keyFrame, KeyValue fxKeyValue) {
// fxTimeline.getKeyFrames().add(new javafx.animation.KeyFrame(
// duration(keyFrame), fxKeyValue));
// }
//
// private Duration duration(KeyFrame keyFrame) {
// return Duration.millis(1000d * keyFrame.getFrame() / frameRate);
// }
//
// public void togglePause() {
// switch (fxTimeline.getStatus()) {
// case PAUSED:
// fxTimeline.play();
// break;
// case RUNNING:
// fxTimeline.pause();
// break;
// case STOPPED:
// fxTimeline.playFromStart();
// break;
// }
// }
//
// public void seekFrame(final int value) {
// fxTimeline.pause();
// final var offset = Duration.millis(1000d * Math.abs(value) / frameRate);
// final var now = fxTimeline.getCurrentTime();
// final var newDuration = value > 0 ? now.add(offset) : now.subtract(offset);
// fxTimeline.jumpTo(newDuration);
// }
//
// public void seek(final int sec) {
// final var now = fxTimeline.getCurrentTime();
// fxTimeline.jumpTo(now.add(Duration.seconds(sec)));
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/ui/controller/RenderTask.java
import com.annimon.hotarufx.visual.Composition;
import com.annimon.hotarufx.visual.TimeLine;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Scene;
import javafx.scene.image.WritableImage;
import javafx.util.Duration;
import javax.imageio.ImageIO;
package com.annimon.hotarufx.ui.controller;
public class RenderTask extends Task<Boolean> {
private final File directory;
private final Composition composition;
private final Scene scene; | private final TimeLine timeLine; |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/ArrayNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.List; | package com.annimon.hotarufx.parser.ast;
public class ArrayNode extends ASTNode {
public final List<Node> elements;
public ArrayNode(List<Node> elements) {
this.elements = elements;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/ArrayNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.List;
package com.annimon.hotarufx.parser.ast;
public class ArrayNode extends ASTNode {
public final List<Node> elements;
public ArrayNode(List<Node> elements) {
this.elements = elements;
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/bundles/InterpolatorsBundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/InterpolatorValue.java
// public class InterpolatorValue implements Value {
//
// private final Interpolator interpolator;
//
// public InterpolatorValue(Interpolator interpolator) {
// this.interpolator = interpolator;
// }
//
// public Interpolator getInterpolator() {
// return interpolator;
// }
//
// @Override
// public int type() {
// return Types.INTERPOLATOR;
// }
//
// @Override
// public Object raw() {
// return interpolator;
// }
//
// @Override
// public Number asNumber() {
// throw new TypeException("Cannot cast interpolator to number");
// }
//
// @Override
// public String asString() {
// throw new TypeException("Cannot cast interpolator to string");
// }
//
// @Override
// public int compareTo(Value o) {
// return 0;
// }
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.InterpolatorValue;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator; | package com.annimon.hotarufx.bundles;
public class InterpolatorsBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/InterpolatorValue.java
// public class InterpolatorValue implements Value {
//
// private final Interpolator interpolator;
//
// public InterpolatorValue(Interpolator interpolator) {
// this.interpolator = interpolator;
// }
//
// public Interpolator getInterpolator() {
// return interpolator;
// }
//
// @Override
// public int type() {
// return Types.INTERPOLATOR;
// }
//
// @Override
// public Object raw() {
// return interpolator;
// }
//
// @Override
// public Number asNumber() {
// throw new TypeException("Cannot cast interpolator to number");
// }
//
// @Override
// public String asString() {
// throw new TypeException("Cannot cast interpolator to string");
// }
//
// @Override
// public int compareTo(Value o) {
// return 0;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/bundles/InterpolatorsBundle.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.InterpolatorValue;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
package com.annimon.hotarufx.bundles;
public class InterpolatorsBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
@Override | public void load(Context context) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/bundles/InterpolatorsBundle.java | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/InterpolatorValue.java
// public class InterpolatorValue implements Value {
//
// private final Interpolator interpolator;
//
// public InterpolatorValue(Interpolator interpolator) {
// this.interpolator = interpolator;
// }
//
// public Interpolator getInterpolator() {
// return interpolator;
// }
//
// @Override
// public int type() {
// return Types.INTERPOLATOR;
// }
//
// @Override
// public Object raw() {
// return interpolator;
// }
//
// @Override
// public Number asNumber() {
// throw new TypeException("Cannot cast interpolator to number");
// }
//
// @Override
// public String asString() {
// throw new TypeException("Cannot cast interpolator to string");
// }
//
// @Override
// public int compareTo(Value o) {
// return 0;
// }
// }
| import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.InterpolatorValue;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator; | package com.annimon.hotarufx.bundles;
public class InterpolatorsBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
@Override
public void load(Context context) {
Bundle.super.load(context); | // Path: app/src/main/java/com/annimon/hotarufx/lib/Context.java
// public final class Context {
//
// private final Map<String, Value> variables;
// private final Map<String, Function> functions;
// private Composition composition;
//
// public Context() {
// variables = new ConcurrentHashMap<>();
// functions = new ConcurrentHashMap<>();
// }
//
// public Map<String, Value> variables() {
// return variables;
// }
//
// public Map<String, Function> functions() {
// return functions;
// }
//
// public Composition composition() {
// return composition;
// }
//
// public void composition(Composition composition) {
// this.composition = composition;
// }
// }
//
// Path: app/src/main/java/com/annimon/hotarufx/lib/InterpolatorValue.java
// public class InterpolatorValue implements Value {
//
// private final Interpolator interpolator;
//
// public InterpolatorValue(Interpolator interpolator) {
// this.interpolator = interpolator;
// }
//
// public Interpolator getInterpolator() {
// return interpolator;
// }
//
// @Override
// public int type() {
// return Types.INTERPOLATOR;
// }
//
// @Override
// public Object raw() {
// return interpolator;
// }
//
// @Override
// public Number asNumber() {
// throw new TypeException("Cannot cast interpolator to number");
// }
//
// @Override
// public String asString() {
// throw new TypeException("Cannot cast interpolator to string");
// }
//
// @Override
// public int compareTo(Value o) {
// return 0;
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/bundles/InterpolatorsBundle.java
import com.annimon.hotarufx.lib.Context;
import com.annimon.hotarufx.lib.InterpolatorValue;
import java.util.HashMap;
import java.util.Map;
import javafx.animation.Interpolator;
package com.annimon.hotarufx.bundles;
public class InterpolatorsBundle implements Bundle {
private static final Map<String, FunctionInfo> FUNCTIONS;
static {
FUNCTIONS = new HashMap<>();
}
@Override
public Map<String, FunctionInfo> functionsInfo() {
return FUNCTIONS;
}
@Override
public void load(Context context) {
Bundle.super.load(context); | context.variables().put("linear", new InterpolatorValue(Interpolator.LINEAR)); |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/parser/ast/FunctionNode.java | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
| import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.ArrayList;
import java.util.List; | package com.annimon.hotarufx.parser.ast;
public class FunctionNode extends ASTNode {
public final Node functionNode;
public final List<Node> arguments;
public FunctionNode(Node functionNode) {
this.functionNode = functionNode;
arguments = new ArrayList<>();
}
public void addArgument(Node arg) {
arguments.add(arg);
}
@Override | // Path: app/src/main/java/com/annimon/hotarufx/parser/visitors/ResultVisitor.java
// public interface ResultVisitor<R, T> {
//
// R visit(AccessNode node, T t);
// R visit(ArrayNode node, T t);
// R visit(AssignNode node, T t);
// R visit(BlockNode node, T t);
// R visit(FunctionNode node, T t);
// R visit(MapNode node, T t);
// R visit(PropertyNode node, T t);
// R visit(UnaryNode node, T t);
// R visit(UnitNode node, T t);
// R visit(ValueNode node, T t);
// R visit(VariableNode node, T t);
//
// Value get(AccessNode node, T t);
// Value set(AccessNode node, Value value, T t);
// Value get(VariableNode node, T t);
// Value set(VariableNode node, Value value, T t);
// }
// Path: app/src/main/java/com/annimon/hotarufx/parser/ast/FunctionNode.java
import com.annimon.hotarufx.parser.visitors.ResultVisitor;
import java.util.ArrayList;
import java.util.List;
package com.annimon.hotarufx.parser.ast;
public class FunctionNode extends ASTNode {
public final Node functionNode;
public final List<Node> arguments;
public FunctionNode(Node functionNode) {
this.functionNode = functionNode;
arguments = new ArrayList<>();
}
public void addArgument(Node arg) {
arguments.add(arg);
}
@Override | public <R, T> R accept(ResultVisitor<R, T> visitor, T input) { |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/lexer/HotaruLexerTest.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/LexerException.java
// public class LexerException extends RuntimeException {
//
// public LexerException(String message) {
// super(message);
// }
//
// public LexerException(SourcePosition position, String message) {
// super(position.toString() + " " + message);
// }
// }
| import com.annimon.hotarufx.exceptions.LexerException;
import java.util.List;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.*; | package com.annimon.hotarufx.lexer;
class HotaruLexerTest {
static List<Token> t(String input) {
return HotaruLexer.tokenize(input);
}
static List<Token> all(String input) {
return new HotaruLexer(input).tokenize();
}
static Token single(String input) {
List<Token> tokens = t(input);
if (tokens.isEmpty()) {
throw new AssertionError("Tokens list is empty");
}
return tokens.get(0);
}
@Test
void testTokenizeNumbers() {
assertThat(all("1 1.5 2"), contains(
tokenId(HotaruTokenId.NUMBER),
tokenId(HotaruTokenId.WS),
tokenId(HotaruTokenId.NUMBER),
tokenId(HotaruTokenId.WS),
tokenId(HotaruTokenId.NUMBER)
));
| // Path: app/src/main/java/com/annimon/hotarufx/exceptions/LexerException.java
// public class LexerException extends RuntimeException {
//
// public LexerException(String message) {
// super(message);
// }
//
// public LexerException(SourcePosition position, String message) {
// super(position.toString() + " " + message);
// }
// }
// Path: app/src/test/java/com/annimon/hotarufx/lexer/HotaruLexerTest.java
import com.annimon.hotarufx.exceptions.LexerException;
import java.util.List;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.*;
package com.annimon.hotarufx.lexer;
class HotaruLexerTest {
static List<Token> t(String input) {
return HotaruLexer.tokenize(input);
}
static List<Token> all(String input) {
return new HotaruLexer(input).tokenize();
}
static Token single(String input) {
List<Token> tokens = t(input);
if (tokens.isEmpty()) {
throw new AssertionError("Tokens list is empty");
}
return tokens.get(0);
}
@Test
void testTokenizeNumbers() {
assertThat(all("1 1.5 2"), contains(
tokenId(HotaruTokenId.NUMBER),
tokenId(HotaruTokenId.WS),
tokenId(HotaruTokenId.NUMBER),
tokenId(HotaruTokenId.WS),
tokenId(HotaruTokenId.NUMBER)
));
| assertThrows(LexerException.class, () -> { |
aNNiMON/HotaruFX | app/src/test/java/com/annimon/hotarufx/visual/objects/NodePropertiesTypeTest.java | // Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
| import com.annimon.hotarufx.visual.Property;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Stream;
import javafx.beans.value.WritableValue;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail; | package com.annimon.hotarufx.visual.objects;
class NodePropertiesTypeTest {
static Stream<Arguments> nodeProvider() {
return Stream.of(
new ArcNode(),
new CircleNode(),
new EllipseNode(),
new GroupNode(Collections.singletonList(new TextNode())),
new LineNode(),
new PolygonNode(Arrays.asList(0d, 0d, 20d, 20d, 30d, 30d)),
new PolylineNode(Arrays.asList(0d, 0d, 20d, 20d, 30d, 30d, 0d, 0d)),
new RectangleNode(),
new SVGPathNode(),
new TextNode()
).flatMap(node -> node.propertyBindings()
.entrySet()
.stream()
.map(entry -> Arguments.of(
node,
entry.getKey(),
entry.getValue(),
node.getClass().getSimpleName()
))
);
}
@DisplayName("Node properties type checking")
@ParameterizedTest(name = "{3}: {1}")
@MethodSource("nodeProvider")
@SuppressWarnings("unchecked") | // Path: app/src/main/java/com/annimon/hotarufx/visual/Property.java
// public final class Property {
//
// private final PropertyType type;
// private final Supplier<PropertyTimeline<?>> property;
//
// public Property(PropertyType type, Supplier<PropertyTimeline<?>> property) {
// this.type = type;
// this.property = property;
// }
//
// public PropertyType getType() {
// return type;
// }
//
// public Supplier<PropertyTimeline<?>> getProperty() {
// return property;
// }
// }
// Path: app/src/test/java/com/annimon/hotarufx/visual/objects/NodePropertiesTypeTest.java
import com.annimon.hotarufx.visual.Property;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.Stream;
import javafx.beans.value.WritableValue;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
package com.annimon.hotarufx.visual.objects;
class NodePropertiesTypeTest {
static Stream<Arguments> nodeProvider() {
return Stream.of(
new ArcNode(),
new CircleNode(),
new EllipseNode(),
new GroupNode(Collections.singletonList(new TextNode())),
new LineNode(),
new PolygonNode(Arrays.asList(0d, 0d, 20d, 20d, 30d, 30d)),
new PolylineNode(Arrays.asList(0d, 0d, 20d, 20d, 30d, 30d, 0d, 0d)),
new RectangleNode(),
new SVGPathNode(),
new TextNode()
).flatMap(node -> node.propertyBindings()
.entrySet()
.stream()
.map(entry -> Arguments.of(
node,
entry.getKey(),
entry.getValue(),
node.getClass().getSimpleName()
))
);
}
@DisplayName("Node properties type checking")
@ParameterizedTest(name = "{3}: {1}")
@MethodSource("nodeProvider")
@SuppressWarnings("unchecked") | void testNode(ObjectNode node, String name, Property property, String nodeName) { |
aNNiMON/HotaruFX | app/src/main/java/com/annimon/hotarufx/lib/MapValue.java | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
| import com.annimon.hotarufx.exceptions.TypeException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects; | private final Map<String, Value> map;
public MapValue(int size) {
this.map = new HashMap<>(size);
}
public MapValue(Map<String, Value> map) {
this.map = map;
}
@Override
public int type() {
return Types.MAP;
}
public int size() {
return map.size();
}
public Map<String, Value> getMap() {
return map;
}
@Override
public Object raw() {
return map;
}
@Override
public Number asNumber() { | // Path: app/src/main/java/com/annimon/hotarufx/exceptions/TypeException.java
// public class TypeException extends HotaruRuntimeException {
//
// public TypeException(String message) {
// super(message);
// }
//
// public TypeException(String message, SourcePosition start, SourcePosition end) {
// super(message, start, end);
// }
// }
// Path: app/src/main/java/com/annimon/hotarufx/lib/MapValue.java
import com.annimon.hotarufx.exceptions.TypeException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
private final Map<String, Value> map;
public MapValue(int size) {
this.map = new HashMap<>(size);
}
public MapValue(Map<String, Value> map) {
this.map = map;
}
@Override
public int type() {
return Types.MAP;
}
public int size() {
return map.size();
}
public Map<String, Value> getMap() {
return map;
}
@Override
public Object raw() {
return map;
}
@Override
public Number asNumber() { | throw new TypeException("Cannot cast map to number"); |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract; | package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false; | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract;
package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false; | private RestrictionBuilder restrictionBuilder = null; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract; | package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false;
private RestrictionBuilder restrictionBuilder = null;
public void setAllAsForVariables()
{ | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract;
package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false;
private RestrictionBuilder restrictionBuilder = null;
public void setAllAsForVariables()
{ | TreeSet<VariableType> forVar = new TreeSet<VariableType>(); |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract; | package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false;
private RestrictionBuilder restrictionBuilder = null;
public void setAllAsForVariables()
{
TreeSet<VariableType> forVar = new TreeSet<VariableType>();
for(PredicateExpression expr : this.restrictions) { | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract;
package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false;
private RestrictionBuilder restrictionBuilder = null;
public void setAllAsForVariables()
{
TreeSet<VariableType> forVar = new TreeSet<VariableType>();
for(PredicateExpression expr : this.restrictions) { | for(VariableAbstract var : expr.getVariables()) { |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java | // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract; | package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false;
private RestrictionBuilder restrictionBuilder = null;
public void setAllAsForVariables()
{
TreeSet<VariableType> forVar = new TreeSet<VariableType>();
for(PredicateExpression expr : this.restrictions) {
for(VariableAbstract var : expr.getVariables()) {
if(var instanceof VariableType) {
forVar.add((VariableType) var);
}
}
}
for(IfExpression ifexpr : this.getIfExpressions()) {
for(VariableAbstract var : ifexpr.getAllVariables()) {
if(var instanceof VariableType) {
forVar.add((VariableType) var);
}
}
}
HashSet<VariableType> setset = new HashSet<VariableType>();
for(VariableType fv : forVar) {
setset.add(fv);
}
this.setForVariables(setset);
}
| // Path: src/main/java/com/googlecode/rockit/app/solver/thread/RestrictionBuilder.java
// public abstract class RestrictionBuilder extends Thread
// {
//
// public abstract FormulaHard getFormula();
//
//
// public abstract void generateRestrictions();
//
//
// public abstract void run();
//
//
// public abstract void addConstraints(ILPConnector con) throws ILPException, SolveException;
//
//
// public abstract boolean isFoundOneRestriction();
//
//
// public abstract void foundNoRestriction();
//
//
// public abstract void setTrackLiterals(boolean trackLiterals);
//
//
// public abstract HashMap<Literal, Literal> getLiterals();
//
//
// public abstract void setEvidenceAxioms(HashMap<Literal, Literal> evidence);
//
//
// public abstract void setSql(MySQLConnector sql);
//
//
// public abstract AggregationManager getAggregationManager();
//
//
// public abstract ArrayList<Clause> getClauses();
//
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableAbstract.java
// public abstract class VariableAbstract implements Comparable<VariableAbstract>
// {
// private String name;
// private boolean addToWhere = true;
//
//
// public VariableAbstract()
// {
// }
//
//
// public VariableAbstract(String name)
// {
// this.name = name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// VariableAbstract other = (VariableAbstract) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// public boolean equals(VariableAbstract var)
// {
// if(this == var)
// return true;
// if(var == null)
// return false;
// if(name == null) {
// if(var.name != null)
// return false;
// } else if(!name.equals(var.name))
// return false;
// return true;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// @Override
// public int compareTo(VariableAbstract arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
//
// public boolean addToWhere()
// {
// return addToWhere;
// }
//
//
// public void setAddToWhere(boolean addToWhere)
// {
// this.addToWhere = addToWhere;
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaHard.java
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
import com.googlecode.rockit.app.solver.thread.RestrictionBuilder;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableAbstract;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
import com.googlecode.rockit.javaAPI.predicates.PredicateAbstract;
package com.googlecode.rockit.javaAPI.formulas;
public class FormulaHard extends FormulaAbstract
{
private ArrayList<PredicateExpression> restrictions = new ArrayList<PredicateExpression>();
private boolean conjunction = false;
private RestrictionBuilder restrictionBuilder = null;
public void setAllAsForVariables()
{
TreeSet<VariableType> forVar = new TreeSet<VariableType>();
for(PredicateExpression expr : this.restrictions) {
for(VariableAbstract var : expr.getVariables()) {
if(var instanceof VariableType) {
forVar.add((VariableType) var);
}
}
}
for(IfExpression ifexpr : this.getIfExpressions()) {
for(VariableAbstract var : ifexpr.getAllVariables()) {
if(var instanceof VariableType) {
forVar.add((VariableType) var);
}
}
}
HashSet<VariableType> setset = new HashSet<VariableType>();
for(VariableType fv : forVar) {
setset.add(fv);
}
this.setForVariables(setset);
}
| public FormulaHard(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, ArrayList<PredicateExpression> restrictions, boolean usesConjunctions) throws ParseException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableDouble.java
// public class VariableDouble extends VariableAbstract
// {
// public VariableDouble()
// {
// }
//
//
// public VariableDouble(String name)
// {
// this.setName(name);
// }
//
//
// public String toString()
// {
// return this.getName();
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableDouble;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType; | package com.googlecode.rockit.javaAPI.formulas;
/**
* Defines a soft formular. A soft formular is a conjunction of positive or negative literals
* assigned with a weight.
*
* At the moment this is restricted to a positive weight.
*
*
* @author jan
*
*/
public class FormulaSoft extends FormulaHard
{ | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableDouble.java
// public class VariableDouble extends VariableAbstract
// {
// public VariableDouble()
// {
// }
//
//
// public VariableDouble(String name)
// {
// this.setName(name);
// }
//
//
// public String toString()
// {
// return this.getName();
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
import java.util.ArrayList;
import java.util.HashSet;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableDouble;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
package com.googlecode.rockit.javaAPI.formulas;
/**
* Defines a soft formular. A soft formular is a conjunction of positive or negative literals
* assigned with a weight.
*
* At the moment this is restricted to a positive weight.
*
*
* @author jan
*
*/
public class FormulaSoft extends FormulaHard
{ | private VariableDouble doubleVariable; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableDouble.java
// public class VariableDouble extends VariableAbstract
// {
// public VariableDouble()
// {
// }
//
//
// public VariableDouble(String name)
// {
// this.setName(name);
// }
//
//
// public String toString()
// {
// return this.getName();
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableDouble;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType; | package com.googlecode.rockit.javaAPI.formulas;
/**
* Defines a soft formular. A soft formular is a conjunction of positive or negative literals
* assigned with a weight.
*
* At the moment this is restricted to a positive weight.
*
*
* @author jan
*
*/
public class FormulaSoft extends FormulaHard
{
private VariableDouble doubleVariable;
private Double weight = null;
public FormulaSoft()
{
}
| // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableDouble.java
// public class VariableDouble extends VariableAbstract
// {
// public VariableDouble()
// {
// }
//
//
// public VariableDouble(String name)
// {
// this.setName(name);
// }
//
//
// public String toString()
// {
// return this.getName();
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
import java.util.ArrayList;
import java.util.HashSet;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableDouble;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
package com.googlecode.rockit.javaAPI.formulas;
/**
* Defines a soft formular. A soft formular is a conjunction of positive or negative literals
* assigned with a weight.
*
* At the moment this is restricted to a positive weight.
*
*
* @author jan
*
*/
public class FormulaSoft extends FormulaHard
{
private VariableDouble doubleVariable;
private Double weight = null;
public FormulaSoft()
{
}
| public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableDouble.java
// public class VariableDouble extends VariableAbstract
// {
// public VariableDouble()
// {
// }
//
//
// public VariableDouble(String name)
// {
// this.setName(name);
// }
//
//
// public String toString()
// {
// return this.getName();
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
| import java.util.ArrayList;
import java.util.HashSet;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableDouble;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType; | package com.googlecode.rockit.javaAPI.formulas;
/**
* Defines a soft formular. A soft formular is a conjunction of positive or negative literals
* assigned with a weight.
*
* At the moment this is restricted to a positive weight.
*
*
* @author jan
*
*/
public class FormulaSoft extends FormulaHard
{
private VariableDouble doubleVariable;
private Double weight = null;
public FormulaSoft()
{
}
| // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableDouble.java
// public class VariableDouble extends VariableAbstract
// {
// public VariableDouble()
// {
// }
//
//
// public VariableDouble(String name)
// {
// this.setName(name);
// }
//
//
// public String toString()
// {
// return this.getName();
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
// public class VariableType extends VariableAbstract
// {
// private Type type;
//
//
// public VariableType()
// {
// }
//
//
// public VariableType(String name, Type type)
// {
// this.setName(name);
// this.type = type;
// }
//
//
// public VariableType(String name)
// {
// this.setName(name);
// }
//
//
// public void setType(Type type)
// {
// this.type = type;
//
// }
//
//
// public Type getType()
// {
// return type;
// }
//
//
// public String toString()
// {
// return getName();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
import java.util.ArrayList;
import java.util.HashSet;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.formulas.expressions.IfExpression;
import com.googlecode.rockit.javaAPI.formulas.expressions.impl.PredicateExpression;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableDouble;
import com.googlecode.rockit.javaAPI.formulas.variables.impl.VariableType;
package com.googlecode.rockit.javaAPI.formulas;
/**
* Defines a soft formular. A soft formular is a conjunction of positive or negative literals
* assigned with a weight.
*
* At the moment this is restricted to a positive weight.
*
*
* @author jan
*
*/
public class FormulaSoft extends FormulaHard
{
private VariableDouble doubleVariable;
private Double weight = null;
public FormulaSoft()
{
}
| public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/file/DimacsFileWriter.java | // Path: src/main/java/com/googlecode/rockit/app/solver/pojo/Literal.java
// public class Literal
// {
// private boolean positive;
// private String name;
// // private GRBVar var;
// private int id = -1;
//
//
// public Literal()
// {
// }
//
//
// public Literal(String name, boolean positive)
// {
// this.name = name;
// this.positive = positive;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public boolean isPositive()
// {
// return positive;
// }
//
//
// public void setPositive(boolean positive)
// {
// this.positive = positive;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// Literal other = (Literal) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// // public GRBVar getVar() {
// // return var;
// // }
//
// // public void setVar(GRBVar var) {
// // this.var = var;
// // }
//
// @Override
// public String toString()
// {
// StringBuilder builder = new StringBuilder();
// builder.append("[");
// if(!positive)
// builder.append("! ");
// builder.append(name);
// builder.append("]");
// return builder.toString();
// }
//
//
// public int getId()
// {
// return id;
// }
//
//
// public void setId(int id)
// {
// this.id = id;
// }
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import com.googlecode.rockit.app.solver.pojo.Literal;
import com.googlecode.rockit.exception.ReadOrWriteToFileException; | package com.googlecode.rockit.file;
/**
* From: http://logic.pdmi.ras.ru/~basolver/dimacs.html
*
* This format is widely accepted as the standard format for boolean formulas in CNF. Benchmarks listed on satlib.org, for instance, are in the DIMACS CNF format.
*
* An input file starts with comments (each line starts with c). The number of variables and the number of clauses is defined by the line p cnf variables clauses
*
* Each of the next lines specifies a clause: a positive literal is denoted by the corresponding number, and a negative literal is denoted by the corresponding negative number. The last number in a line should be zero. For example,
*
* c A sample .cnf file.
* p cnf 3 2
* 1 -3 0
* 2 3 -1 0
*
*
* @author jan
*
*/
public class DimacsFileWriter
{
private static MyFileWriter writer;
| // Path: src/main/java/com/googlecode/rockit/app/solver/pojo/Literal.java
// public class Literal
// {
// private boolean positive;
// private String name;
// // private GRBVar var;
// private int id = -1;
//
//
// public Literal()
// {
// }
//
//
// public Literal(String name, boolean positive)
// {
// this.name = name;
// this.positive = positive;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public boolean isPositive()
// {
// return positive;
// }
//
//
// public void setPositive(boolean positive)
// {
// this.positive = positive;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// Literal other = (Literal) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// // public GRBVar getVar() {
// // return var;
// // }
//
// // public void setVar(GRBVar var) {
// // this.var = var;
// // }
//
// @Override
// public String toString()
// {
// StringBuilder builder = new StringBuilder();
// builder.append("[");
// if(!positive)
// builder.append("! ");
// builder.append(name);
// builder.append("]");
// return builder.toString();
// }
//
//
// public int getId()
// {
// return id;
// }
//
//
// public void setId(int id)
// {
// this.id = id;
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/file/DimacsFileWriter.java
import java.util.ArrayList;
import java.util.HashMap;
import com.googlecode.rockit.app.solver.pojo.Literal;
import com.googlecode.rockit.exception.ReadOrWriteToFileException;
package com.googlecode.rockit.file;
/**
* From: http://logic.pdmi.ras.ru/~basolver/dimacs.html
*
* This format is widely accepted as the standard format for boolean formulas in CNF. Benchmarks listed on satlib.org, for instance, are in the DIMACS CNF format.
*
* An input file starts with comments (each line starts with c). The number of variables and the number of clauses is defined by the line p cnf variables clauses
*
* Each of the next lines specifies a clause: a positive literal is denoted by the corresponding number, and a negative literal is denoted by the corresponding negative number. The last number in a line should be zero. For example,
*
* c A sample .cnf file.
* p cnf 3 2
* 1 -3 0
* 2 3 -1 0
*
*
* @author jan
*
*/
public class DimacsFileWriter
{
private static MyFileWriter writer;
| private static HashMap<Literal, Integer> literalMapping = new HashMap<Literal, Integer>(); |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/app/solver/aggregate/AggregationManager.java | // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/SolveException.java
// public class SolveException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public SolveException()
// {
// }
//
//
// public SolveException(String msg)
// {
// super(msg);
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
| import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.exception.ILPException;
import com.googlecode.rockit.exception.SolveException;
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft; | package com.googlecode.rockit.app.solver.aggregate;
public interface AggregationManager
{
public abstract void resetAggregatedSoftFormulas();
/**
* Adds aggregated soft constraints.
*
* These aggregated soft constraints will be included into the gurobi model,
* when solve() is executed.
*
* @param weight
* @param variableNames
* @param mustBePositive
* @param conjunction
* @param id
* @throws ILPException
*/ | // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/SolveException.java
// public class SolveException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public SolveException()
// {
// }
//
//
// public SolveException(String msg)
// {
// super(msg);
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/app/solver/aggregate/AggregationManager.java
import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.exception.ILPException;
import com.googlecode.rockit.exception.SolveException;
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft;
package com.googlecode.rockit.app.solver.aggregate;
public interface AggregationManager
{
public abstract void resetAggregatedSoftFormulas();
/**
* Adds aggregated soft constraints.
*
* These aggregated soft constraints will be included into the gurobi model,
* when solve() is executed.
*
* @param weight
* @param variableNames
* @param mustBePositive
* @param conjunction
* @param id
* @throws ILPException
*/ | public void addClauseForAggregation(Clause clause, FormulaSoft formula); |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/app/solver/aggregate/AggregationManager.java | // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/SolveException.java
// public class SolveException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public SolveException()
// {
// }
//
//
// public SolveException(String msg)
// {
// super(msg);
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
| import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.exception.ILPException;
import com.googlecode.rockit.exception.SolveException;
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft; | package com.googlecode.rockit.app.solver.aggregate;
public interface AggregationManager
{
public abstract void resetAggregatedSoftFormulas();
/**
* Adds aggregated soft constraints.
*
* These aggregated soft constraints will be included into the gurobi model,
* when solve() is executed.
*
* @param weight
* @param variableNames
* @param mustBePositive
* @param conjunction
* @param id
* @throws ILPException
*/
public void addClauseForAggregation(Clause clause, FormulaSoft formula);
| // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/SolveException.java
// public class SolveException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public SolveException()
// {
// }
//
//
// public SolveException(String msg)
// {
// super(msg);
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/app/solver/aggregate/AggregationManager.java
import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.exception.ILPException;
import com.googlecode.rockit.exception.SolveException;
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft;
package com.googlecode.rockit.app.solver.aggregate;
public interface AggregationManager
{
public abstract void resetAggregatedSoftFormulas();
/**
* Adds aggregated soft constraints.
*
* These aggregated soft constraints will be included into the gurobi model,
* when solve() is executed.
*
* @param weight
* @param variableNames
* @param mustBePositive
* @param conjunction
* @param id
* @throws ILPException
*/
public void addClauseForAggregation(Clause clause, FormulaSoft formula);
| public void addConstraintsToILP(ILPConnector connector) throws ILPException, SolveException; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/app/solver/aggregate/AggregationManager.java | // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/SolveException.java
// public class SolveException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public SolveException()
// {
// }
//
//
// public SolveException(String msg)
// {
// super(msg);
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
| import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.exception.ILPException;
import com.googlecode.rockit.exception.SolveException;
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft; | package com.googlecode.rockit.app.solver.aggregate;
public interface AggregationManager
{
public abstract void resetAggregatedSoftFormulas();
/**
* Adds aggregated soft constraints.
*
* These aggregated soft constraints will be included into the gurobi model,
* when solve() is executed.
*
* @param weight
* @param variableNames
* @param mustBePositive
* @param conjunction
* @param id
* @throws ILPException
*/
public void addClauseForAggregation(Clause clause, FormulaSoft formula);
| // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
//
// Path: src/main/java/com/googlecode/rockit/exception/SolveException.java
// public class SolveException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public SolveException()
// {
// }
//
//
// public SolveException(String msg)
// {
// super(msg);
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/app/solver/aggregate/AggregationManager.java
import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.exception.ILPException;
import com.googlecode.rockit.exception.SolveException;
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft;
package com.googlecode.rockit.app.solver.aggregate;
public interface AggregationManager
{
public abstract void resetAggregatedSoftFormulas();
/**
* Adds aggregated soft constraints.
*
* These aggregated soft constraints will be included into the gurobi model,
* when solve() is executed.
*
* @param weight
* @param variableNames
* @param mustBePositive
* @param conjunction
* @param id
* @throws ILPException
*/
public void addClauseForAggregation(Clause clause, FormulaSoft formula);
| public void addConstraintsToILP(ILPConnector connector) throws ILPException, SolveException; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/types/Type.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/Predicate.java
// public class Predicate extends PredicateAbstract
// {
//
// public Predicate()
// {
// }
//
//
// public Predicate(String name, boolean hidden, Type... types) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// for(int i = 0; i < types.length; i++) {
// this.addType(types[i]);
// }
// }
//
//
// public Predicate(String name, boolean hidden) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(String... values) throws ParseException
// {
// if(values.length != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. Add types first."); }
// this.getGroundValues().add(values);
//
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(ArrayList<String> line) throws ParseException
// {
// if(this.getTypes().size() > 0 && line.size() != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. "); }
// String[] e = new String[line.size()];
// for(int i = 0; i < line.size(); i++) {
// e[i] = line.get(i);
// }
// this.getGroundValues().add(e);
// }
//
//
// public Predicate(String name, boolean hidden, ArrayList<Type> types, ArrayList<String[]> groundValues) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// if(groundValues == null) { throw new ParseException("Predicate: " + this.getName() + " - Ground value axiom must not be zero."); }
// if(types == null) { throw new ParseException("Predicate: " + this.getName() + " - Types axiom must not be zero."); }
// /*
// * if(types.size()>0 && groundValues.size()>0 &&groundValues.size()!=types.size()){
// * throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute.");
// * }
// */
// this.setGroundValues(groundValues);
//
// this.setTypes(types);
//
// }
//
//
// @Override
// public String getId()
// {
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuffer sb = new StringBuffer();
// sb.append("// ").append(this.getName()).append("\n");
// // print axioms
// if(this.getGroundValues().size() > 0) {
// for(int i = 0; i < this.getGroundValues().size(); i++) {
// sb.append(this.getName()).append("(");
// String[] groundValue = this.getGroundValues().get(i);
// for(int j = 0; j < groundValue.length; j++) {
// sb.append("\"").append(u.getConstant(groundValue[j])).append("\"");
// if(j < groundValue.length - 1) {
// sb.append(", ");
// }
// }
// sb.append(")\n");
// }
// } else {
// sb.append("// no values");
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// StringBuilder sb = new StringBuilder();
// ArrayList<Type> types = this.getTypes();
//
// sb.append("Predicate " + this.getName() + "P = new Predicate(\"" + this.getName() + "\"," + this.isHidden() + ",");
// for(int i = 0; i < types.size() - 1; i++) {
// sb.append(types.get(i).getName() + "T, ");
// }
// sb.append(types.get(types.size() - 1).getName() + "T");
// sb.append(");\n");
//
// return sb.toString();
// }
// }
| import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.predicates.Predicate; | package com.googlecode.rockit.javaAPI.types;
/**
* Type for config file.
*
* @author jan
*
*/
public class Type implements Comparable<Type>
{
private String name;
| // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/Predicate.java
// public class Predicate extends PredicateAbstract
// {
//
// public Predicate()
// {
// }
//
//
// public Predicate(String name, boolean hidden, Type... types) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// for(int i = 0; i < types.length; i++) {
// this.addType(types[i]);
// }
// }
//
//
// public Predicate(String name, boolean hidden) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(String... values) throws ParseException
// {
// if(values.length != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. Add types first."); }
// this.getGroundValues().add(values);
//
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(ArrayList<String> line) throws ParseException
// {
// if(this.getTypes().size() > 0 && line.size() != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. "); }
// String[] e = new String[line.size()];
// for(int i = 0; i < line.size(); i++) {
// e[i] = line.get(i);
// }
// this.getGroundValues().add(e);
// }
//
//
// public Predicate(String name, boolean hidden, ArrayList<Type> types, ArrayList<String[]> groundValues) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// if(groundValues == null) { throw new ParseException("Predicate: " + this.getName() + " - Ground value axiom must not be zero."); }
// if(types == null) { throw new ParseException("Predicate: " + this.getName() + " - Types axiom must not be zero."); }
// /*
// * if(types.size()>0 && groundValues.size()>0 &&groundValues.size()!=types.size()){
// * throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute.");
// * }
// */
// this.setGroundValues(groundValues);
//
// this.setTypes(types);
//
// }
//
//
// @Override
// public String getId()
// {
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuffer sb = new StringBuffer();
// sb.append("// ").append(this.getName()).append("\n");
// // print axioms
// if(this.getGroundValues().size() > 0) {
// for(int i = 0; i < this.getGroundValues().size(); i++) {
// sb.append(this.getName()).append("(");
// String[] groundValue = this.getGroundValues().get(i);
// for(int j = 0; j < groundValue.length; j++) {
// sb.append("\"").append(u.getConstant(groundValue[j])).append("\"");
// if(j < groundValue.length - 1) {
// sb.append(", ");
// }
// }
// sb.append(")\n");
// }
// } else {
// sb.append("// no values");
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// StringBuilder sb = new StringBuilder();
// ArrayList<Type> types = this.getTypes();
//
// sb.append("Predicate " + this.getName() + "P = new Predicate(\"" + this.getName() + "\"," + this.isHidden() + ",");
// for(int i = 0; i < types.size() - 1; i++) {
// sb.append(types.get(i).getName() + "T, ");
// }
// sb.append(types.get(types.size() - 1).getName() + "T");
// sb.append(");\n");
//
// return sb.toString();
// }
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.predicates.Predicate;
package com.googlecode.rockit.javaAPI.types;
/**
* Type for config file.
*
* @author jan
*
*/
public class Type implements Comparable<Type>
{
private String name;
| private Predicate groundValuesPredicate = null; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/types/Type.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/Predicate.java
// public class Predicate extends PredicateAbstract
// {
//
// public Predicate()
// {
// }
//
//
// public Predicate(String name, boolean hidden, Type... types) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// for(int i = 0; i < types.length; i++) {
// this.addType(types[i]);
// }
// }
//
//
// public Predicate(String name, boolean hidden) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(String... values) throws ParseException
// {
// if(values.length != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. Add types first."); }
// this.getGroundValues().add(values);
//
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(ArrayList<String> line) throws ParseException
// {
// if(this.getTypes().size() > 0 && line.size() != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. "); }
// String[] e = new String[line.size()];
// for(int i = 0; i < line.size(); i++) {
// e[i] = line.get(i);
// }
// this.getGroundValues().add(e);
// }
//
//
// public Predicate(String name, boolean hidden, ArrayList<Type> types, ArrayList<String[]> groundValues) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// if(groundValues == null) { throw new ParseException("Predicate: " + this.getName() + " - Ground value axiom must not be zero."); }
// if(types == null) { throw new ParseException("Predicate: " + this.getName() + " - Types axiom must not be zero."); }
// /*
// * if(types.size()>0 && groundValues.size()>0 &&groundValues.size()!=types.size()){
// * throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute.");
// * }
// */
// this.setGroundValues(groundValues);
//
// this.setTypes(types);
//
// }
//
//
// @Override
// public String getId()
// {
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuffer sb = new StringBuffer();
// sb.append("// ").append(this.getName()).append("\n");
// // print axioms
// if(this.getGroundValues().size() > 0) {
// for(int i = 0; i < this.getGroundValues().size(); i++) {
// sb.append(this.getName()).append("(");
// String[] groundValue = this.getGroundValues().get(i);
// for(int j = 0; j < groundValue.length; j++) {
// sb.append("\"").append(u.getConstant(groundValue[j])).append("\"");
// if(j < groundValue.length - 1) {
// sb.append(", ");
// }
// }
// sb.append(")\n");
// }
// } else {
// sb.append("// no values");
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// StringBuilder sb = new StringBuilder();
// ArrayList<Type> types = this.getTypes();
//
// sb.append("Predicate " + this.getName() + "P = new Predicate(\"" + this.getName() + "\"," + this.isHidden() + ",");
// for(int i = 0; i < types.size() - 1; i++) {
// sb.append(types.get(i).getName() + "T, ");
// }
// sb.append(types.get(types.size() - 1).getName() + "T");
// sb.append(");\n");
//
// return sb.toString();
// }
// }
| import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.predicates.Predicate; | package com.googlecode.rockit.javaAPI.types;
/**
* Type for config file.
*
* @author jan
*
*/
public class Type implements Comparable<Type>
{
private String name;
private Predicate groundValuesPredicate = null;
// private int groundValueSize = 0;
public Type()
{
}
public Type(String name)
{
this.setName(name);
}
| // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/Predicate.java
// public class Predicate extends PredicateAbstract
// {
//
// public Predicate()
// {
// }
//
//
// public Predicate(String name, boolean hidden, Type... types) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// for(int i = 0; i < types.length; i++) {
// this.addType(types[i]);
// }
// }
//
//
// public Predicate(String name, boolean hidden) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(String... values) throws ParseException
// {
// if(values.length != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. Add types first."); }
// this.getGroundValues().add(values);
//
// }
//
//
// /**
// * Add one line to the ground atoms.
// *
// * Note that the size of the line attribut has to be equal to the
// * types attribute.
// *
// * @param line
// * @throws ParseException
// */
// public void addGroundValueLine(ArrayList<String> line) throws ParseException
// {
// if(this.getTypes().size() > 0 && line.size() != this.getTypes().size()) { throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute. "); }
// String[] e = new String[line.size()];
// for(int i = 0; i < line.size(); i++) {
// e[i] = line.get(i);
// }
// this.getGroundValues().add(e);
// }
//
//
// public Predicate(String name, boolean hidden, ArrayList<Type> types, ArrayList<String[]> groundValues) throws ParseException
// {
// this.setName(name);
// this.setHidden(hidden);
// if(groundValues == null) { throw new ParseException("Predicate: " + this.getName() + " - Ground value axiom must not be zero."); }
// if(types == null) { throw new ParseException("Predicate: " + this.getName() + " - Types axiom must not be zero."); }
// /*
// * if(types.size()>0 && groundValues.size()>0 &&groundValues.size()!=types.size()){
// * throw new ParseException("Predicate: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute.");
// * }
// */
// this.setGroundValues(groundValues);
//
// this.setTypes(types);
//
// }
//
//
// @Override
// public String getId()
// {
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuffer sb = new StringBuffer();
// sb.append("// ").append(this.getName()).append("\n");
// // print axioms
// if(this.getGroundValues().size() > 0) {
// for(int i = 0; i < this.getGroundValues().size(); i++) {
// sb.append(this.getName()).append("(");
// String[] groundValue = this.getGroundValues().get(i);
// for(int j = 0; j < groundValue.length; j++) {
// sb.append("\"").append(u.getConstant(groundValue[j])).append("\"");
// if(j < groundValue.length - 1) {
// sb.append(", ");
// }
// }
// sb.append(")\n");
// }
// } else {
// sb.append("// no values");
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// StringBuilder sb = new StringBuilder();
// ArrayList<Type> types = this.getTypes();
//
// sb.append("Predicate " + this.getName() + "P = new Predicate(\"" + this.getName() + "\"," + this.isHidden() + ",");
// for(int i = 0; i < types.size() - 1; i++) {
// sb.append(types.get(i).getName() + "T, ");
// }
// sb.append(types.get(types.size() - 1).getName() + "T");
// sb.append(");\n");
//
// return sb.toString();
// }
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.predicates.Predicate;
package com.googlecode.rockit.javaAPI.types;
/**
* Type for config file.
*
* @author jan
*
*/
public class Type implements Comparable<Type>
{
private String name;
private Predicate groundValuesPredicate = null;
// private int groundValueSize = 0;
public Type()
{
}
public Type(String name)
{
this.setName(name);
}
| public Type(String name, Predicate groundValuesPredicate) throws ParseException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/app/learner/FormulaForLearning.java | // Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
| import com.googlecode.rockit.javaAPI.formulas.FormulaSoft; | package com.googlecode.rockit.app.learner;
public class FormulaForLearning
{
| // Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/FormulaSoft.java
// public class FormulaSoft extends FormulaHard
// {
// private VariableDouble doubleVariable;
// private Double weight = null;
//
//
// public FormulaSoft()
// {
// }
//
//
// public FormulaSoft(String name, HashSet<VariableType> forVariables, ArrayList<IfExpression> ifExpressions, VariableDouble doubleVariable, ArrayList<PredicateExpression> restrictions, boolean usesConjunction) throws ParseException
// {
// this.setForVariables(forVariables);
// this.setName(name);
// this.setIfExpressions(ifExpressions);
// this.setDoubleVariable(doubleVariable);
// this.setRestrictions(restrictions);
// if(usesConjunction) {
// this.setConjunction();
// } else {
// this.setDisjunction();
// }
// }
//
//
// public Double getWeight()
// {
// return weight;
// }
//
//
// public void setDoubleVariable(VariableDouble doubleVariable)
// {
// this.doubleVariable = doubleVariable;
// }
//
//
// public VariableDouble getDoubleVariable()
// {
// return doubleVariable;
// }
//
//
// public void setWeight(Double weight)
// {
// this.weight = weight;
// }
//
//
// public String toString()
// {
// StringBuilder sb = new StringBuilder();
// if(weight != null)
// sb.append(this.getWeight());
// if(doubleVariable != null)
// sb.append(this.doubleVariable.toString()).append(":");
// sb.append(" ");
//
// sb.append(super.toSuperString());
//
// if(this.isConjunction())
// sb.append("(");
// int i = 0;
// for(PredicateExpression restriction : this.getRestrictions()) {
// sb.append(restriction.toString());
// if(i < (this.getRestrictions().size() - 1)) {
// if(this.isConjunction()) {
// sb.append(" n ");
// } else {
// sb.append(" v ");
// }
// }
// i++;
// }
// if(this.isConjunction())
// sb.append(")");
// /*
// * if(this.doubleVariable!= null){
// * sb.append(" * ");
// * sb.append(this.doubleVariable.toString());
// * }
// */
// sb.append("\n");
// return sb.toString();
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/app/learner/FormulaForLearning.java
import com.googlecode.rockit.javaAPI.formulas.FormulaSoft;
package com.googlecode.rockit.app.learner;
public class FormulaForLearning
{
| private FormulaSoft formula; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/app/solver/exact/GroundingSet.java | // Path: src/main/java/com/googlecode/rockit/app/solver/pojo/Literal.java
// public class Literal
// {
// private boolean positive;
// private String name;
// // private GRBVar var;
// private int id = -1;
//
//
// public Literal()
// {
// }
//
//
// public Literal(String name, boolean positive)
// {
// this.name = name;
// this.positive = positive;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public boolean isPositive()
// {
// return positive;
// }
//
//
// public void setPositive(boolean positive)
// {
// this.positive = positive;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// Literal other = (Literal) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// // public GRBVar getVar() {
// // return var;
// // }
//
// // public void setVar(GRBVar var) {
// // this.var = var;
// // }
//
// @Override
// public String toString()
// {
// StringBuilder builder = new StringBuilder();
// builder.append("[");
// if(!positive)
// builder.append("! ");
// builder.append(name);
// builder.append("]");
// return builder.toString();
// }
//
//
// public int getId()
// {
// return id;
// }
//
//
// public void setId(int id)
// {
// this.id = id;
// }
//
// }
| import java.math.BigInteger;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.app.solver.pojo.Literal; | package com.googlecode.rockit.app.solver.exact;
/**
*
* @author Bernd
*
*/
@SuppressWarnings ("serial")
public class GroundingSet extends BitSet implements Iterable<GroundingSet>
{
private static final boolean debug = true;
| // Path: src/main/java/com/googlecode/rockit/app/solver/pojo/Literal.java
// public class Literal
// {
// private boolean positive;
// private String name;
// // private GRBVar var;
// private int id = -1;
//
//
// public Literal()
// {
// }
//
//
// public Literal(String name, boolean positive)
// {
// this.name = name;
// this.positive = positive;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public boolean isPositive()
// {
// return positive;
// }
//
//
// public void setPositive(boolean positive)
// {
// this.positive = positive;
// }
//
//
// @Override
// public int hashCode()
// {
// final int prime = 31;
// int result = 1;
// result = prime * result + ((name == null) ? 0 : name.hashCode());
// return result;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(this == obj)
// return true;
// if(obj == null)
// return false;
// if(getClass() != obj.getClass())
// return false;
// Literal other = (Literal) obj;
// if(name == null) {
// if(other.name != null)
// return false;
// } else if(!name.equals(other.name))
// return false;
// return true;
// }
//
//
// // public GRBVar getVar() {
// // return var;
// // }
//
// // public void setVar(GRBVar var) {
// // this.var = var;
// // }
//
// @Override
// public String toString()
// {
// StringBuilder builder = new StringBuilder();
// builder.append("[");
// if(!positive)
// builder.append("! ");
// builder.append(name);
// builder.append("]");
// return builder.toString();
// }
//
//
// public int getId()
// {
// return id;
// }
//
//
// public void setId(int id)
// {
// this.id = id;
// }
//
// }
// Path: src/main/java/com/googlecode/rockit/app/solver/exact/GroundingSet.java
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.googlecode.rockit.app.solver.pojo.Clause;
import com.googlecode.rockit.app.solver.pojo.Literal;
package com.googlecode.rockit.app.solver.exact;
/**
*
* @author Bernd
*
*/
@SuppressWarnings ("serial")
public class GroundingSet extends BitSet implements Iterable<GroundingSet>
{
private static final boolean debug = true;
| private Literal[] literals; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/conn/ilp/cplex/CplexConnector.java | // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
| import ilog.concert.IloException;
import ilog.concert.IloLinearNumExpr;
import ilog.concert.IloNumVar;
import ilog.concert.IloNumVarType;
import ilog.cplex.IloCplex;
import ilog.cplex.IloCplex.UnknownObjectException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.conn.ilp.ILPOperator;
import com.googlecode.rockit.conn.ilp.ILPVariable;
import com.googlecode.rockit.exception.ILPException; | package com.googlecode.rockit.conn.ilp.cplex;
public class CplexConnector extends ILPConnector
{
private IloCplex cplex;
private Map<String, IloNumVar> variables = new HashMap<String, IloNumVar>();
private Map<String, Double> objective = new HashMap<String, Double>();
| // Path: src/main/java/com/googlecode/rockit/exception/ILPException.java
// public class ILPException extends SolveException
// {
// /**
// * When the ilp is infeasible, this exception occurs.
// */
// private static final long serialVersionUID = -4390221337485101364L;
//
//
// public ILPException()
// {
// }
//
//
// public ILPException(String msg)
// {
// super(msg);
// }
// }
// Path: src/main/java/com/googlecode/rockit/conn/ilp/cplex/CplexConnector.java
import ilog.concert.IloException;
import ilog.concert.IloLinearNumExpr;
import ilog.concert.IloNumVar;
import ilog.concert.IloNumVarType;
import ilog.cplex.IloCplex;
import ilog.cplex.IloCplex.UnknownObjectException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.googlecode.rockit.conn.ilp.ILPConnector;
import com.googlecode.rockit.conn.ilp.ILPOperator;
import com.googlecode.rockit.conn.ilp.ILPVariable;
import com.googlecode.rockit.exception.ILPException;
package com.googlecode.rockit.conn.ilp.cplex;
public class CplexConnector extends ILPConnector
{
private IloCplex cplex;
private Map<String, IloNumVar> variables = new HashMap<String, IloNumVar>();
private Map<String, Double> objective = new HashMap<String, Double>();
| public CplexConnector() throws ILPException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java | // Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
| import com.googlecode.rockit.javaAPI.types.Type; | package com.googlecode.rockit.javaAPI.formulas.variables.impl;
public class VariableType extends VariableAbstract
{ | // Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/formulas/variables/impl/VariableType.java
import com.googlecode.rockit.javaAPI.types.Type;
package com.googlecode.rockit.javaAPI.formulas.variables.impl;
public class VariableType extends VariableAbstract
{ | private Type type; |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/predicates/PredicateDouble.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
| import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.types.Type; | package com.googlecode.rockit.javaAPI.predicates;
/**
* This predicate also has the possibility to has one array of double values
*
* @author jan
*
*/
public class PredicateDouble extends PredicateAbstract
{
private ArrayList<Double> doubleValues = new ArrayList<Double>();
public ArrayList<Double> getDoubleValues()
{
return doubleValues;
}
public void setDoubleValues(ArrayList<Double> doubleValues)
{
this.doubleValues = doubleValues;
}
public PredicateDouble()
{
}
public PredicateDouble(String name, boolean hidden)
{
this.setHidden(hidden);
this.setName(name);
}
/**
* In the groundvalues, the last position of the Array contains the double value (encoded as string).
*
*/ | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/PredicateDouble.java
import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.types.Type;
package com.googlecode.rockit.javaAPI.predicates;
/**
* This predicate also has the possibility to has one array of double values
*
* @author jan
*
*/
public class PredicateDouble extends PredicateAbstract
{
private ArrayList<Double> doubleValues = new ArrayList<Double>();
public ArrayList<Double> getDoubleValues()
{
return doubleValues;
}
public void setDoubleValues(ArrayList<Double> doubleValues)
{
this.doubleValues = doubleValues;
}
public PredicateDouble()
{
}
public PredicateDouble(String name, boolean hidden)
{
this.setHidden(hidden);
this.setName(name);
}
/**
* In the groundvalues, the last position of the Array contains the double value (encoded as string).
*
*/ | public void setGroundAndDoubleValues(ArrayList<String[]> groundValues) throws ParseException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/predicates/PredicateDouble.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
| import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.types.Type; | return;
if((this.getTypes().size() > 0) && groundValues.get(0).length != this.getTypes().size() + 1) {
for(String[] s : groundValues) {
for(String ss : s) {
System.out.print(ss);
System.out.print(",");
}
System.out.println();
}
throw new ParseException("PredicateDouble: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute.");
}
this.doubleValues = new ArrayList<Double>();
this.setGroundValues(new ArrayList<String[]>());
for(String[] sArray : groundValues) {
int lastPos = sArray.length - 1;
double value = 0;
try {
value = Double.parseDouble(sArray[lastPos]);
} catch(NumberFormatException e) {
throw new ParseException("In PrdicateDouble " + this.getName() + " is a Double value which can not be parsed to a double number: " + sArray[lastPos]);
}
String[] groundV = new String[lastPos];
for(int i = 0; i < lastPos; i++) {
groundV[i] = sArray[i];
}
this.addGroundValueLine(value, groundV);
}
}
| // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/PredicateDouble.java
import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.types.Type;
return;
if((this.getTypes().size() > 0) && groundValues.get(0).length != this.getTypes().size() + 1) {
for(String[] s : groundValues) {
for(String ss : s) {
System.out.print(ss);
System.out.print(",");
}
System.out.println();
}
throw new ParseException("PredicateDouble: " + this.getName() + " - The size of the line input has to be equal to the size of the types attribute.");
}
this.doubleValues = new ArrayList<Double>();
this.setGroundValues(new ArrayList<String[]>());
for(String[] sArray : groundValues) {
int lastPos = sArray.length - 1;
double value = 0;
try {
value = Double.parseDouble(sArray[lastPos]);
} catch(NumberFormatException e) {
throw new ParseException("In PrdicateDouble " + this.getName() + " is a Double value which can not be parsed to a double number: " + sArray[lastPos]);
}
String[] groundV = new String[lastPos];
for(int i = 0; i < lastPos; i++) {
groundV[i] = sArray[i];
}
this.addGroundValueLine(value, groundV);
}
}
| public PredicateDouble(String name, boolean hidden, Type... types) throws ParseException |
jnoessner/rockIt | src/main/java/com/googlecode/rockit/javaAPI/predicates/Predicate.java | // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
| import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.types.Type; | package com.googlecode.rockit.javaAPI.predicates;
public class Predicate extends PredicateAbstract
{
public Predicate()
{
}
| // Path: src/main/java/com/googlecode/rockit/exception/ParseException.java
// public class ParseException extends Exception
// {
//
// /**
// * Exceptions which can occur in the Parse Phase of the application.
// */
// private static final long serialVersionUID = -4390051337485101364L;
//
//
// public ParseException()
// {
// }
//
//
// public ParseException(String msg)
// {
// super(Messages.printParseExceptionError(msg));
// }
//
// }
//
// Path: src/main/java/com/googlecode/rockit/javaAPI/types/Type.java
// public class Type implements Comparable<Type>
// {
// private String name;
//
// private Predicate groundValuesPredicate = null;
//
//
// // private int groundValueSize = 0;
//
// public Type()
// {
// }
//
//
// public Type(String name)
// {
// this.setName(name);
// }
//
//
// public Type(String name, Predicate groundValuesPredicate) throws ParseException
// {
// this.setName(name);
// this.setGroundValuesPredicate(groundValuesPredicate);
// }
//
//
// /**
// * Sets the ground values of the current type to those of the given predicate.
// *
// * If the predicate has more than one "row" in ground values (e.g. more than one Type assignment),
// * an exception is thrown.
// *
// * @param predicate
// * @throws ParseException
// */
// public void setGroundValuesPredicate(Predicate predicate) throws ParseException
// {
// if(predicate == null) { throw new ParseException("Predicates must not equal null when added to type. You tried to add a null predicate to type " + this.getName()); }
// if(predicate.getTypes().size() > 1) { throw new ParseException("Predicates which are used to set ground values must not have more than one type. This happens when trying to assign predicate " + predicate.getName() + " to type " + this.getName()); }
// this.groundValuesPredicate = predicate;
// }
//
//
// public ArrayList<String[]> getGroundValues()
// {
// return groundValuesPredicate.getGroundValues();
// }
//
//
// public Predicate getGroundValuesPredicate()
// {
// return groundValuesPredicate;
// }
//
//
// @Override
// public boolean equals(Object obj)
// {
// if(obj.getClass() == Type.class) {
// Type t = (Type) obj;
// return t.getName().equals(this.getName());
// } else {
// return false;
// }
// }
//
//
// public String getId()
// {
//
// return this.getClass().getName();
// }
//
//
// public String toLongString()
// {
// StringBuilder sb = new StringBuilder();
// sb.append("> type ").append(this.getName()).append("\n");
// if(this.groundValuesPredicate != null) {
// for(String[] s : this.groundValuesPredicate.getGroundValues()) {
// sb.append("\"" + s[0] + "\"\n");
// }
// }
// return sb.toString();
// }
//
//
// public String output()
// {
// String result = "Type " + this.getName() + "T = new Type(\"" + this.getName() + "\");\n";
// if(this.groundValuesPredicate != null) {
// result = result + this.getName() + ".values = " + this.getGroundValuesPredicate().getName();
// }
// return result;
//
// }
//
//
// public void setName(String name)
// {
// this.name = name;
// }
//
//
// public String getName()
// {
// return name;
// }
//
//
// public String toString()
// {
// return name;
// }
//
//
// public String toMediumString()
// {
// return "type " + name + ";";
// }
//
//
// @Override
// public int compareTo(Type arg0)
// {
// return this.name.compareTo(arg0.getName());
// }
//
// /*
// * public int getGroundValueSize() throws ParseException {
// * if(this.groundValuesPredicate==null){
// * throw new ParseException("Can not determine the size if no ground values predicate is set. Type name: " + this.name);
// * }
// * if(groundValueSize==0){
// * for(String[] p:groundValuesPredicate.getGroundValues()){
// * groundValueSize = Math.max(groundValueSize, p[0].length());
// * }
// * }
// * return groundValueSize;
// * }
// */
// }
// Path: src/main/java/com/googlecode/rockit/javaAPI/predicates/Predicate.java
import java.util.ArrayList;
import com.googlecode.rockit.exception.ParseException;
import com.googlecode.rockit.javaAPI.types.Type;
package com.googlecode.rockit.javaAPI.predicates;
public class Predicate extends PredicateAbstract
{
public Predicate()
{
}
| public Predicate(String name, boolean hidden, Type... types) throws ParseException |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.