Before the dawn
This commit is contained in:
12
.gitattributes
vendored
Normal file
12
.gitattributes
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#
|
||||||
|
# https://help.github.com/articles/dealing-with-line-endings/
|
||||||
|
#
|
||||||
|
# Linux start script should use lf
|
||||||
|
/gradlew text eol=lf
|
||||||
|
|
||||||
|
# These are Windows script files and should use crlf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
|
||||||
|
# Binary files should be left untouched
|
||||||
|
*.jar binary
|
||||||
|
|
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Ignore Gradle project-specific cache directory
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# Ignore Gradle build output directory
|
||||||
|
build
|
||||||
|
|
||||||
|
app/bin
|
||||||
|
app/build
|
28
.project
Normal file
28
.project
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>lab5-test</name>
|
||||||
|
<comment>Project lab5-test created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1743511323199</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
|
</projectDescription>
|
2
.settings/org.eclipse.buildship.core.prefs
Normal file
2
.settings/org.eclipse.buildship.core.prefs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=app
|
||||||
|
eclipse.preferences.version=1
|
18
app/.classpath
Normal file
18
app/.classpath
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="gradle_scope" value="main"/>
|
||||||
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="gradle_scope" value="main"/>
|
||||||
|
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||||
|
<classpathentry kind="output" path="bin/default"/>
|
||||||
|
</classpath>
|
34
app/.project
Normal file
34
app/.project
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>app</name>
|
||||||
|
<comment>Project app created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1743511323190</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
|
</projectDescription>
|
13
app/.settings/org.eclipse.buildship.core.prefs
Normal file
13
app/.settings/org.eclipse.buildship.core.prefs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
arguments=--init-script /home/oxff/.cache/jdtls/config/org.eclipse.osgi/58/0/.cp/gradle/init/init.gradle
|
||||||
|
auto.sync=false
|
||||||
|
build.scans.enabled=false
|
||||||
|
connection.gradle.distribution=GRADLE_DISTRIBUTION(LOCAL_INSTALLATION(/usr/share/java/gradle))
|
||||||
|
connection.project.dir=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
gradle.user.home=
|
||||||
|
java.home=/usr/lib/jvm/java-21-openjdk
|
||||||
|
jvm.arguments=
|
||||||
|
offline.mode=false
|
||||||
|
override.workspace.settings=true
|
||||||
|
show.console.view=true
|
||||||
|
show.executions.view=true
|
4
app/.settings/org.eclipse.jdt.core.prefs
Normal file
4
app/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=21
|
||||||
|
org.eclipse.jdt.core.compiler.source=21
|
46
app/build.gradle
Normal file
46
app/build.gradle
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* This file was generated by the Gradle 'init' task.
|
||||||
|
*
|
||||||
|
* This generated file contains a sample Java application project to get you started.
|
||||||
|
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.13/userguide/building_java_projects.html in the Gradle documentation.
|
||||||
|
* This project uses @Incubating APIs which are subject to change.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
|
id 'application'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Use Maven Central for resolving dependencies.
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// This dependency is used by the application.
|
||||||
|
implementation libs.guava
|
||||||
|
}
|
||||||
|
|
||||||
|
testing {
|
||||||
|
suites {
|
||||||
|
// Configure the built-in test suite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply a specific Java toolchain to ease working on different environments.
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(21)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
// Define the main class for the application.
|
||||||
|
mainClass = 'itmo.lab5.App'
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes 'Main-Class': application.mainClass
|
||||||
|
}
|
||||||
|
}
|
112
app/src/main/java/itmo/lab5/App.java
Normal file
112
app/src/main/java/itmo/lab5/App.java
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
package itmo.lab5;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.InvalidPathException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.*;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandBuilder;
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.cli.CommandRegistry;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.cli.commands.*;
|
||||||
|
import itmo.lab5.models.Flat;
|
||||||
|
import itmo.lab5.parser.Reader;
|
||||||
|
import itmo.lab5.cli.helpers.History;
|
||||||
|
|
||||||
|
public class App {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(FileHandler.class.getName());
|
||||||
|
|
||||||
|
public static void main(String[] g_args) {
|
||||||
|
Path dataFilePath = null;
|
||||||
|
var history = new History();
|
||||||
|
var flats = new HashMap<Integer, Flat>();
|
||||||
|
|
||||||
|
CommandContext context = new CommandContext();
|
||||||
|
CommandRegistry registry = new CommandBuilder()
|
||||||
|
.register("exit", new ExitCommand())
|
||||||
|
.register("help", new HelpCommand())
|
||||||
|
.register("info", new InfoCommand())
|
||||||
|
.register("clear", new ClearCommand())
|
||||||
|
.register("show", new ShowCommand())
|
||||||
|
.register("remove_key", new RemoveKeyCommand())
|
||||||
|
.register("history", new HistoryCommand())
|
||||||
|
.register("insert", new InsertCommand())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
dataFilePath = getDataFileFromEnv("LAB5_DATA");
|
||||||
|
flats = new Reader().parseCSV(dataFilePath.toFile());
|
||||||
|
} catch (IllegalArgumentException | IOException e) {
|
||||||
|
LOGGER.log(Level.WARNING, "There's error while loading file: " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.set("registry", registry);
|
||||||
|
context.set("collection", flats);
|
||||||
|
context.set("history", history);
|
||||||
|
|
||||||
|
var scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
System.out.print("> ");
|
||||||
|
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String[] args = input.split(" ");
|
||||||
|
String commandName = args[0];
|
||||||
|
Command command = registry.getByName(commandName);
|
||||||
|
|
||||||
|
if (command != null) {
|
||||||
|
history.add(commandName);
|
||||||
|
var localArgs = args.length > 1 ? java.util.Arrays.copyOfRange(args, 1, args.length) : new String[0];
|
||||||
|
var response = command.execute(localArgs, context);
|
||||||
|
System.out.println(response);
|
||||||
|
} else {
|
||||||
|
System.out.println("Unknown command: " + commandName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Path getDataFileFromEnv(String envVariable) throws IOException {
|
||||||
|
String envPath = System.getenv(envVariable);
|
||||||
|
final Path path;
|
||||||
|
|
||||||
|
if (envPath == null || envPath.trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Environment variable '" + envVariable + "' is not set or empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
path = Paths.get(envPath);
|
||||||
|
} catch (InvalidPathException ex) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"The path provided in environment variable '" +
|
||||||
|
envVariable + "' is invalid: " + ex.getMessage(),
|
||||||
|
ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
throw new IllegalArgumentException("The file at path '" + path + "' does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.isRegularFile(path)) {
|
||||||
|
throw new IllegalArgumentException("The path '" + path + "' is not a file. Check twice!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.isReadable(path)) {
|
||||||
|
throw new IllegalArgumentException("The file at path '" + path + "' is not readable. " +
|
||||||
|
"Check file permissions!");
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info("File '" + path + "' exists and is readable.");
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
20
app/src/main/java/itmo/lab5/cli/CommandBuilder.java
Normal file
20
app/src/main/java/itmo/lab5/cli/CommandBuilder.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package itmo.lab5.cli;
|
||||||
|
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
|
||||||
|
public class CommandBuilder {
|
||||||
|
private final CommandRegistry registry;
|
||||||
|
|
||||||
|
public CommandBuilder() {
|
||||||
|
this.registry = new CommandRegistry();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandBuilder register(String name, Command newCommand) {
|
||||||
|
this.registry.register(name, newCommand);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandRegistry build() {
|
||||||
|
return this.registry;
|
||||||
|
}
|
||||||
|
}
|
15
app/src/main/java/itmo/lab5/cli/CommandContext.java
Normal file
15
app/src/main/java/itmo/lab5/cli/CommandContext.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package itmo.lab5.cli;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CommandContext {
|
||||||
|
private HashMap<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
public void set(String key, Object value) {
|
||||||
|
this.data.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get(String name) {
|
||||||
|
return this.data.get(name);
|
||||||
|
}
|
||||||
|
}
|
21
app/src/main/java/itmo/lab5/cli/CommandRegistry.java
Normal file
21
app/src/main/java/itmo/lab5/cli/CommandRegistry.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package itmo.lab5.cli;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
|
||||||
|
public class CommandRegistry {
|
||||||
|
private final Map<String, Command> commands = new HashMap<>();
|
||||||
|
|
||||||
|
public void register(String name, Command newCommand) {
|
||||||
|
this.commands.put(name, newCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command getByName(String name) {
|
||||||
|
return this.commands.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Command> getAllCommands() {
|
||||||
|
return this.commands;
|
||||||
|
}
|
||||||
|
}
|
23
app/src/main/java/itmo/lab5/cli/commands/ClearCommand.java
Normal file
23
app/src/main/java/itmo/lab5/cli/commands/ClearCommand.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.models.Flat;
|
||||||
|
|
||||||
|
public class ClearCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String args[], CommandContext context) {
|
||||||
|
var collection = new HashMap<Integer, Flat>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
collection = (HashMap<Integer, Flat>) context.get("collection");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return "Can't clear collection. It might be missed";
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.clear();
|
||||||
|
return "Collection was successfuly cleared!";
|
||||||
|
}
|
||||||
|
}
|
12
app/src/main/java/itmo/lab5/cli/commands/ExitCommand.java
Normal file
12
app/src/main/java/itmo/lab5/cli/commands/ExitCommand.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
|
||||||
|
public class ExitCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String[] args, CommandContext context) {
|
||||||
|
System.exit(0);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
28
app/src/main/java/itmo/lab5/cli/commands/HelpCommand.java
Normal file
28
app/src/main/java/itmo/lab5/cli/commands/HelpCommand.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.cli.CommandRegistry;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
|
||||||
|
public class HelpCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String args[], CommandContext context) {
|
||||||
|
var registry = (CommandRegistry) context.get("registry");
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
|
||||||
|
if (registry == null) {
|
||||||
|
result.append("There aren't any avaliable commands!");
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.append("List of avaliable commands: ");
|
||||||
|
for (String command : registry.getAllCommands().keySet()) {
|
||||||
|
result.append(command + ", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
.delete(result.length() - 2, result.length())
|
||||||
|
.append(".")
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
23
app/src/main/java/itmo/lab5/cli/commands/HistoryCommand.java
Normal file
23
app/src/main/java/itmo/lab5/cli/commands/HistoryCommand.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.cli.helpers.*;
|
||||||
|
|
||||||
|
public class HistoryCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String args[], CommandContext context) {
|
||||||
|
var history = new History();
|
||||||
|
|
||||||
|
try {
|
||||||
|
history = (History) context.get("history");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return "There's problem with history. It might be null :(";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (history == null)
|
||||||
|
return "We reach End of History. Somewhere in the world, one Fukuyama is rejoicing :_)";
|
||||||
|
|
||||||
|
return history.toString();
|
||||||
|
}
|
||||||
|
}
|
30
app/src/main/java/itmo/lab5/cli/commands/InfoCommand.java
Normal file
30
app/src/main/java/itmo/lab5/cli/commands/InfoCommand.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.models.Flat;
|
||||||
|
|
||||||
|
public class InfoCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String args[], CommandContext context) {
|
||||||
|
var flats = new HashMap<Integer, Flat>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
flats = (HashMap<Integer, Flat>) context.get("collection");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return "Can't parse collection. Something goes wrong!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flats == null || flats.isEmpty()) {
|
||||||
|
return "Collection is empty now!";
|
||||||
|
}
|
||||||
|
|
||||||
|
var anyFlat = flats.values().iterator().next();
|
||||||
|
|
||||||
|
return ("Information about collection: \n" +
|
||||||
|
"Collections stores in: " + flats.getClass().getName() + "\n" +
|
||||||
|
"Collection consists of: " + anyFlat.getClass().getName() + "\n" +
|
||||||
|
"Items: " + flats.size());
|
||||||
|
}
|
||||||
|
}
|
182
app/src/main/java/itmo/lab5/cli/commands/InsertCommand.java
Normal file
182
app/src/main/java/itmo/lab5/cli/commands/InsertCommand.java
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.models.enums.*;
|
||||||
|
import itmo.lab5.models.*;
|
||||||
|
|
||||||
|
public class InsertCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String[] args, CommandContext context) {
|
||||||
|
if (args.length < 1 || !"null".equals(args[0])) {
|
||||||
|
return "Usage: insert null {element}";
|
||||||
|
}
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
Date creationDate = new Date();
|
||||||
|
|
||||||
|
System.out.print("- Enter name: ");
|
||||||
|
String name = readNonEmptyString(scanner);
|
||||||
|
|
||||||
|
System.out.println("- Coordinates:");
|
||||||
|
System.out.print("Enter x (int): ");
|
||||||
|
int x = readInt(scanner);
|
||||||
|
System.out.print("Enter y (Long): ");
|
||||||
|
Long y = readLongNotNull(scanner);
|
||||||
|
Coordinates coordinates = new Coordinates(x, y);
|
||||||
|
|
||||||
|
System.out.print("Enter square (Double > 0, <= 626): ");
|
||||||
|
Double area = readDoubleInRange(scanner, 0.0, 626.0);
|
||||||
|
|
||||||
|
System.out.print("Enter room count (int > 0): ");
|
||||||
|
int numberOfRooms = readIntMin(scanner, 1);
|
||||||
|
|
||||||
|
System.out.println("- Furnish");
|
||||||
|
Furnish furnish = readEnum(scanner, Furnish.class);
|
||||||
|
|
||||||
|
System.out.println("- View");
|
||||||
|
View view = readEnumNullable(scanner, View.class);
|
||||||
|
|
||||||
|
System.out.println("- Transport");
|
||||||
|
Transport transport = readEnum(scanner, Transport.class);
|
||||||
|
|
||||||
|
System.out.println("- House");
|
||||||
|
System.out.print("Enter house's name: ");
|
||||||
|
|
||||||
|
String houseName = scanner.nextLine();
|
||||||
|
House house = null;
|
||||||
|
|
||||||
|
if (!houseName.isBlank()) {
|
||||||
|
System.out.print("Enter house age (1-959): ");
|
||||||
|
int year = readIntInRange(scanner, 1, 959);
|
||||||
|
System.out.print("Enter house's floors count (1-77): ");
|
||||||
|
long numberOfFloors = readLongInRange(scanner, 1, 77);
|
||||||
|
house = new House(houseName, year, numberOfFloors);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
HashMap<Integer, Flat> collection = (HashMap<Integer, Flat>) context.get("collection");
|
||||||
|
var newID = collection.size() + 1;
|
||||||
|
|
||||||
|
Flat flat = new Flat(newID, name, coordinates, creationDate, area,
|
||||||
|
numberOfRooms, furnish, view, transport, house);
|
||||||
|
collection.put(newID, flat);
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return "There's an error while trying to add new element. Collection im some kind of broken.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "New flat was successfully inserted!";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readNonEmptyString(Scanner scanner) {
|
||||||
|
while (true) {
|
||||||
|
String line = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if (!line.isEmpty())
|
||||||
|
return line;
|
||||||
|
|
||||||
|
System.out.print("Value can't be empty. Retry input: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int readInt(Scanner scanner) {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(scanner.nextLine().trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.print("Please, enter integer: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Long readLongNotNull(Scanner scanner) {
|
||||||
|
while (true) {
|
||||||
|
String line = scanner.nextLine().trim();
|
||||||
|
if (!line.isEmpty()) {
|
||||||
|
try {
|
||||||
|
return Long.parseLong(line);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.print("Please, enter Long: ");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.print("Field can't be null. Retry: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int readIntMin(Scanner scanner, int min) {
|
||||||
|
while (true) {
|
||||||
|
int value = readInt(scanner);
|
||||||
|
if (value >= min)
|
||||||
|
return value;
|
||||||
|
System.out.print("Number must be bigger than " + min + ". Retry: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int readIntInRange(Scanner scanner, int min, int max) {
|
||||||
|
while (true) {
|
||||||
|
int value = readInt(scanner);
|
||||||
|
if (value >= min && value <= max)
|
||||||
|
return value;
|
||||||
|
System.out.print("Enter number in range [" + min + " ... " + max + "] ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long readLongInRange(Scanner scanner, long min, long max) {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
long value = Long.parseLong(scanner.nextLine().trim());
|
||||||
|
if (value >= min && value <= max)
|
||||||
|
return value;
|
||||||
|
System.out.print("Enter number in range [" + min + " ... " + max + "]");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.print("Enter Long number: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double readDoubleInRange(Scanner scanner, double min, double max) {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
Double value = Double.parseDouble(scanner.nextLine().trim());
|
||||||
|
if (value > min && value <= max)
|
||||||
|
return value;
|
||||||
|
System.out.print("Enter float in range [" + (min + 0.0001) + " ... " + max + "] ");
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.print("Enter float number: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Enum<T>> T readEnum(Scanner scanner, Class<T> enumClass) {
|
||||||
|
System.out.println("Allowed values: " + Arrays.toString(enumClass.getEnumConstants()));
|
||||||
|
while (true) {
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(enumClass, input);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.print("You must enter one of values from the previous list: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Enum<T>> T readEnumNullable(Scanner scanner, Class<T> enumClass) {
|
||||||
|
System.out
|
||||||
|
.println("Allowed values (or empty string): " + Arrays.toString(enumClass.getEnumConstants()));
|
||||||
|
while (true) {
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
return null;
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(enumClass, input);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.print("You must enter one of values from the previous list: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.models.Flat;
|
||||||
|
|
||||||
|
public class RemoveKeyCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String args[], CommandContext context) {
|
||||||
|
HashMap<Integer, Flat> flats = new HashMap<Integer, Flat>();
|
||||||
|
Integer idToDelete = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
flats = (HashMap<Integer, Flat>) context.get("collection");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
return "There's a problem with collection parsing";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flats == null)
|
||||||
|
return "Collection is empty. Can't delete anything :(";
|
||||||
|
|
||||||
|
try {
|
||||||
|
idToDelete = Integer.parseInt(args[0]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "You provide misstyped argument!";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (idToDelete == null)
|
||||||
|
return "Check argument's value twice";
|
||||||
|
|
||||||
|
if (!flats.containsKey(idToDelete))
|
||||||
|
return "Can't find flat with such id";
|
||||||
|
|
||||||
|
flats.remove(idToDelete);
|
||||||
|
return "Successfuly deleted flat!";
|
||||||
|
}
|
||||||
|
}
|
30
app/src/main/java/itmo/lab5/cli/commands/ShowCommand.java
Normal file
30
app/src/main/java/itmo/lab5/cli/commands/ShowCommand.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import itmo.lab5.models.Flat;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
|
||||||
|
public class ShowCommand implements Command {
|
||||||
|
@Override
|
||||||
|
public String execute(String args[], CommandContext context) {
|
||||||
|
var collection = new HashMap<Integer, Flat>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
collection = (HashMap<Integer, Flat>) context.get("collection");
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
System.out.println("Can't parse collection!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (collection.isEmpty() || collection.size() == 0) {
|
||||||
|
return "Nothing to show!";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Flat flat : collection.values()) {
|
||||||
|
System.out.println(flat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
135
app/src/main/java/itmo/lab5/cli/commands/UpdateCommand.java
Normal file
135
app/src/main/java/itmo/lab5/cli/commands/UpdateCommand.java
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
package itmo.lab5.cli.commands;
|
||||||
|
|
||||||
|
import itmo.lab5.models.*;
|
||||||
|
import itmo.lab5.models.enums.*;
|
||||||
|
import itmo.lab5.interfaces.Command;
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class UpdateCommand implements Command {
|
||||||
|
private final Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(String[] args, CommandContext context) {
|
||||||
|
if (args.length < 1)
|
||||||
|
return "Usage: update id {element}";
|
||||||
|
|
||||||
|
int idToUpdate;
|
||||||
|
try {
|
||||||
|
idToUpdate = Integer.parseInt(args[1]);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return "Invalid ID!";
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, Flat> collection = (Map<Integer, Flat>) context.get("collection");
|
||||||
|
if (!collection.containsKey(idToUpdate)) {
|
||||||
|
return "No flat with such ID: " + idToUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
Flat oldFlat = collection.get(idToUpdate);
|
||||||
|
Flat updatedFlat = readFlat(idToUpdate, oldFlat);
|
||||||
|
collection.put(idToUpdate, updatedFlat);
|
||||||
|
return "Flat with ID " + idToUpdate + " updated.";
|
||||||
|
}
|
||||||
|
|
||||||
|
private Flat readFlat(int id, Flat oldFlat) {
|
||||||
|
System.out.println("- New information for Flat #" + id);
|
||||||
|
String name = readString("Enter new name: ", false, oldFlat.getName());
|
||||||
|
Coordinates coordinates = readCoordinates(oldFlat.getCoordinates());
|
||||||
|
Date creationDate = new Date();
|
||||||
|
Double area = readNumber("Enter new square: ", 0.0, 626.0, Double::parseDouble, oldFlat.getArea());
|
||||||
|
int rooms = readNumber("Enter new rooms count: ", 1, Integer.MAX_VALUE, Integer::parseInt,
|
||||||
|
oldFlat.getNumberOfRooms());
|
||||||
|
Furnish furnish = readEnum("Enter new furnish: ", Furnish.class, oldFlat.getFurnish());
|
||||||
|
View view = readEnumNullable("Enter new view (or empty string)", View.class, oldFlat.getView());
|
||||||
|
Transport transport = readEnum("Enter new transport: ", Transport.class, oldFlat.getTransport());
|
||||||
|
House house = readHouse(oldFlat.getHouse());
|
||||||
|
|
||||||
|
return new Flat(id, name, coordinates, creationDate, area, rooms, furnish, view, transport, house);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Coordinates readCoordinates(Coordinates oldCoords) {
|
||||||
|
int x = readNumber("Введите координату X", Integer.MIN_VALUE, Integer.MAX_VALUE, Integer::parseInt,
|
||||||
|
oldCoords.getX());
|
||||||
|
Long y = readNumber("Введите координату Y", Long.MIN_VALUE, Long.MAX_VALUE, Long::parseLong, oldCoords.getY());
|
||||||
|
return new Coordinates(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private House readHouse(House oldHouse) {
|
||||||
|
System.out.print("Введите название дома (" + (oldHouse != null ? oldHouse.getName() : "null")
|
||||||
|
+ ", пусто — не изменять, полностью пусто — null): ");
|
||||||
|
String name = scanner.nextLine().trim();
|
||||||
|
if (name.isEmpty())
|
||||||
|
return oldHouse;
|
||||||
|
if (name.equals("null"))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
int year = readNumber("Введите год постройки", 1, 959, Integer::parseInt, oldHouse.getYear());
|
||||||
|
long floors = readNumber("Введите количество этажей", 1L, 77L, Long::parseLong, oldHouse.getNumberOfFloors());
|
||||||
|
|
||||||
|
return new House(name, year, floors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readString(String message, boolean allowEmpty, String oldValue) {
|
||||||
|
while (true) {
|
||||||
|
System.out.print(message + " (" + oldValue + "): ");
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
if (!input.isEmpty() || allowEmpty)
|
||||||
|
return input;
|
||||||
|
System.out.println("Строка не может быть пустой.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Enum<T>> T readEnum(String message, Class<T> enumClass, T oldValue) {
|
||||||
|
while (true) {
|
||||||
|
System.out.println(message + " (" + oldValue + ", варианты: "
|
||||||
|
+ String.join(", ", Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).toList()) + "):");
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(enumClass, input);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Неверное значение. Повторите ввод.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Enum<T>> T readEnumNullable(String message, Class<T> enumClass, T oldValue) {
|
||||||
|
while (true) {
|
||||||
|
System.out.println(message + " (" + (oldValue != null ? oldValue : "null") + ", варианты: "
|
||||||
|
+ String.join(", ", Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).toList()) + "):");
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(enumClass, input);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Неверное значение. Повторите ввод.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Comparable<T>> T readNumber(String message, T min, T max, Parser<T> parser, T oldValue) {
|
||||||
|
while (true) {
|
||||||
|
System.out.print(message + " (" + oldValue + "): ");
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
try {
|
||||||
|
T value = parser.parse(input);
|
||||||
|
if (value.compareTo(min) >= 0 && value.compareTo(max) <= 0)
|
||||||
|
return value;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
System.out.println("Некорректный ввод. Повторите попытку.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Parser<T> {
|
||||||
|
T parse(String input) throws Exception;
|
||||||
|
}
|
||||||
|
}
|
33
app/src/main/java/itmo/lab5/cli/helpers/History.java
Normal file
33
app/src/main/java/itmo/lab5/cli/helpers/History.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package itmo.lab5.cli.helpers;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Deque;
|
||||||
|
|
||||||
|
public class History {
|
||||||
|
private static final int MAX_SIZE = 8;
|
||||||
|
private final Deque<String> history = new ArrayDeque<String>(MAX_SIZE);
|
||||||
|
|
||||||
|
public void add(String command) {
|
||||||
|
if (history.size() >= MAX_SIZE)
|
||||||
|
history.removeFirst();
|
||||||
|
|
||||||
|
history.add(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get(int x) {
|
||||||
|
if (x >= MAX_SIZE)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return (String) history.toArray()[x];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get() {
|
||||||
|
return history.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
var builder = new StringBuilder("History: \n");
|
||||||
|
history.forEach(command -> builder.append(" - " + command + "\n"));
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
95
app/src/main/java/itmo/lab5/cli/helpers/ReaderUtil.java
Normal file
95
app/src/main/java/itmo/lab5/cli/helpers/ReaderUtil.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package itmo.lab5.cli.helpers;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class ReaderUtil {
|
||||||
|
private final Scanner scanner;
|
||||||
|
|
||||||
|
public ReaderUtil(Scanner scanner) {
|
||||||
|
this.scanner = scanner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String promptString(String message, boolean allowEmpty, String oldValue) {
|
||||||
|
while (true) {
|
||||||
|
System.out.print(message);
|
||||||
|
if (!oldValue.isEmpty() || oldValue != null)
|
||||||
|
System.out.print(" (" + oldValue + "): ");
|
||||||
|
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
if (!input.isEmpty() || allowEmpty)
|
||||||
|
return input;
|
||||||
|
|
||||||
|
System.out.println("String can't be empty ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Enum<T>> T promptEnum(String message, Class<T> enumClass, T oldValue) {
|
||||||
|
while (true) {
|
||||||
|
if (oldValue != null)
|
||||||
|
System.out.print("Now it's: " + oldValue + ". ");
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
message + "(options: " +
|
||||||
|
String.join(", ", Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).toList()) +
|
||||||
|
"): ");
|
||||||
|
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(enumClass, input);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid name; Please, try again: ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Enum<T>> T promptEnumNullable(String message, Class<T> enumClass, T oldValue) {
|
||||||
|
while (true) {
|
||||||
|
if (oldValue != null)
|
||||||
|
System.out.print("Now it's: " + oldValue + ". ");
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
message + "(options: " +
|
||||||
|
String.join(", ", Arrays.stream(enumClass.getEnumConstants()).map(Enum::name).toList()) +
|
||||||
|
"): ");
|
||||||
|
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
try {
|
||||||
|
return Enum.valueOf(enumClass, input);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
System.out.println("Invalid name; Please, try again: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Comparable<T>> T promptNumber(String message, T min, T max, Parser<T> parser, T oldValue) {
|
||||||
|
while (true) {
|
||||||
|
System.out.print(message + " (" + oldValue + "): ");
|
||||||
|
String input = scanner.nextLine().trim();
|
||||||
|
if (input.isEmpty())
|
||||||
|
return oldValue;
|
||||||
|
try {
|
||||||
|
T value = parser.parse(input);
|
||||||
|
if (value.compareTo(min) >= 0 && value.compareTo(max) <= 0)
|
||||||
|
return value;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Invalid value; Please, try again: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Parser<T> {
|
||||||
|
T parse(String input) throws Exception;
|
||||||
|
}
|
||||||
|
}
|
7
app/src/main/java/itmo/lab5/interfaces/Command.java
Normal file
7
app/src/main/java/itmo/lab5/interfaces/Command.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package itmo.lab5.interfaces;
|
||||||
|
|
||||||
|
import itmo.lab5.cli.CommandContext;
|
||||||
|
|
||||||
|
public interface Command {
|
||||||
|
String execute(String[] args, CommandContext context);
|
||||||
|
}
|
31
app/src/main/java/itmo/lab5/models/Coordinates.java
Normal file
31
app/src/main/java/itmo/lab5/models/Coordinates.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package itmo.lab5.models;
|
||||||
|
|
||||||
|
public class Coordinates {
|
||||||
|
private int x;
|
||||||
|
private Long y; // Поле не может быть null
|
||||||
|
|
||||||
|
public Coordinates(int x, Long y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(Long y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getY() {
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Point(x = " + Integer.toString(x) + ", y = " + Long.toString(y) + ")";
|
||||||
|
}
|
||||||
|
}
|
141
app/src/main/java/itmo/lab5/models/Flat.java
Normal file
141
app/src/main/java/itmo/lab5/models/Flat.java
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package itmo.lab5.models;
|
||||||
|
|
||||||
|
import itmo.lab5.models.enums.*;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Flat {
|
||||||
|
private int id; // Значение поля должно быть больше 0, Значение этого поля должно быть
|
||||||
|
// уникальным, Значение этого поля должно генерироваться автоматически
|
||||||
|
private String name; // Поле не может быть null, Строка не может быть пустой
|
||||||
|
private Coordinates coordinates; // Поле не может быть null
|
||||||
|
private Date creationDate; // Поле не может быть null, Значение этого поля должно генерироваться
|
||||||
|
// автоматически
|
||||||
|
private Double area; // Максимальное значение поля: 626, Значение поля должно быть больше 0
|
||||||
|
private int numberOfRooms; // Значение поля должно быть больше 0
|
||||||
|
private Furnish furnish; // Поле не может быть null
|
||||||
|
private View view; // Поле может быть null
|
||||||
|
private Transport transport; // Поле не может быть null
|
||||||
|
private House house; // Поле может быть null
|
||||||
|
|
||||||
|
public Flat(int id, String name, Coordinates coordinates, Date creationDate, Double area,
|
||||||
|
int numberOfRooms, Furnish furnish, View view, Transport transport, House house) {
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
this.creationDate = creationDate;
|
||||||
|
this.area = area;
|
||||||
|
this.numberOfRooms = numberOfRooms;
|
||||||
|
this.furnish = furnish;
|
||||||
|
this.view = view;
|
||||||
|
this.transport = transport;
|
||||||
|
this.house = house;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Flat() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinates getCoordinates() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoordinates(Coordinates coordinates) {
|
||||||
|
this.coordinates = coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreationDate() {
|
||||||
|
return creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreationDate(Date creationDate) {
|
||||||
|
this.creationDate = creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getArea() {
|
||||||
|
return area;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArea(Double area) {
|
||||||
|
this.area = area;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfRooms() {
|
||||||
|
return numberOfRooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumberOfRooms(int numberOfRooms) {
|
||||||
|
this.numberOfRooms = numberOfRooms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Furnish getFurnish() {
|
||||||
|
return furnish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFurnish(Furnish furnish) {
|
||||||
|
this.furnish = furnish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getView() {
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setView(View view) {
|
||||||
|
this.view = view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Transport getTransport() {
|
||||||
|
return transport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransport(Transport transport) {
|
||||||
|
this.transport = transport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public House getHouse() {
|
||||||
|
return house;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHouse(House house) {
|
||||||
|
this.house = house;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
var sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
var dateFormat = (creationDate == null) ? "null" : sdf.format(creationDate);
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
builder
|
||||||
|
.append("Flat:\n")
|
||||||
|
.append(" ID: ").append(id).append("\n")
|
||||||
|
.append(" Name: ").append(name).append("\n")
|
||||||
|
.append(" Coordinates: ").append(coordinates != null ? coordinates.toString() : "null").append("\n")
|
||||||
|
.append(" Creation Date: ").append(dateFormat).append("\n")
|
||||||
|
.append(" Area: ").append(area).append("\n")
|
||||||
|
.append(" Number Of Rooms: ").append(numberOfRooms).append("\n")
|
||||||
|
.append(" Furnish: ").append(furnish).append("\n")
|
||||||
|
.append(" View: ").append(view != null ? view : "null").append("\n")
|
||||||
|
.append(" Transport: ").append(transport).append("\n")
|
||||||
|
.append(" House: ").append(house != null ? house.toString() : "null").append("\n");
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
}
|
33
app/src/main/java/itmo/lab5/models/House.java
Normal file
33
app/src/main/java/itmo/lab5/models/House.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package itmo.lab5.models;
|
||||||
|
|
||||||
|
public class House {
|
||||||
|
private String name; // Поле не может быть null
|
||||||
|
private int year; // Максимальное значение поля: 959, Значение поля должно быть больше 0
|
||||||
|
private long numberOfFloors; // Максимальное значение поля: 77, Значение поля должно быть больше 0
|
||||||
|
|
||||||
|
public House(String name, int year, long numberOfFloors) {
|
||||||
|
this.name = name;
|
||||||
|
this.year = year;
|
||||||
|
this.numberOfFloors = numberOfFloors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYear() {
|
||||||
|
return this.year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getNumberOfFloors() {
|
||||||
|
return this.getNumberOfFloors();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "House(" +
|
||||||
|
"name = '" + name +
|
||||||
|
"', year = " + Integer.toString(year) +
|
||||||
|
", numberOfFloors = " + Long.toString(numberOfFloors) +
|
||||||
|
")";
|
||||||
|
}
|
||||||
|
}
|
7
app/src/main/java/itmo/lab5/models/enums/Furnish.java
Normal file
7
app/src/main/java/itmo/lab5/models/enums/Furnish.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package itmo.lab5.models.enums;
|
||||||
|
|
||||||
|
public enum Furnish {
|
||||||
|
DESIGNER,
|
||||||
|
FINE,
|
||||||
|
BAD;
|
||||||
|
}
|
8
app/src/main/java/itmo/lab5/models/enums/Transport.java
Normal file
8
app/src/main/java/itmo/lab5/models/enums/Transport.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package itmo.lab5.models.enums;
|
||||||
|
|
||||||
|
public enum Transport {
|
||||||
|
FEW,
|
||||||
|
NONE,
|
||||||
|
LITTLE,
|
||||||
|
NORMAL;
|
||||||
|
}
|
8
app/src/main/java/itmo/lab5/models/enums/View.java
Normal file
8
app/src/main/java/itmo/lab5/models/enums/View.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package itmo.lab5.models.enums;
|
||||||
|
|
||||||
|
public enum View {
|
||||||
|
STREET,
|
||||||
|
PARK,
|
||||||
|
NORMAL,
|
||||||
|
GOOD;
|
||||||
|
}
|
79
app/src/main/java/itmo/lab5/parser/Reader.java
Normal file
79
app/src/main/java/itmo/lab5/parser/Reader.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
package itmo.lab5.parser;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import itmo.lab5.models.enums.*;
|
||||||
|
import itmo.lab5.models.*;
|
||||||
|
|
||||||
|
public class Reader {
|
||||||
|
static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
|
||||||
|
public HashMap<Integer, Flat> parseCSV(File file) throws FileNotFoundException, IllegalArgumentException {
|
||||||
|
var collection = new HashMap<Integer, Flat>();
|
||||||
|
var scanner = new Scanner(file);
|
||||||
|
|
||||||
|
if (scanner.hasNextLine()) {
|
||||||
|
var currentLine = scanner.nextLine();
|
||||||
|
if (!currentLine.contains("id,name")) {
|
||||||
|
scanner = new Scanner(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
var currentLine = scanner.nextLine();
|
||||||
|
Flat parsedFlat = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
parsedFlat = parseFlat(currentLine);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"There's an error while trying to parse line: '"
|
||||||
|
+ currentLine + "'; "
|
||||||
|
+ "The error is: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.put(parsedFlat.getId(), parsedFlat);
|
||||||
|
}
|
||||||
|
|
||||||
|
collection = collection.entrySet()
|
||||||
|
.stream()
|
||||||
|
.sorted(HashMap.Entry.comparingByKey())
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
Map.Entry::getValue,
|
||||||
|
(oldValue, newValue) -> oldValue,
|
||||||
|
HashMap::new));
|
||||||
|
|
||||||
|
scanner.close();
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Flat parseFlat(String lineToParse) throws IllegalArgumentException, ParseException {
|
||||||
|
var values = lineToParse.split(",", -1);
|
||||||
|
var flat = new Flat();
|
||||||
|
|
||||||
|
flat.setId(Integer.parseInt(values[0]));
|
||||||
|
flat.setName(values[1]);
|
||||||
|
flat.setCoordinates(new Coordinates(Integer.parseInt(values[2]), Long.parseLong(values[3])));
|
||||||
|
flat.setCreationDate(dateFormat.parse(values[4]));
|
||||||
|
flat.setArea(Double.parseDouble(values[5]));
|
||||||
|
flat.setNumberOfRooms(Integer.parseInt(values[6]));
|
||||||
|
flat.setFurnish(Furnish.valueOf(values[7]));
|
||||||
|
flat.setView(values[8].isEmpty() ? null : View.valueOf(values[8]));
|
||||||
|
flat.setTransport(Transport.valueOf(values[9]));
|
||||||
|
|
||||||
|
if (!values[10].isEmpty()) {
|
||||||
|
House house = new House(values[10], Integer.parseInt(values[11]), Long.parseLong(values[12]));
|
||||||
|
flat.setHouse(house);
|
||||||
|
}
|
||||||
|
|
||||||
|
return flat;
|
||||||
|
}
|
||||||
|
}
|
6
app/src/main/resources/data.csv
Normal file
6
app/src/main/resources/data.csv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
id,name,coordinates_x,coordinates_y,creationDate,area,numberOfRooms,furnish,view,transport,house_name,house_year,house_numberOfFloors
|
||||||
|
1,Flat1,100,50,2024-04-01T12:00:00,500.5,3,DESIGNER,STREET,NORMAL,House1,500,10
|
||||||
|
2,Flat2,200,60,2024-04-01T12:05:00,450.0,2,FINE,,FEW,House2,800,5
|
||||||
|
3,Flat3,300,70,2024-04-01T12:10:00,626.0,4,BAD,PARK,LITTLE,,,
|
||||||
|
4,Flat4,400,80,2024-04-01T12:15:00,300.0,1,DESIGNER,GOOD,NONE,House3,959,77
|
||||||
|
5,Flat5,500,90,2024-04-01T12:20:00,550.5,2,FINE,NORMAL,NORMAL,House4,600,20
|
|
7
gradle.properties
Normal file
7
gradle.properties
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file was generated by the Gradle 'init' task.
|
||||||
|
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
||||||
|
|
||||||
|
org.gradle.configuration-cache=true
|
||||||
|
org.gradle.parallel=true
|
||||||
|
org.gradle.caching=true
|
||||||
|
|
8
gradle/libs.versions.toml
Normal file
8
gradle/libs.versions.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# This file was generated by the Gradle 'init' task.
|
||||||
|
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
|
||||||
|
|
||||||
|
[versions]
|
||||||
|
guava = "33.3.1-jre"
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
7
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
251
gradlew
vendored
Executable file
251
gradlew
vendored
Executable file
@ -0,0 +1,251 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed 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
|
||||||
|
#
|
||||||
|
# https://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.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
94
gradlew.bat
vendored
Normal file
94
gradlew.bat
vendored
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
15
settings.gradle
Normal file
15
settings.gradle
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* This file was generated by the Gradle 'init' task.
|
||||||
|
*
|
||||||
|
* The settings file is used to specify which projects to include in your build.
|
||||||
|
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.13/userguide/multi_project_builds.html in the Gradle documentation.
|
||||||
|
* This project uses @Incubating APIs which are subject to change.
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
// Apply the foojay-resolver plugin to allow automatic download of JDKs
|
||||||
|
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.9.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = 'lab5'
|
||||||
|
include('app')
|
Reference in New Issue
Block a user