Initial
This commit is contained in:
commit
509adad1d6
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@ -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*
|
||||
27
Action.java
Normal file
27
Action.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
60
ActionHistory.java
Normal file
60
ActionHistory.java
Normal file
@ -0,0 +1,60 @@
|
||||
public class ActionHistory {
|
||||
private class Node<T> {
|
||||
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());
|
||||
}
|
||||
}
|
||||
12
GNUmakefile
Normal file
12
GNUmakefile
Normal file
@ -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
|
||||
29
Main.java
Normal file
29
Main.java
Normal file
@ -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());
|
||||
}
|
||||
}
|
||||
53
flake.nix
Normal file
53
flake.nix
Normal file
@ -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 = { };
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user