From 509adad1d6c8f0c3b199472435c33db6f2dcec52 Mon Sep 17 00:00:00 2001 From: Sobottasgithub Date: Fri, 9 Jan 2026 23:15:03 +0100 Subject: [PATCH] Initial --- .envrc | 1 + .gitignore | 24 +++++++++++++++++++ Action.java | 27 +++++++++++++++++++++ ActionHistory.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++ GNUmakefile | 12 ++++++++++ Main.java | 29 ++++++++++++++++++++++ flake.nix | 53 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 206 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Action.java create mode 100644 ActionHistory.java create mode 100644 GNUmakefile create mode 100644 Main.java create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..a5dbbcb --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..524f096 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* diff --git a/Action.java b/Action.java new file mode 100644 index 0000000..2100a93 --- /dev/null +++ b/Action.java @@ -0,0 +1,27 @@ +public class Action { + private String name; + private int damage; + + public Action() {} + + public Action(String name, int damage) { + this.name = name; + this.damage = damage; + } + + public int getDamage() { + return damage; + } + + public String getName() { + return name; + } + + public void setDamage(int damage) { + this.damage = damage; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/ActionHistory.java b/ActionHistory.java new file mode 100644 index 0000000..54e947b --- /dev/null +++ b/ActionHistory.java @@ -0,0 +1,60 @@ +public class ActionHistory { + private class Node { + private T content = null; + private Node nextNode = null; + + public Node(T content) { + setContent(content); + } + + private void setContent(T content) { + this.content = content; + } + + private T getContent() { + return this.content; + } + + private void setNextNode(Node nextNode) { + this.nextNode = nextNode; + } + + private Node getNextNode() { + return this.nextNode; + } + } + + private Node head = null; + + public ActionHistory() {} + + public boolean isEmpty() { + if (head == null) { + return true; + } + return false; + } + + public void push(Object content) { + if (isEmpty()) { + head = new Node(content); + } else { + Node newNode = new Node(content); + newNode.setNextNode(head); + head = newNode; + } + } + + public Object pop() { + if (isEmpty()) { + return null; + } + Object content = head.getContent(); + head = head.getNextNode(); + return content; + } + + public Object top() { + return ((isEmpty()) ? null : head.getContent()); + } +} diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..2ab9f2e --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,12 @@ +JAVA_FMT = google-java-format +JAVA_FILES = $(shell find . -name '*.java') +XML_FMT = xmlindent +XML_FILES = $(shell find . -name '*.xml') + +.PHONY: fmt +fmt: + @echo "Formatting all Java files..." + @for f in $(JAVA_FILES); do \ + echo " $$f"; \ + $(JAVA_FMT) -i $$f; \ + done diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..f7c1c8e --- /dev/null +++ b/Main.java @@ -0,0 +1,29 @@ +public class Main { + public static void main(String[] args) { + Action delete = new Action("delete", 12); + Action changeFont = new Action("changeFont", 0); + Action bold = new Action("bold", 1); + + ActionHistory actionHistory = new ActionHistory(); + System.out.println(actionHistory.isEmpty()); + actionHistory.push(delete); + actionHistory.push(changeFont); + System.out.println("+ 2 Items pushed"); + + System.out.println(actionHistory.isEmpty()); + System.out.println(actionHistory.pop()); + System.out.println(actionHistory.pop()); + System.out.println("- 2 Items poped"); + actionHistory.pop(); + + actionHistory.push(bold); + System.out.println("+ 1 Item pushed"); + + System.out.println(actionHistory.isEmpty()); + System.out.println("Action top: " + actionHistory.top()); + System.out.println(actionHistory.pop()); + System.out.println("- 1 Item poped"); + System.out.println(actionHistory.isEmpty()); + System.out.println("Action top: " + actionHistory.top()); + } +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9feddbd --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Stack"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ ]; + systems = + [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, ... }: + let + + jdk = pkgs.jdk21.override { }; + + buildInputs = [ jdk ]; + + devTools = [ pkgs.google-java-format ]; + + in { + devShells.default = + pkgs.mkShell { buildInputs = buildInputs ++ devTools; }; + + packages = { + default = pkgs.stdenv.mkDerivation { + pname = "stack"; + version = "1.0.0"; + + src = ./.; + + nativeBuildInputs = buildInputs ++ [ pkgs.makeWrapper ]; + + buildPhase = '' + javac -Werror -g:none -deprecation -verbose Main.java + ''; + + installPhase = '' + mkdir -p $out/{bin,lib} + cp *.class $out/lib + + makeWrapper ${ + pkgs.lib.getExe jdk + } $out/bin/stack --add-flags "-cp $out/lib/ Main" + ''; + }; + }; + }; + flake = { }; + }; +}