FIFO-Pipe implementiert mit Platzhalter Klasse fuer Messages

This commit is contained in:
eichehome 2021-05-11 15:36:40 +02:00
parent c50b9c4aff
commit 0ffffe257e
7 changed files with 202 additions and 20 deletions

View file

@ -1,9 +1,10 @@
annotation.processing.enabled=true annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list= annotation.processing.processors.list=
annotation.processing.run.all.processors=true annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=ChatApplication
application.vendor=eichehome
build.classes.dir=${build.dir}/classes build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned: # This directory is removed when the project is cleaned:
@ -32,6 +33,7 @@ dist.jar=${dist.dir}/ChatApplication.jar
dist.javadoc.dir=${dist.dir}/javadoc dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/ChatApplication dist.jlink.output=${dist.jlink.dir}/ChatApplication
endorsed.classpath=
excludes= excludes=
includes=** includes=**
jar.compress=false jar.compress=false
@ -76,6 +78,7 @@ manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false mkdist.disabled=false
platform.active=default_platform platform.active=default_platform
project.license=gpl30
run.classpath=\ run.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir} ${build.classes.dir}

View file

@ -1,7 +1,18 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright (C) 2021 eichehome
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package client; package client;

View file

@ -1,7 +1,18 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright (C) 2021 eichehome
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package client; package client;

32
src/server/Element.java Normal file
View file

@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 eichehome
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package server;
/**
*
* @author eichehome
*/
public class Element {
private String bezeichner;
public Element(String inhalt) {
bezeichner = inhalt;
}
public String gebeData() {
return bezeichner;
}
}

View file

@ -1,7 +1,18 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright (C) 2021 eichehome
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package server; package server;
@ -11,15 +22,42 @@ package server;
*/ */
public class FifoPipe { public class FifoPipe {
private PipeElement firstElement; public PipeElement firstElement;
private PipeElement lastElement; public PipeElement lastElement;
public FifoPipe() { public FifoPipe() {
} }
public queuElement(Object element) { public void queuElement(Element element) {
PipeElement pipeElement = new PipeElement(element);
try {
lastElement.setNextElement(pipeElement);
lastElement = pipeElement;
} catch (NullPointerException ex) {
firstElement = pipeElement;
lastElement = pipeElement;
}
}
public PipeElement getNextElement() {
PipeElement result = null;
if (firstElement == null) {
return result;
} else {
if (firstElement == lastElement) {
result = firstElement;
firstElement = null;
lastElement = null;
return result;
} else {
result = firstElement;
PipeElement next = firstElement.getNext();
firstElement = next;
return result;
}
}
} }
} }

View file

@ -1,7 +1,18 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Copyright (C) 2021 eichehome
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package server; package server;
@ -11,9 +22,24 @@ package server;
*/ */
public class PipeElement { public class PipeElement {
private PipeElement naechster; private PipeElement next;
private Object data; private Element data;
public void setNextElement(Obj) public PipeElement(Element el) {
data = el;
next = null;
}
public PipeElement getNext() {
return next;
}
public void setNextElement(PipeElement element) {
next = element;
}
public Element getData() {
return data;
}
} }

61
src/server/PipeTest.java Normal file
View file

@ -0,0 +1,61 @@
/*
* Copyright (C) 2021 eichehome
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package server;
/**
*
* @author eichehome
*/
public class PipeTest {
public static void main(String[] args) {
FifoPipe pipe = new FifoPipe();
System.out.println("Erstes Element: " + pipe.firstElement);
System.out.println("Letztes Element: " + pipe.lastElement);
Element el = new Element("Test");
pipe.queuElement(el);
System.out.println("Angehängt");
System.out.println("Erstes Element: " + pipe.firstElement);
System.out.println("Letztes Element: " + pipe.lastElement);
System.out.println("Erstes Element Inhalt: " + pipe.firstElement.getData().gebeData());
System.out.println("Letztes Element Inhalt: " + pipe.lastElement.getData().gebeData());
Element el2 = new Element("Test2");
pipe.queuElement(el2);
System.out.println("Angehängt2");
System.out.println("Erstes Element: " + pipe.firstElement);
System.out.println("Letztes Element: " + pipe.lastElement);
System.out.println("Erstes Element Inhalt: " + pipe.firstElement.getData().gebeData());
System.out.println("Letztes Element Inhalt: " + pipe.lastElement.getData().gebeData());
PipeElement pipeElement = pipe.getNextElement();
System.out.println("Oben entnommen");
System.out.println("Entnommen Inhalt: " + pipeElement.getData().gebeData());
System.out.println("Erstes Element: " + pipe.firstElement);
System.out.println("Letztes Element: " + pipe.lastElement);
System.out.println("Erstes Element Inhalt: " + pipe.firstElement.getData().gebeData());
System.out.println("Letztes Element Inhalt: " + pipe.lastElement.getData().gebeData());
PipeElement pipeElement2 = pipe.getNextElement();
System.out.println("Oben entnommen2");
System.out.println("Entnommen Inhalt: " + pipeElement2.getData().gebeData());
System.out.println("Erstes Element: " + pipe.firstElement);
System.out.println("Letztes Element: " + pipe.lastElement);
//Wieso wills nicht funktionieren?
PipeElement pipeElement3 = pipe.getNextElement();
System.out.println("Oben entnommen3");
//System.out.println(pipeElement3.getData().gebeData());
System.out.println("Erstes Element: " + pipe.firstElement);
System.out.println("Letztes Element: " + pipe.lastElement);
}
}