Init
This commit is contained in:
commit
67df614d41
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Inventar.iml" filepath="$PROJECT_DIR$/Inventar.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
16
GNUmakefile
Normal file
16
GNUmakefile
Normal file
@ -0,0 +1,16 @@
|
||||
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
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -rf *.class *.~ava result
|
||||
17
Gegenstand.java
Normal file
17
Gegenstand.java
Normal file
@ -0,0 +1,17 @@
|
||||
public class Gegenstand {
|
||||
private String name;
|
||||
private int ausdauer;
|
||||
|
||||
public Gegenstand(String name, int ausdauer) {
|
||||
this.name = name;
|
||||
this.ausdauer = ausdauer;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAusdauer() {
|
||||
return ausdauer;
|
||||
}
|
||||
}
|
||||
77
Inventar.java
Normal file
77
Inventar.java
Normal file
@ -0,0 +1,77 @@
|
||||
import java.util.Collections;
|
||||
|
||||
public class Inventar {
|
||||
private Gegenstand[] gegenstaende;
|
||||
|
||||
public Inventar() {
|
||||
this.gegenstaende = new Gegenstand[10];
|
||||
gegenstaende[0] = new Gegenstand ("Bogen", 20);
|
||||
gegenstaende[1] = new Gegenstand ("Gürtel", 10);
|
||||
gegenstaende[2] = new Gegenstand ("Helm", 25);
|
||||
gegenstaende[3] = new Gegenstand ("Pfeile", 5);
|
||||
gegenstaende[4] = new Gegenstand ("Ring", 7);
|
||||
gegenstaende[5] = new Gegenstand ("Schild", 30);
|
||||
gegenstaende[6] = new Gegenstand ("Schwert", 18);
|
||||
gegenstaende[7] = new Gegenstand ("Rüstung", 22);
|
||||
gegenstaende[8] = new Gegenstand ("Stiefel", 16);
|
||||
gegenstaende[9] = new Gegenstand ("Kette", 18);
|
||||
|
||||
gegenstaende = sortArray(gegenstaende);
|
||||
|
||||
for(int i = 0; i < gegenstaende.length; i++) {
|
||||
System.out.println(gegenstaende[i].getName());
|
||||
}
|
||||
|
||||
// Test binary search:
|
||||
int position = binarySearch(gegenstaende, gegenstaende[2].getName());
|
||||
System.out.println("Found " + gegenstaende[position].getName() + " at position: " + position + " with 'ausdauer': " + gegenstaende[position].getAusdauer());
|
||||
}
|
||||
|
||||
public Gegenstand[] sortArray(Gegenstand[] gegenstaende) {
|
||||
// Insertion sort
|
||||
|
||||
for (int index = 1; index < gegenstaende.length; index++) {
|
||||
Gegenstand entry = gegenstaende[index];
|
||||
int previousIndex = index;
|
||||
|
||||
while (previousIndex > 0 && gegenstaende[previousIndex - 1].getName().compareTo(entry.getName()) > 0) {
|
||||
gegenstaende[previousIndex] = gegenstaende[previousIndex - 1];
|
||||
previousIndex--;
|
||||
}
|
||||
gegenstaende[previousIndex] = entry;
|
||||
}
|
||||
|
||||
return gegenstaende;
|
||||
}
|
||||
|
||||
public int binarySearch(Gegenstand[] gegenstaende, String searchedName) {
|
||||
int low = 0;
|
||||
int high = gegenstaende.length-1;
|
||||
|
||||
while(low <= high) {
|
||||
int pivot = (low + high) / 2;
|
||||
|
||||
int compareToResult = gegenstaende[pivot].getName().compareTo(searchedName);
|
||||
if(compareToResult == 0) {
|
||||
return pivot;
|
||||
} else if (compareToResult < 0) {
|
||||
low = pivot + 1;
|
||||
} else if (compareToResult > 0) {
|
||||
high = pivot -1;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void lineareSuche(String name) {
|
||||
// to do
|
||||
}
|
||||
|
||||
public Gegenstand[] getGegenstaende() {
|
||||
return gegenstaende;
|
||||
}
|
||||
|
||||
public void maxAusdauer() {
|
||||
// to do
|
||||
}
|
||||
}
|
||||
5
Main.java
Normal file
5
Main.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Inventar inventar = new Inventar();
|
||||
}
|
||||
}
|
||||
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
## Gerne auch mit nix ausführen!
|
||||
Dafür einfach nur in der Konsole (sofern installiert):
|
||||
```bash
|
||||
nix run
|
||||
```
|
||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1760948891,
|
||||
"narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1761114652,
|
||||
"narHash": "sha256-f/QCJM/YhrV/lavyCVz8iU3rlZun6d+dAiC3H+CDle4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "01f116e4df6a15f4ccdffb1bcd41096869fb385c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1754788789,
|
||||
"narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "a73b9c743612e4244d865a2fdee11865283c04e6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
57
flake.nix
Normal file
57
flake.nix
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
description = "Inventar";
|
||||
|
||||
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 = "inventar";
|
||||
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/inventar --add-flags "-cp $out/lib/ Main"
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
flake = {
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user