Remove clone

This commit is contained in:
J-Jamet
2019-06-01 12:58:28 +02:00
parent 6ba45c3d87
commit e649be230e
14 changed files with 28 additions and 179 deletions

View File

@@ -27,7 +27,7 @@ public class PwDateTest extends TestCase {
public void testDate() {
PwDate jDate = new PwDate(System.currentTimeMillis());
PwDate intermediate = jDate.clone();
PwDate intermediate = new PwDate(jDate);
PwDate cDate = new PwDate(intermediate.getCDate(), 0);

View File

@@ -28,7 +28,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class AutoType implements Cloneable, Parcelable {
public class AutoType implements Parcelable {
private static final long OBF_OPT_NONE = 0;
public boolean enabled = true;
@@ -79,18 +79,6 @@ public class AutoType implements Cloneable, Parcelable {
}
};
@SuppressWarnings("unchecked")
public AutoType clone() {
AutoType auto;
try {
auto = (AutoType) super.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
auto.windowSeqPairs = (HashMap<String, String>) windowSeqPairs.clone();
return auto;
}
public void put(String key, String value) {
windowSeqPairs.put(key, value);
}
@@ -98,5 +86,4 @@ public class AutoType implements Cloneable, Parcelable {
public Set<Map.Entry<String, String>> entrySet() {
return windowSeqPairs.entrySet();
}
}

View File

@@ -35,13 +35,13 @@ import java.util.Date;
* @author bpellin
*
*/
public class PwDate implements Cloneable, Parcelable {
public class PwDate implements Parcelable {
private static final int DATE_SIZE = 5;
private Date jDate;
private Date jDate = null;
private boolean jDateBuilt = false;
transient private byte[] cDate;
transient private byte[] cDate = null;
transient private boolean cDateBuilt = false;
public static final Date NEVER_EXPIRE = getNeverExpire();
@@ -80,9 +80,18 @@ public class PwDate implements Cloneable, Parcelable {
cDateBuilt = true;
}
public PwDate(PwDate date) {
jDate = new Date(date.jDate.getTime());
jDateBuilt = date.jDateBuilt;
public PwDate(PwDate source) {
if (source.jDate != null) {
this.jDate = new Date(source.jDate.getTime());
}
this.jDateBuilt = source.jDateBuilt;
if (source.cDate != null) {
int dateLength = source.cDate.length;
this.cDate = new byte[dateLength];
System.arraycopy(source.cDate, 0, this.cDate, 0, dateLength);
}
this.cDateBuilt = source.cDateBuilt;
}
public PwDate(Date date) {
@@ -128,25 +137,6 @@ public class PwDate implements Cloneable, Parcelable {
return new PwDate[size];
}
};
@Override
public PwDate clone() {
PwDate copy = new PwDate();
if ( cDateBuilt ) {
byte[] newC = new byte[DATE_SIZE];
System.arraycopy(cDate, 0, newC, 0, DATE_SIZE);
copy.cDate = newC;
copy.cDateBuilt = true;
}
if ( jDateBuilt ) {
copy.jDate = (Date) jDate.clone();
copy.jDateBuilt = true;
}
return copy;
}
public Date getDate() {
if ( ! jDateBuilt ) {
@@ -273,5 +263,4 @@ public class PwDate implements Cloneable, Parcelable {
(cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND));
}
}

View File

@@ -163,34 +163,6 @@ public class PwEntryV3 extends PwEntry<PwGroupV3, PwEntryV3> {
}
}
@Override
public PwEntryV3 clone() {
// Attributes in parent
PwEntryV3 newEntry = (PwEntryV3) super.clone();
// Attributes here
// newEntry.parent stay the same in copy
// newEntry.groupId stay the same in copy
// newEntry.title stay the same in copy
// newEntry.username stay the same in copy
if (password != null) {
int passLen = password.length;
password = new byte[passLen];
System.arraycopy(password, 0, newEntry.password, 0, passLen);
}
// newEntry.url stay the same in copy
// newEntry.additional stay the same in copy
// newEntry.binaryDesc stay the same in copy
if ( binaryData != null ) {
int descLen = binaryData.length;
newEntry.binaryData = new byte[descLen];
System.arraycopy(binaryData, 0, newEntry.binaryData, 0, descLen);
}
return newEntry;
}
@Override
public Type getType() {
return Type.ENTRY;

View File

@@ -161,33 +161,6 @@ public class PwEntryV4 extends PwEntry<PwGroupV4, PwEntryV4> implements ITimeLog
tags = source.tags;
}
@SuppressWarnings("unchecked")
@Override
public PwEntryV4 clone() {
// Attributes in parent
PwEntryV4 newEntry = (PwEntryV4) super.clone();
// Attributes here
newEntry.customIcon = new PwIconCustom(this.customIcon);
// newEntry.usageCount stay the same in copy
newEntry.parentGroupLastMod = this.parentGroupLastMod.clone();
newEntry.fields = new ExtraFields(this.fields);
// TODO customData make copy from hashmap
newEntry.binaries = (HashMap<String, ProtectedBinary>) this.binaries.clone();
// newEntry.foregroundColor stay the same in copy
// newEntry.backgroupColor stay the same in copy
// newEntry.overrideURL stay the same in copy
newEntry.autoType = autoType.clone();
newEntry.history = (ArrayList<PwEntryV4>) this.history.clone();
// newEntry.url stay the same in copy
// newEntry.additional stay the same in copy
// newEntry.tags stay the same in copy
return newEntry;
}
@NonNull
@Override
public Type getType() {

View File

@@ -78,16 +78,6 @@ public class PwGroupV3 extends PwGroup<Integer, PwGroupV3, PwEntryV3> {
flags = source.flags;
}
@SuppressWarnings("unchecked")
@Override
public PwGroupV3 clone() {
// name is clone automatically (IMMUTABLE)
// newGroup.groupId stay the same in copy
// newGroup.level stay the same in copy
// newGroup.flags stay the same in copy
return (PwGroupV3) super.clone();
}
@Override
public Type getType() {
return Type.GROUP;

View File

@@ -126,30 +126,6 @@ public class PwGroupV4 extends PwGroup<UUID, PwGroupV4, PwEntryV4> implements IT
lastTopVisibleEntry = source.lastTopVisibleEntry;
}
@Override
public PwGroupV4 clone() {
// Attributes in parent
PwGroupV4 newGroup = (PwGroupV4) super.clone();
// Attributes here
// name is clone automatically (IMMUTABLE)
newGroup.customIcon = new PwIconCustom(this.customIcon);
// newGroup.usageCount stay the same in copy
newGroup.locationChangeDate = this.locationChangeDate.clone();
// TODO customData make copy from hashmap newGroup.customData = (HashMap<String, String>) this.customData.clone();
// newGroup.expires stay the same in copy
// newGroup.notes stay the same in copy
// newGroup.isExpanded stay the same in copy
// newGroup.defaultAutoTypeSequence stay the same in copy
// newGroup.enableAutoType stay the same in copy
// newGroup.enableSearching stay the same in copy
// newGroup.lastTopVisibleEntry stay the same in copy
return newGroup;
}
@NonNull
@Override
public Type getType() {

View File

@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.database.element;
import android.os.Parcel;
import android.os.Parcelable;
public abstract class PwIcon implements Parcelable, Cloneable {
public abstract class PwIcon implements Parcelable {
public static final int UNKNOWN = -1;
@@ -38,9 +38,6 @@ public abstract class PwIcon implements Parcelable, Cloneable {
public abstract int getIconId();
@Override
protected abstract PwIcon clone() throws CloneNotSupportedException;
@Override
public int describeContents() {
return 0;

View File

@@ -88,11 +88,6 @@ public class PwIconCustom extends PwIcon {
}
};
@Override
protected PwIconCustom clone() throws CloneNotSupportedException {
return new PwIconCustom(this);
}
@Override
public int hashCode() {
final int prime = 31;

View File

@@ -76,11 +76,6 @@ public class PwIconStandard extends PwIcon {
return iconId == 0;
}
@Override
protected PwIconStandard clone() throws CloneNotSupportedException {
return new PwIconStandard(this);
}
@Override
public int hashCode() {
final int prime = 31;

View File

@@ -87,24 +87,6 @@ public abstract class PwNode
this.expireDate = new PwDate(source.expireDate);
}
@Override
public PwNode clone() {
PwNode newNode;
try {
newNode = (PwNode) super.clone();
newNode.nodeId = nodeId.clone();
// newNode.parent stay the same in copy
newNode.icon = icon.clone();
newNode.creation = creation.clone();
newNode.lastMod = lastMod.clone();
newNode.lastAccess = lastAccess.clone();
newNode.expireDate = expireDate.clone();
} catch (CloneNotSupportedException e) {
throw new RuntimeException("Clone should be supported");
}
return newNode;
}
public IdType getId() {
return getNodeId().getId();
}

View File

@@ -22,7 +22,7 @@ package com.kunzisoft.keepass.database.element;
import android.os.Parcel;
import android.os.Parcelable;
public abstract class PwNodeId<Id> implements Cloneable, Parcelable {
public abstract class PwNodeId<Id> implements Parcelable {
public PwNodeId() {}
@@ -37,9 +37,4 @@ public abstract class PwNodeId<Id> implements Cloneable, Parcelable {
}
public abstract Id getId();
@Override
public PwNodeId clone() throws CloneNotSupportedException {
return (PwNodeId) super.clone();
}
}

View File

@@ -31,6 +31,10 @@ public class PwNodeIdInt extends PwNodeId<Integer> {
this(new Random().nextInt());
}
public PwNodeIdInt(PwNodeIdInt source) {
this(source.id);
}
public PwNodeIdInt(int groupId) {
super();
this.id = groupId;
@@ -59,11 +63,6 @@ public class PwNodeIdInt extends PwNodeId<Integer> {
}
};
@Override
public PwNodeIdInt clone() throws CloneNotSupportedException {
return (PwNodeIdInt) super.clone();
}
@Override
public boolean equals(Object compare) {
if ( ! (compare instanceof PwNodeIdInt) ) {

View File

@@ -30,7 +30,11 @@ public class PwNodeIdUUID extends PwNodeId<UUID> {
public PwNodeIdUUID() {
this(UUID.randomUUID());
}
public PwNodeIdUUID(PwNodeIdUUID source) {
this(source.uuid);
}
public PwNodeIdUUID(UUID uuid) {
super();
this.uuid = uuid;
@@ -59,11 +63,6 @@ public class PwNodeIdUUID extends PwNodeId<UUID> {
}
};
@Override
public PwNodeIdUUID clone() throws CloneNotSupportedException {
return (PwNodeIdUUID) super.clone();
}
@Override
public boolean equals(Object id) {
if ( ! (id instanceof PwNodeIdUUID) ) {