Skip to content

Commit

Permalink
Record-Interface für Teildatensatz eingeführt, um später Implementier…
Browse files Browse the repository at this point in the history
…ung austauschen zu können
  • Loading branch information
oboehm committed Feb 21, 2021
1 parent 94baaf2 commit 85f01df
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<artifactId>log4j-core</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>

<!-- Validation -->
<dependency>
<groupId>de.jfachwert</groupId>
Expand Down
22 changes: 20 additions & 2 deletions core/src/main/java/gdv/xport/core/GdvFeld.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @author oliver
* @since 09.02.2021
*/
public class GdvFeld implements Comparable<GdvFeld> {
public class GdvFeld implements Comparable<GdvFeld>, Cloneable {

private static final Logger LOG = LogManager.getLogger();
private final GdvBezeichner bezeichner;
Expand Down Expand Up @@ -71,7 +71,7 @@ public GdvFeld(GdvBezeichner name, ByteAdresse byteAdresse, String s) {
* @param other das originale Feld
*/
public GdvFeld(final GdvFeld other) {
this(other.bezeichner, other.byteAdresse, other.getInhalt());
this(other.bezeichner, other.byteAdresse, new String(other.inhalt));
}

/**
Expand Down Expand Up @@ -280,4 +280,22 @@ public int compareTo(final GdvFeld other) {
return this.getByteAdresse() - other.getByteAdresse();
}

/**
* Die clone-Methode hat gegenueber dem CopyConstructor
* {@link GdvFeld#GdvFeld(GdvFeld)} den Vorteil, dass es den richtigen Typ
* fuer die abgeleiteten Klassen zurueckliefert.
*
* @return eine Kopie
*/
@SuppressWarnings("squid:S2975")
@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException ex) {
LOG.info("Clone wird als Fallback ueber Copy-Ctor realisiert:", ex);
return new GdvFeld(this);
}
}

}
45 changes: 45 additions & 0 deletions core/src/main/java/gdv/xport/core/Record.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 by Oliver Boehm
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 21.02.21 by oliver (ob@oasd.de)
*/
package gdv.xport.core;

import java.io.IOException;
import java.io.Writer;

/**
* Ein Record ist eine Sammlung von Feldern.
*
* @author <a href="ob@aosd.de">oliver</a>
*/
public interface Record {

/**
* Fuegt das uebergebene Feld zum Record hinzu.
*
* @param feld das Feld
*/
void add(final GdvFeld feld);

/**
* Exportiert den Record.
*
* @param writer the writer
* @throws IOException Signals that an I/O exception has occurred.
*/
void export(final Writer writer) throws IOException;

}
11 changes: 11 additions & 0 deletions lib/src/main/java/gdv/xport/feld/Feld.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ public Feld(final Feld other) {
this.setInhalt(other.getInhalt());
}

/**
* Dieser Copy-Constructor dient dazu, um ein {@link GdvFeld} in ein
* {@link Feld} umzuwandeln
*
* @param feld zu wandelndes Feld
*/
public Feld(GdvFeld feld) {
super(feld);
this.ausrichtung = Align.UNKNOWN;
}

/**
* Die Default-Ausrichtung ist links-buendig. Diese Vorgabe kann aber von den Unterklassen ueberschrieben werde.
*
Expand Down
9 changes: 8 additions & 1 deletion lib/src/main/java/gdv/xport/satz/Teildatensatz.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import gdv.xport.config.Config;
import gdv.xport.core.ByteAdresse;
import gdv.xport.core.GdvFeld;
import gdv.xport.core.Record;
import gdv.xport.feld.Bezeichner;
import gdv.xport.feld.Feld;
import gdv.xport.feld.NumFeld;
Expand All @@ -45,7 +47,7 @@
* @author ob@aosd.de
* @since 04.10.2009
*/
public class Teildatensatz extends Satz {
public class Teildatensatz extends Satz implements Record {

private static final Logger LOG = LogManager.getLogger(Teildatensatz.class);

Expand Down Expand Up @@ -211,6 +213,11 @@ public void setSatznummer(Zeichen satznummer) {
add(this.satznummer);
}

@Override
public void add(final GdvFeld feld) {

}

/**
* Fuegt das angegebene Feld in den Teildatensatz ein.
* Bei Einfuegen wird ueberprueft, ob es zu Ueberschneidungen mit
Expand Down

0 comments on commit 85f01df

Please sign in to comment.