<commit_before>package org.genericsystem.reactor.appserver;

import io.vertx.core.json.JsonObject;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
import org.genericsystem.common.AbstractRoot;
import org.genericsystem.common.EnginesDeploymentConfig.EngineDeploymentConfig;
import org.genericsystem.common.Generic;
import org.genericsystem.common.Statics;
import org.genericsystem.reactor.HtmlElement;
import org.genericsystem.reactor.Model;
import org.genericsystem.reactor.html.HtmlApp;

/**
 * @author <NAME>
 *
 */
public class ApplicationsDeploymentConfig extends JsonObject {

	public ApplicationsDeploymentConfig() {
		this(Statics.DEFAULT_HOST, Statics.DEFAULT_PORT);
	}

	public ApplicationsDeploymentConfig(String host, int port) {
		put("apps", new JsonObject());
		put("host", host);
		put("port", port);
	}

	public String getHost() {
		return getString("host");
	}

	public int getPort() {
		return getInteger("port");
	}

	public Set<String> getApplicationsPaths() {
		return getJsonObject("apps").getMap().keySet();
	}

	public Class<? extends HtmlApp<?>> getApplicationClass(String applicationPath) {
		return getApplicationDeploymentConfig(applicationPath).getHtmlAppClass();
	}

	private ApplicationDeploymentConfig getApplicationDeploymentConfig(String applicationPath) {
		return applicationDeploymentConfig(getJsonObject("apps").getJsonObject(applicationPath));
	}

	private ApplicationDeploymentConfig applicationDeploymentConfig(JsonObject json) {
		return new ApplicationDeploymentConfig(json.getMap());
	}

	public ApplicationsDeploymentConfig addApplication(String path, Class<? extends HtmlElement<?, ?, ?>> clazz, String persistentDirectoryPath,
			Class<?>... classes) {
		getJsonObject("apps").put(path, new ApplicationDeploymentConfig(clazz, persistentDirectoryPath, classes));
		return this;
	}

	public void removeApplication(String path) {
		getJsonObject("apps").remove(path);
	}

	public Set<Class<?>> getClasses(String persistentDirectoryPath) {
		return getJsonObject("apps").getMap().values().stream().map(json -> applicationDeploymentConfig((JsonObject) json))
				.filter(conf -> Objects.equals(persistentDirectoryPath, conf.getPersistentDirectoryPath())).flatMap(conf -> conf.getClasses().stream())
				.collect(Collectors.toSet());
	}

	public Set<String> getPersistentDirectoryPaths() {
		return getJsonObject("apps").getMap().keySet().stream().map(this::getPersistentDirectoryPath).collect(Collectors.toSet());
	}

	public String getPersistentDirectoryPath(String applicationPath) {
		return getApplicationDeploymentConfig(applicationPath).getPersistentDirectoryPath();
	}

	public static class ApplicationDeploymentConfig extends EngineDeploymentConfig {
		public ApplicationDeploymentConfig(Map<String, Object> map) {
			super(map);
			assert getString("applicationClass") != null;
		}

		public ApplicationDeploymentConfig(Class<? extends HtmlElement<?, ?, ?>> applicationClass, String repositoryPath, Class<?>... classes) {
			super(repositoryPath, classes);
			put("applicationClass", applicationClass.getName());
		}

		@SuppressWarnings("unchecked")
		public Class<? extends HtmlApp<?>> getHtmlAppClass() {
			try {
				return (Class<? extends HtmlApp<?>>) Class.forName(getString("applicationClass"));
			} catch (ClassNotFoundException e) {
				throw new IllegalStateException(e);
			}
		}
	}

	public static class DefaultPathSingleWebAppDeployment extends ApplicationsDeploymentConfig {
		public DefaultPathSingleWebAppDeployment(Class<? extends HtmlApp<?>> htmlApp, Class<?>... classes) {
			addApplication("/", htmlApp, null, classes);
		}

		public DefaultPathSingleWebAppDeployment(Class<? extends HtmlApp<?>> htmlApp, String persistentDirectoryPath, Class<?>... classes) {
			addApplication("/", htmlApp, persistentDirectoryPath, classes);
		}
	}

	public Class<? extends Model> getModelClass(String applicationPath) {
		TODO
	}
}
<commit_msg>Unstable<commit_after>package org.genericsystem.reactor.appserver;

import io.vertx.core.json.JsonObject;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.genericsystem.common.EnginesDeploymentConfig.EngineDeploymentConfig;
import org.genericsystem.common.Statics;
import org.genericsystem.reactor.HtmlElement;
import org.genericsystem.reactor.Model;
import org.genericsystem.reactor.html.HtmlApp;

/**
 * @author <NAME>
 *
 */
public class ApplicationsDeploymentConfig extends JsonObject {

	public ApplicationsDeploymentConfig() {
		this(Statics.DEFAULT_HOST, Statics.DEFAULT_PORT);
	}

	public ApplicationsDeploymentConfig(String host, int port) {
		put("apps", new JsonObject());
		put("host", host);
		put("port", port);
	}

	public String getHost() {
		return getString("host");
	}

	public int getPort() {
		return getInteger("port");
	}

	public Set<String> getApplicationsPaths() {
		return getJsonObject("apps").getMap().keySet();
	}

	public Class<? extends HtmlApp<?>> getApplicationClass(String applicationPath) {
		return getApplicationDeploymentConfig(applicationPath).getHtmlAppClass();
	}

	public Class<? extends Model> getModelClass(String applicationPath) {
		return getApplicationDeploymentConfig(applicationPath).getModelClass();
	}

	private ApplicationDeploymentConfig getApplicationDeploymentConfig(String applicationPath) {
		return applicationDeploymentConfig(getJsonObject("apps").getJsonObject(applicationPath));
	}

	private ApplicationDeploymentConfig applicationDeploymentConfig(JsonObject json) {
		return new ApplicationDeploymentConfig(json.getMap());
	}

	public ApplicationsDeploymentConfig addApplication(String path, Class<? extends HtmlElement<?, ?, ?>> htmlAppClass, Class<? extends Model> modelClass,
			String persistentDirectoryPath, Class<?>... classes) {
		getJsonObject("apps").put(path, new ApplicationDeploymentConfig(htmlAppClass, modelClass, persistentDirectoryPath, classes));
		return this;
	}

	public void removeApplication(String path) {
		getJsonObject("apps").remove(path);
	}

	public Set<Class<?>> getClasses(String persistentDirectoryPath) {
		return getJsonObject("apps").getMap().values().stream().map(json -> applicationDeploymentConfig((JsonObject) json))
				.filter(conf -> Objects.equals(persistentDirectoryPath, conf.getPersistentDirectoryPath())).flatMap(conf -> conf.getClasses().stream())
				.collect(Collectors.toSet());
	}

	public Set<String> getPersistentDirectoryPaths() {
		return getJsonObject("apps").getMap().keySet().stream().map(this::getPersistentDirectoryPath).collect(Collectors.toSet());
	}

	public String getPersistentDirectoryPath(String applicationPath) {
		return getApplicationDeploymentConfig(applicationPath).getPersistentDirectoryPath();
	}

	public static class ApplicationDeploymentConfig extends EngineDeploymentConfig {
		public ApplicationDeploymentConfig(Map<String, Object> map) {
			super(map);
			assert getString("applicationClass") != null;
		}

		public ApplicationDeploymentConfig(Class<? extends HtmlElement<?, ?, ?>> applicationClass, Class<? extends Model> modelClass, String repositoryPath,
				Class<?>... classes) {
			super(repositoryPath, classes);
			put("applicationClass", applicationClass.getName());
			put("modelClass", applicationClass.getName());
		}

		@SuppressWarnings("unchecked")
		public Class<? extends HtmlApp<?>> getHtmlAppClass() {
			try {
				return (Class<? extends HtmlApp<?>>) Class.forName(getString("applicationClass"));
			} catch (ClassNotFoundException e) {
				throw new IllegalStateException(e);
			}
		}

		@SuppressWarnings("unchecked")
		public Class<? extends Model> getModelClass() {
			try {
				return (Class<? extends Model>) Class.forName(getString("modelClass"));
			} catch (ClassNotFoundException e) {
				throw new IllegalStateException(e);
			}
		}
	}

	public static class DefaultPathSingleWebAppDeployment extends ApplicationsDeploymentConfig {
		public DefaultPathSingleWebAppDeployment(Class<? extends HtmlApp<?>> htmlAppClass, Class<? extends Model> modelClass, Class<?>... classes) {
			addApplication("/", htmlAppClass, modelClass, null, classes);
		}

		public DefaultPathSingleWebAppDeployment(Class<? extends HtmlApp<?>> htmlAppClass, Class<? extends Model> modelClass, String persistentDirectoryPath,
				Class<?>... classes) {
			addApplication("/", htmlAppClass, modelClass, persistentDirectoryPath, classes);
		}
	}
}

{'fraction_non_alphanumeric': 0.12197139817988417, 'fraction_numerical': 0.0, 'mean_word_length': 6.541889483065954, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7396644', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2308, 'n_words': 468}