Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCardProperties: implement deepCopy methods #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/ezvcard/VCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -4715,4 +4715,13 @@ static <T extends HasAltId> String generateAltId(Collection<T> properties) {
}
return altId + "";
}

public VCard deepCopy() {
VCard that = new VCard();
that.version = this.version;
for (final VCardProperty property : getProperties()) {
that.addProperty(property.deepCopy());
}
return that;
}
}
5 changes: 1 addition & 4 deletions src/main/java/ezvcard/ValidationWarnings.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package ezvcard;

import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;

import ezvcard.property.VCardProperty;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ezvcard/property/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public class Address extends VCardProperty implements HasAltId {
private String postalCode;
private String country;

@Override public Address deepCopy() {
Address that = new Address();
this.copyTo(that);
that.poBox = this.poBox;
that.extendedAddress = this.extendedAddress;
that.streetAddress = this.streetAddress;
that.locality = this.locality;
that.region = this.region;
that.postalCode = this.postalCode;
that.country = this.country;
return that;
}

/**
* Gets the P.O. (post office) box.
* @return the P.O. box or null if not set
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ezvcard/property/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public Agent() {
//empty
}

public Agent deepCopy() {
Agent that = new Agent();
this.copyTo(that);
that.url = this.url;
that.vcard = this.vcard;
return that;
}

/**
* Creates an agent property.
* @param url a URL pointing to the agent's information
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ezvcard/property/Anniversary.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public Anniversary(Date date) {
super(date);
}

@Override public Anniversary deepCopy() {
Anniversary that = new Anniversary(this.getDate());
copyTo(that);
return that;
}

/**
* Creates an anniversary property.
* @param date the anniversary date
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ezvcard/property/BinaryProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public abstract class BinaryProperty<T extends MediaTypeParameter> extends VCard
*/
protected T contentType;

@Override public abstract BinaryProperty deepCopy();

protected void copyTo(BinaryProperty<T> that) {
that.data = this.data.clone();
that.url = this.url;
that.contentType = this.contentType;
}

public BinaryProperty() {
//empty
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Birthday.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public Birthday(Date date) {
super(date);
}

@Override
public Birthday deepCopy() {
Birthday that = new Birthday(this.getDate());
copyTo(that);
return that;
}

/**
* Creates a birthday property.
* @param date the birthday
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Birthplace.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public Birthplace() {
super();
}

@Override
public Birthplace deepCopy() {
Birthplace that = new Birthplace();
copyTo(that);
return that;
}

/**
* Creates a new birthplace property.
* @param latitude the latitude coordinate of the place
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/CalendarRequestUri.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public CalendarRequestUri(String uri) {
}

@Override
public CalendarRequestUri deepCopy() {
CalendarRequestUri that = new CalendarRequestUri(value);
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/CalendarUri.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public CalendarUri(String uri) {
super(uri);
}

@Override
public CalendarUri deepCopy() {
CalendarUri that = new CalendarUri(value);
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Categories.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
* @author Michael Angstadt
*/
public class Categories extends TextListProperty implements HasAltId {
@Override
public Categories deepCopy() {
Categories that = new Categories();
copyTo(that);
return that;
}

@Override
public List<Integer[]> getPids() {
return super.getPids();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Classification.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public Classification(String classValue) {
super(classValue);
}

@Override
public Classification deepCopy() {
Classification that = new Classification(this.getValue());
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V3_0);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/ClientPidMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public ClientPidMap(Integer pid, String uri) {
this.uri = uri;
}

@Override
public ClientPidMap deepCopy() {
ClientPidMap that = new ClientPidMap(pid, uri);
copyTo(that);
return that;
}

/**
* Generates a CLIENTPIDMAP type that contains a random UID URI.
* @param pid the PID
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/ezvcard/property/DateOrTimeProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ public class DateOrTimeProperty extends VCardProperty implements HasAltId {
private PartialDate partialDate;
private boolean dateHasTime;

private DateOrTimeProperty() {}

@Override
public DateOrTimeProperty deepCopy() {
DateOrTimeProperty that = new DateOrTimeProperty();
copyTo(that);
return that;
}

protected void copyTo(final DateOrTimeProperty that) {
super.copyTo(that);
that.text = this.text;
that.date = new Date(this.date.getTime());
that.partialDate = this.partialDate; // immutable
that.dateHasTime = this.dateHasTime;
}

/**
* Creates a date-and-or-time property.
* @param date the date value
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Deathdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ public Deathdate(Date date) {
super(date);
}

@Override
public Deathdate deepCopy() {
Deathdate that = new Deathdate(getDate());
copyTo(that);
return that;
}

/**
* Creates a deathdate property.
* @param date the deathdate
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Deathplace.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public Deathplace() {
super();
}

@Override
public Deathplace deepCopy() {
Deathplace that = new Deathplace();
copyTo(that);
return that;
}

/**
* Creates a new deathplace property.
* @param latitude the latitude coordinate of the place
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public Email(String email) {
super(email);
}

@Override
public Email deepCopy() {
Email that = new Email(getValue());
copyTo(that);
return that;
}

/**
* Gets all the TYPE parameters.
* @return the TYPE parameters or empty set if there are none
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Expertise.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public Expertise(String skill) {
}

@Override
public Expertise deepCopy() {
Expertise that = new Expertise(getValue());
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/FormattedName.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public FormattedName(String name) {
super(name);
}

@Override
public FormattedName deepCopy() {
FormattedName that = new FormattedName(getValue());
copyTo(that);
return that;
}

/**
* Gets the TYPE parameter.
* <p>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/FreeBusyUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public FreeBusyUrl(String uri) {
super(uri);
}

@Override
public FreeBusyUrl deepCopy() {
FreeBusyUrl that = new FreeBusyUrl(getValue());
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ezvcard/property/Gender.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public Gender(String gender) {
this.gender = gender;
}

@Override
public Gender deepCopy() {
Gender that = new Gender(gender);
copyTo(that);
that.text = this.text;
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Geo.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public Geo(Double latitude, Double longitude) {
this(new GeoUri.Builder(latitude, longitude).build());
}

@Override
public Geo deepCopy() {
Geo that = new Geo(this.uri);
copyTo(that);
return that;
}

/**
* Creates a geo property.
* @param uri the geo URI
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Hobby.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public Hobby(String hobby) {
super(hobby);
}

@Override
public Hobby deepCopy() {
Hobby that = new Hobby(getValue());
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ezvcard/property/ImageProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
* @author Michael Angstadt
*/
public class ImageProperty extends BinaryProperty<ImageType> {

protected ImageProperty() {}

@Override
public ImageProperty deepCopy() {
ImageProperty that = new ImageProperty();
copyTo(that);
return that;
}

/**
* Creates an image property.
* @param url the URL to the image
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Impp.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public class Impp extends VCardProperty implements HasAltId {

private URI uri;

@Override
public Impp deepCopy() {
Impp that = new Impp(this.uri);
copyTo(that);
return that;
}

/**
* Creates an IMPP property. Note that this class has static factory methods
* for creating IMPP properties of common IM protocols.
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/ezvcard/property/Interest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public Interest(String interest) {
super(interest);
}

@Override
public Interest deepCopy() {
Interest that = new Interest(getValue());
copyTo(that);
return that;
}

@Override
public Set<VCardVersion> _supportedVersions() {
return EnumSet.of(VCardVersion.V4_0);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ezvcard/property/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public Key() {
super();
}

@Override
public Key deepCopy() {
Key that = new Key();
copyTo(that);
that.text = this.text;
return that;
}

/**
* Creates a key property.
* @param data the binary data
Expand Down
Loading