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

APP-3018: Using varargs in constructor and setAttachment methods #196

Merged
merged 1 commit into from
Sep 3, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -23,37 +24,25 @@ public OutboundMessage(String message, String data) {
this.data = data;
}

public OutboundMessage(String message, File[] attachment) {
public OutboundMessage(String message, File... attachment) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen if we pass a null value here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to cast it to File class, then the attachment array will contain only 1 null element.

this.message = message;
this.attachment = attachment;
}

public OutboundMessage(String message, File attachment) {
this.message = message;
this.attachment = new File[] { attachment };
}

public OutboundMessage(String message, String data, File[] attachment) {
public OutboundMessage(String message, String data, File... attachment) {
this.message = message;
this.data = data;
this.attachment = attachment;
}

public OutboundMessage(String message, String data, File attachment) {
this.message = message;
this.data = data;
this.attachment = new File[] { attachment };
}

public OutboundMessage(String message, List<ContentAttachment> contentAttachment) {
this.message = message;
this.contentAttachment = contentAttachment;
}

public OutboundMessage(String message, ContentAttachment contentAttachment) {
public OutboundMessage(String message, ContentAttachment... contentAttachment) {
this.message = message;
this.contentAttachment = new ArrayList<>();
this.contentAttachment.add(contentAttachment);
this.contentAttachment = Arrays.asList(contentAttachment);
}

public OutboundMessage(String message, String data, List<ContentAttachment> contentAttachment) {
Expand All @@ -62,11 +51,10 @@ public OutboundMessage(String message, String data, List<ContentAttachment> cont
this.contentAttachment = contentAttachment;
}

public OutboundMessage(String message, String data, ContentAttachment contentAttachment) {
public OutboundMessage(String message, String data, ContentAttachment... contentAttachment) {
this.message = message;
this.data = data;
this.contentAttachment = new ArrayList<>();
this.contentAttachment.add(contentAttachment);
this.contentAttachment = Arrays.asList(contentAttachment);
}

public String getMessage() {
Expand All @@ -89,14 +77,10 @@ public File[] getAttachment() {
return attachment;
}

public void setAttachment(File[] attachment) {
public void setAttachment(File... attachment) {
this.attachment = attachment;
}

public void setAttachment(File attachment) {
this.attachment = new File[] { attachment };
}

public void addAttachment(File attachment) {
if (this.attachment == null) {
this.attachment = new File[] { attachment };
Expand All @@ -116,9 +100,8 @@ public void setContentAttachment(List<ContentAttachment> contentAttachment) {
this.contentAttachment = contentAttachment;
}

public void setContentAttachment(ContentAttachment contentAttachment) {
this.contentAttachment = new ArrayList<>();
this.contentAttachment.add(contentAttachment);
public void setContentAttachment(ContentAttachment... contentAttachment) {
this.contentAttachment = Arrays.asList(contentAttachment);
}

public void addContentAttachment(ContentAttachment contentAttachment) {
Expand Down