Skip to content

Commit b485216

Browse files
committed
replaced util.copy package with object-copier
1 parent cfee63f commit b485216

14 files changed

Lines changed: 51 additions & 603 deletions

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = 'org.xmlobjects'
12-
version = '1.4.0'
12+
version = '2.0.0-SNAPSHOT'
1313
description = 'A simple and lightweight XML-to-object mapping library'
1414
ext.date = new Date()
1515

@@ -33,12 +33,16 @@ repositories {
3333
}
3434

3535
dependencies {
36+
api 'org.xmlobjects:object-copier:1.0.0-SNAPSHOT'
3637
api 'org.glassfish.jaxb:xsom:4.0.7'
3738
api 'org.xmlobjects:classindex:3.13.1'
3839
annotationProcessor 'org.xmlobjects:classindex:3.13.1'
3940
}
4041

4142
javadoc {
43+
def name = project.name
44+
def version = project.version
45+
4246
options {
4347
overview = "$projectDir/build/tmp/javadoc/overview.html"
4448
header = "$project.name $project.version"

src/main/java/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module org.xmlobjects {
2+
requires transitive org.xmlobjects.copy;
23
requires transitive java.xml;
34
requires transitive com.sun.xml.xsom;
45
requires transitive org.xmlobjects.classindex;
@@ -12,7 +13,6 @@
1213
exports org.xmlobjects.stream;
1314
exports org.xmlobjects.util;
1415
exports org.xmlobjects.util.composite;
15-
exports org.xmlobjects.util.copy;
1616
exports org.xmlobjects.util.xml;
1717
exports org.xmlobjects.xml;
1818
}

src/main/java/org/xmlobjects/model/Child.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
package org.xmlobjects.model;
77

8-
public interface Child {
8+
import org.xmlobjects.copy.CopyCallback;
9+
import org.xmlobjects.copy.CopyContext;
10+
import org.xmlobjects.copy.CopyMode;
11+
12+
public interface Child extends CopyCallback {
913
Child getParent();
1014

1115
void setParent(Child parent);
@@ -20,4 +24,19 @@ default <T extends Child> T getParent(Class<T> type) {
2024

2125
return null;
2226
}
27+
28+
@Override
29+
default void preCopy(CopyContext context, CopyMode mode, boolean isRoot) {
30+
Child parent = getParent();
31+
if (parent != null) {
32+
context.withCloneIfAbsent(parent, parent);
33+
}
34+
}
35+
36+
@Override
37+
default void postCopy(CopyContext context, CopyMode mode, boolean isRoot) {
38+
if (isRoot) {
39+
setParent(null);
40+
}
41+
}
2342
}

src/main/java/org/xmlobjects/model/ChildList.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55

66
package org.xmlobjects.model;
77

8+
import org.xmlobjects.copy.CopyContext;
9+
import org.xmlobjects.copy.CopyMode;
10+
import org.xmlobjects.copy.Copyable;
11+
812
import java.util.ArrayList;
913
import java.util.Collection;
1014
import java.util.function.UnaryOperator;
1115

12-
public class ChildList<T extends Child> extends ArrayList<T> {
16+
public class ChildList<T extends Child> extends ArrayList<T> implements Copyable<ChildList<T>> {
1317
private Child parent;
1418

1519
public ChildList(Child parent) {
@@ -85,4 +89,24 @@ private void applyParent(Collection<? extends T> c) {
8589
}
8690
}
8791
}
92+
93+
@Override
94+
public ChildList<T> newInstance(CopyMode mode, CopyContext context) {
95+
return new ChildList<>(size(), switch (mode) {
96+
case SHALLOW -> getParent();
97+
case DEEP -> context.deepCopy(getParent());
98+
});
99+
}
100+
101+
@Override
102+
public void shallowCopyTo(ChildList<T> dest, CopyContext context) {
103+
dest.addAll(this);
104+
}
105+
106+
@Override
107+
public void deepCopyTo(ChildList<T> dest, CopyContext context) {
108+
for (T element : this) {
109+
dest.add(context.deepCopy(element));
110+
}
111+
}
88112
}

src/main/java/org/xmlobjects/util/copy/AbstractCloner.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/main/java/org/xmlobjects/util/copy/ArrayCloner.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/main/java/org/xmlobjects/util/copy/ChildListCloner.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/java/org/xmlobjects/util/copy/CollectionCloner.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)