Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Kemper authored and Christian Kemper committed Nov 26, 2019
0 parents commit 17cec25
Show file tree
Hide file tree
Showing 46 changed files with 891 additions and 0 deletions.
11 changes: 11 additions & 0 deletions BCEL/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'java'
}

group = 'de.fiduciagad.tools.BCEL'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

dependencies {
implementation 'org.apache.bcel:bcel:5.2'
}
Binary file added BCEL/src/main/.DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions BCEL/src/main/java/de/fiduciagad/bcel/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.fiduciagad.bcel;

import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;

/**
*
* @author xgadkem
*/
public class Main {

/**
* @param args
*/
public static void main(String[] args) {
try {

System.out.println();

printClassVersion("C:\\TEMP\\client.jar", "de/gad/b21/Test.class");
}
catch (Exception e) {
e.printStackTrace();
}
}

public static void printClassVersion(String jarfile, String classfile) throws Exception {
ClassParser cp = new ClassParser(jarfile, classfile);
JavaClass clazz1 = cp.parse();
System.out.println(jarfile + " -> " + classfile);
System.out.println("Major: " + clazz1.getMajor());
System.out.println("Minor: " + clazz1.getMinor());
}

}
44 changes: 44 additions & 0 deletions JNI/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id 'java'
id 'application'
id 'cpp'
}

mainClassName = 'de.gad.jni.SayHello'

group = 'de.fiduciagad.tools.JNI'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

println "Building on OS: " + System.properties['os.name']
println "Using JDK: " + System.properties['java.home']

dependencies {
testImplementation 'junit:junit:4.12'
}


test {
systemProperty "java.library.path", file("${buildDir}/libs/hello/shared").absolutePath
}


model {
components {
sayHello(NativeLibrarySpec) {
sources {
cpp {
source {
srcDir 'src/main/jni'
include "**/*.cpp"
}
exportedHeaders {
srcDirs "${org.gradle.internal.jvm.Jvm.current().javaHome}/include", "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/darwin"
}
}
}
}
}
}

test.dependsOn 'sayHelloSharedLibrary'
39 changes: 39 additions & 0 deletions JNI/src/main/java/de/gad/jni/SayHello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.gad.jni;

public class SayHello {

static {
System.out.println("Load lib from classloader " + SayHello.class.getClassLoader());
try {
System.loadLibrary("sayHello");
}
catch (Throwable e) {
System.err.println("Ignoring exception " + e);
}
}

private native String sayHello(String name);

public String say(String name) {
return sayHello(name);
}

@Override
protected void finalize() throws Throwable {
System.err.println("I'm finalized!!!");
}

public static void main(String[] args) {
try {
SayHello hello = new SayHello();
for (int i = 0; i < 50; ++i) {
hello.say("Roundtrip call " + i);
}
System.out.println(hello.sayHello("xgadkem"));
// Thread.sleep(5000);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
10 changes: 10 additions & 0 deletions JNI/src/main/java/de/gad/jni/SayHelloAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package de.gad.jni;

public class SayHelloAdapter {

private final SayHello hello = new SayHello();

public String sayHello(String name) {
return hello.say(name);
}
}
17 changes: 17 additions & 0 deletions JNI/src/main/jni/SayHello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "de_gad_jni_SayHello.h"

#include <string>

using namespace std;

JNIEXPORT jstring JNICALL Java_de_gad_jni_SayHello_sayHello(JNIEnv* env, jobject obj, jstring name) {

const char* c_str = env->GetStringUTFChars(name, NULL);
string c_name(c_str);

env->ReleaseStringUTFChars(name, c_str);

c_name = "Hello " + c_name + " from the native code!";

return env->NewStringUTF(c_name.c_str());
}
21 changes: 21 additions & 0 deletions JNI/src/main/jni/de_gad_jni_SayHello.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions JNI/src/test/java/de/gad/jni/SayHelloTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.gad.jni;


import org.junit.Assert;
import org.junit.Test;

public class SayHelloTest {

@Test
public void testHello() throws Exception
{
SayHello hello = new SayHello();
String spoken = hello.say("Lutz");
Assert.assertEquals("Hello Lutz from the native code!", spoken);
}
}
11 changes: 11 additions & 0 deletions backtracking/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'java'
}

group = 'de.fiduciagad.tools.backtracking'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

dependencies {

}
99 changes: 99 additions & 0 deletions backtracking/src/main/java/backtracking/Labyrinth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package backtracking;

public class Labyrinth {
public char [][] lab = {{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*'},
{' ',' ','*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','K','*'},
{'*',' ',' ',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*'},
{'*',' ','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*',' ','*'},
{'*',' ',' ',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','*'},
{'*',' ','*','*','*','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ','*'},
{'*',' ','*','*',' ','*','*','*','*',' ','*','*','*','*','*','*','*','*',' ','*'},
{'*',' ',' ',' ',' ','*','*','*','*',' ','*','*',' ',' ',' ',' ','*','*',' ','*'},
{'*',' ','*','*','*','*','*','*','*',' ','*','*',' ','*','*',' ','*','*',' ','*'},
{'*',' ','*','*','*','*',' ',' ',' ',' ','*','*','*','*','*',' ','*','*',' ','*'},
{'*',' ','*','*','*','*',' ','*',' ',' ','*','*','*','*','*',' ','*','*',' ','*'},
{'*',' ','*','*','*','*',' ','*',' ',' ',' ',' ',' ',' ',' ',' ','*','*',' ','*'},
{'*',' ','*','*','*','*',' ','*',' ','*','*','*','*','*','*','*',' ',' ',' ','*'},
{'*',' ',' ',' ',' ','*',' ','*',' ','*','*','*','*','*',' ','*','*','*',' ','*'},
{'*','*','*','*',' ','*',' ','*',' ',' ',' ',' ',' ','*',' ',' ',' ',' ',' ','*'},
{'*',' ',' ',' ',' ','*',' ','*','*','*','*','*',' ','*','*','*','*','*',' ','*'},
{'*','*',' ','*',' ',' ',' ','*','*','*','*','*',' ','*','*','*','*','*',' ','*'},
{'*','*',' ','*','*','*','*','*','*','*','*','*',' ','*','*','*','*','*',' ','*'},
{'*',' ',' ',' ',' ',' ','*','*','*','*','*','*',' ',' ',' ',' ',' ',' ',' ','*'},
{'*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*','*' ,'*','*'},
};
public Labyrinth() {
}

public void ausgeben(){
for (int i = 0; i<lab.length;i++){
for(int j = 0; j<lab[i].length;j++){
System.out.print(lab[i][j]);
}
System.out.println("");
}
}
public boolean rechtsFrei(int posX, int posY){
try {

if(lab[posX+1][posY] != '*' && lab[posX+1][posY] != 'M')
return true;
else
return false;
}
catch (Exception ex) {
return false;
}
}
public boolean linksFrei(int posX, int posY){
try {
if(lab[posX-1][posY] != '*' && lab[posX-1][posY] != 'M')
return true;
else
return false;
}
catch (Exception ex) {
return false;
}

}
public boolean untenFrei(int posX, int posY){
try {
if(lab[posX][posY+1] != '*' && lab[posX][posY+1] != 'M')
return true;
else
return false;
}
catch (Exception ex) {
return false;
}

}
public boolean obenFrei(int posX, int posY){
try {
if(lab[posX][posY-1] != '*' && lab[posX][posY-1] != 'M')
return true;
else
return false;
}
catch (Exception ex) {
return false;
}
}

public boolean gefunden(int posX, int posY){
try {
if(lab[posX][posY] == 'K')
return true;
else
return false;
}
catch (Exception ex) {
return false;
}
}

public void setzteMaus(int posX, int posY, char c){
lab[posX][posY] = c;
}
}
10 changes: 10 additions & 0 deletions backtracking/src/main/java/backtracking/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package backtracking;

public class Main {

public Main() {
}
public static void main(String[] args) {
Maus maus = new Maus();
}
}
34 changes: 34 additions & 0 deletions backtracking/src/main/java/backtracking/Maus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package backtracking;

public class Maus {
public Labyrinth lab = new Labyrinth();

public Maus() {
lab.ausgeben();
sucheKaese(1, 0);
}

public void sucheKaese(int posX, int posY) {

if (lab.gefunden(posX, posY)) {
System.out.println("Käse gefunden");
lab.ausgeben();
}
else {
lab.setzteMaus(posX, posY, 'M');
if (lab.rechtsFrei(posX, posY)) {
sucheKaese(++posX, posY);
}
if (lab.linksFrei(posX, posY)) {
sucheKaese(--posX, posY);
}
if (lab.obenFrei(posX, posY)) {
sucheKaese(posX, --posY);
}
if (lab.untenFrei(posX, posY)) {
sucheKaese(posX, ++posY);
}
}
lab.setzteMaus(posX, posY, ' ');
}
}
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
subprojects {
repositories {
maven {
url "https://nexus.in.fiduciagad.de/repository/maven2-internet-proxy/"
credentials {
username "xgtconrb"
password "BCCeWDUWjgcQc6Kcmpa2kwBF252xpQxwKGgUnKmbD3v5FJmaCjB8NBq9VPn9kVxx"
}
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Sep 10 14:56:27 CEST 2019
distributionUrl=https\://nexus.fiducia.de/nexus/content/repositories/thirdparty/org/gradle/gradle-all/5.5/gradle-all-5.5.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Loading

0 comments on commit 17cec25

Please sign in to comment.