Skip to content

Commit 75904e2

Browse files
committed
Merge pull request OfficeDev#342 from vbauer/minor-bugs
Remove unnecessary assertions, Simplify constant expressions. minor bug fixes
2 parents 9ad6c6b + 794b44e commit 75904e2

12 files changed

Lines changed: 76 additions & 110 deletions

File tree

src/main/java/microsoft/exchange/webservices/data/core/service/item/Item.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ public Item(ExchangeService service) throws Exception {
9999
* @param parentAttachment The parent attachment.
100100
* @throws Exception the exception
101101
*/
102-
public Item(ItemAttachment parentAttachment) throws Exception {
102+
public Item(final ItemAttachment parentAttachment) throws Exception {
103103
this(parentAttachment.getOwner().getService());
104-
EwsUtilities.ewsAssert(parentAttachment != null, "Item.ctor", "parentAttachment is null");
105-
106104
this.parentAttachment = parentAttachment;
107105
}
108106

src/main/java/microsoft/exchange/webservices/data/core/service/response/PostReply.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public final class PostReply extends ServiceObject {
6767
*/
6868
public PostReply(Item referenceItem) throws Exception {
6969
super(referenceItem.getService());
70-
EwsUtilities.ewsAssert(referenceItem != null, "PostReply.ctor", "referenceItem is null");
7170
referenceItem.throwIfThisIsNew();
7271

7372
this.referenceItem = referenceItem;

src/main/java/microsoft/exchange/webservices/data/core/service/response/ResponseObject.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public abstract class ResponseObject<TMessage extends EmailMessage> extends Serv
6767
*/
6868
protected ResponseObject(Item referenceItem) throws Exception {
6969
super(referenceItem.getService());
70-
EwsUtilities.ewsAssert(referenceItem != null, "ResponseObject.ctor", "referenceItem is null");
7170
referenceItem.throwIfThisIsNew();
7271
this.referenceItem = referenceItem;
7372
}

src/main/java/microsoft/exchange/webservices/data/property/complex/AttachmentCollection.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,31 @@ public void validate() throws Exception {
383383
for (int attachmentIndex = 0; attachmentIndex < this.getAddedItems()
384384
.size(); attachmentIndex++) {
385385
final Attachment attachment = this.getAddedItems().get(attachmentIndex);
386-
if (attachment != null && attachment.isNew() && attachment instanceof FileAttachment) {
387-
// At the server side, only the last attachment with
388-
// IsContactPhoto is kept, all other IsContactPhoto
389-
// attachments are removed. CreateAttachment will generate
390-
// AttachmentId for each of such attachments (although
391-
// only the last one is valid).
392-
//
393-
// With E14 SP2 CreateItemWithAttachment, such request will only
394-
// return 1 AttachmentId; but the client
395-
// expects to see all, so let us prevent such "invalid" request
396-
// in the first place.
397-
//
398-
// The IsNew check is to still let CreateAttachmentRequest allow
399-
// multiple IsContactPhoto attachments.
400-
//
401-
if (((FileAttachment) attachment).isContactPhoto()) {
402-
if (contactPhotoFound) {
403-
throw new ServiceValidationException(
404-
"Multiple contact photos in attachment.");
386+
if (attachment != null) {
387+
if (attachment.isNew() && attachment instanceof FileAttachment) {
388+
// At the server side, only the last attachment with
389+
// IsContactPhoto is kept, all other IsContactPhoto
390+
// attachments are removed. CreateAttachment will generate
391+
// AttachmentId for each of such attachments (although
392+
// only the last one is valid).
393+
//
394+
// With E14 SP2 CreateItemWithAttachment, such request will only
395+
// return 1 AttachmentId; but the client
396+
// expects to see all, so let us prevent such "invalid" request
397+
// in the first place.
398+
//
399+
// The IsNew check is to still let CreateAttachmentRequest allow
400+
// multiple IsContactPhoto attachments.
401+
//
402+
if (((FileAttachment) attachment).isContactPhoto()) {
403+
if (contactPhotoFound) {
404+
throw new ServiceValidationException("Multiple contact photos in attachment.");
405+
}
406+
contactPhotoFound = true;
405407
}
406-
contactPhotoFound = true;
407408
}
409+
attachment.validate(attachmentIndex);
408410
}
409-
attachment.validate(attachmentIndex);
410411
}
411412
}
412413
}

src/main/java/microsoft/exchange/webservices/data/property/complex/ExtendedProperty.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
3232
import microsoft.exchange.webservices.data.misc.MapiTypeConverter;
3333
import microsoft.exchange.webservices.data.property.definition.ExtendedPropertyDefinition;
34+
import org.apache.commons.lang3.StringUtils;
3435

3536
import javax.xml.stream.XMLStreamException;
3637

@@ -213,19 +214,13 @@ private String getStringValue() {
213214
* @return boolean
214215
*/
215216
@Override
216-
public boolean equals(Object obj) {
217-
217+
public boolean equals(final Object obj) {
218218
if (obj instanceof ExtendedProperty) {
219-
ExtendedProperty other = (ExtendedProperty) obj;
220-
if (other.getPropertyDefinition().equals(
221-
this.getPropertyDefinition())) {
222-
return this.getStringValue().equals(other.getStringValue());
223-
} else {
224-
return false;
225-
}
226-
} else {
227-
return false;
219+
final ExtendedProperty other = (ExtendedProperty) obj;
220+
return other.getPropertyDefinition().equals(this.getPropertyDefinition())
221+
&& StringUtils.equals(this.getStringValue(), other.getStringValue());
228222
}
223+
return false;
229224
}
230225

231226
/**

src/main/java/microsoft/exchange/webservices/data/property/complex/FolderId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ protected boolean getIsValid() {
207207
*/
208208
@Override
209209
public boolean equals(Object obj) {
210-
if (obj == this || (obj == null && this == null)) {
210+
if (obj == this) {
211211
return true;
212212
} else if (obj instanceof FolderId) {
213213
FolderId other = (FolderId) obj;

src/main/java/microsoft/exchange/webservices/data/property/complex/ServiceId.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import microsoft.exchange.webservices.data.core.EwsUtilities;
2929
import microsoft.exchange.webservices.data.core.XmlAttributeNames;
3030
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
31+
import org.apache.commons.lang3.StringUtils;
3132

3233
/**
3334
* Represents the Id of an Exchange object.
@@ -172,14 +173,8 @@ public void setChangeKey(String changeKey) {
172173
* @param other The ServiceId to compare with the current ServiceId.
173174
* @return true if equal otherwise false.
174175
*/
175-
public boolean sameIdAndChangeKey(ServiceId other) {
176-
if (this.equals(other)) {
177-
return ((this.getChangeKey() == null) &&
178-
(other.getChangeKey() == null)) ||
179-
this.getChangeKey().equals(other.getChangeKey());
180-
} else {
181-
return false;
182-
}
176+
public boolean sameIdAndChangeKey(final ServiceId other) {
177+
return this.equals(other) && StringUtils.equals(this.getChangeKey(), other.getChangeKey());
183178
}
184179

185180
/**

src/main/java/microsoft/exchange/webservices/data/property/complex/recurrence/DayOfTheWeekCollection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import microsoft.exchange.webservices.data.core.exception.misc.ArgumentOutOfRangeException;
3333
import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
3434
import microsoft.exchange.webservices.data.property.complex.ComplexProperty;
35+
import org.apache.commons.lang3.StringUtils;
3536

3637
import javax.xml.stream.XMLStreamException;
3738

@@ -109,7 +110,7 @@ public void loadFromXml(EwsServiceXmlReader reader, String xmlElementName)
109110
throws XMLStreamException, ServiceXmlSerializationException {
110111
String daysOfWeekAsString = this.toString(" ");
111112

112-
if (!(daysOfWeekAsString == null || daysOfWeekAsString.isEmpty())) {
113+
if (!StringUtils.isEmpty(daysOfWeekAsString)) {
113114
writer.writeElementValue(XmlNamespace.Types,
114115
XmlElementNames.DaysOfWeek, daysOfWeekAsString);
115116
}

src/main/java/microsoft/exchange/webservices/data/property/complex/time/TimeZoneDefinition.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.ArrayList;
3838
import java.util.Collections;
3939
import java.util.Comparator;
40+
import java.util.Date;
4041
import java.util.HashMap;
4142
import java.util.Iterator;
4243
import java.util.List;
@@ -109,20 +110,21 @@ public class TimeZoneDefinition extends ComplexProperty implements Comparator<Ti
109110
* positive number if x is greater than y.
110111
*/
111112
@Override
112-
public int compare(TimeZoneTransition x, TimeZoneTransition y) {
113+
public int compare(final TimeZoneTransition x, final TimeZoneTransition y) {
113114
if (x == y) {
114115
return 0;
115-
} else if (x instanceof TimeZoneTransition) {
116-
return -1;
117-
} else if (y instanceof TimeZoneTransition) {
118-
return 1;
119-
} else {
120-
AbsoluteDateTransition firstTransition = (AbsoluteDateTransition) x;
121-
AbsoluteDateTransition secondTransition = (AbsoluteDateTransition) y;
116+
} else if (x != null && y != null) {
117+
final AbsoluteDateTransition firstTransition = (AbsoluteDateTransition) x;
118+
final AbsoluteDateTransition secondTransition = (AbsoluteDateTransition) y;
122119

123-
return firstTransition.getDateTime().compareTo(
124-
secondTransition.getDateTime());
120+
final Date firstDateTime = firstTransition.getDateTime();
121+
final Date secondDateTime = secondTransition.getDateTime();
122+
123+
return firstDateTime.compareTo(secondDateTime);
124+
} else if (y == null) {
125+
return 1;
125126
}
127+
return -1;
126128
}
127129

128130
/**

src/main/java/microsoft/exchange/webservices/data/property/definition/ComplexPropertyDefinitionBase.java

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525

2626
import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
2727
import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
28+
import microsoft.exchange.webservices.data.core.ExchangeService;
2829
import microsoft.exchange.webservices.data.core.PropertyBag;
29-
import microsoft.exchange.webservices.data.core.service.ServiceObject;
3030
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
31-
import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags;
3231
import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
32+
import microsoft.exchange.webservices.data.core.enumeration.property.PropertyDefinitionFlags;
33+
import microsoft.exchange.webservices.data.core.service.ServiceObject;
3334
import microsoft.exchange.webservices.data.misc.OutParam;
3435
import microsoft.exchange.webservices.data.property.complex.ComplexProperty;
3536

@@ -92,33 +93,21 @@ protected ComplexPropertyDefinitionBase(String xmlElementName, String uri,
9293
* @param propertyBag The property bag.
9394
* @throws Exception the exception
9495
*/
95-
protected void internalLoadFromXml(EwsServiceXmlReader reader,
96-
PropertyBag propertyBag) throws Exception {
97-
OutParam<Object> complexProperty = new OutParam<Object>();
96+
protected void internalLoadFromXml(
97+
final EwsServiceXmlReader reader, final PropertyBag propertyBag
98+
) throws Exception {
99+
final OutParam<ComplexProperty> complexProperty = new OutParam<ComplexProperty>();
100+
final boolean justCreated = getPropertyInstance(propertyBag, complexProperty);
98101

99-
boolean justCreated = getPropertyInstance(propertyBag, complexProperty);
100102
if (!justCreated && this.hasFlag(PropertyDefinitionFlags.UpdateCollectionItems,
101103
propertyBag.getOwner().getService().getRequestedServerVersion())) {
102-
ComplexProperty c = (ComplexProperty) complexProperty.getParam();
103-
if (complexProperty.getParam() instanceof ComplexProperty) {
104-
c.updateFromXml(reader, reader.getLocalName());
105-
}
106-
107-
108-
104+
final ComplexProperty c = complexProperty.getParam();
105+
c.updateFromXml(reader, reader.getLocalName());
109106
} else {
110-
ComplexProperty c = (ComplexProperty) complexProperty.getParam();
107+
final ComplexProperty c = complexProperty.getParam();
111108
c.loadFromXml(reader, reader.getLocalName());
112109
}
113-
/*if (!propertyBag.tryGetValue(this, complexProperty) ||
114-
!this.hasFlag(PropertyDefinitionFlags.ReuseInstance)) {
115-
complexProperty.setParam(this.createPropertyInstance(propertyBag
116-
.getOwner()));
117-
}
118-
if (complexProperty.getParam() instanceof ComplexProperty) {
119-
ComplexProperty c = (ComplexProperty)complexProperty.getParam();
120-
c.loadFromXml(reader, reader.getLocalName());
121-
}*/
110+
122111
propertyBag.setObjectFromPropertyDefinition(this, complexProperty
123112
.getParam());
124113
}
@@ -132,17 +121,18 @@ protected void internalLoadFromXml(EwsServiceXmlReader reader,
132121
* @param complexProperty The property instance.
133122
* @return True if the instance is newly created.
134123
*/
135-
private boolean getPropertyInstance(PropertyBag propertyBag, OutParam<Object> complexProperty) {
136-
boolean retValue = false;
137-
if (!propertyBag.tryGetValue(this, complexProperty) || !this
138-
.hasFlag(PropertyDefinitionFlags.ReuseInstance,
139-
propertyBag.getOwner().getService().getRequestedServerVersion())) {
140-
complexProperty.setParam(this.createPropertyInstance(propertyBag
141-
.getOwner()));
142-
retValue = true;
124+
private boolean getPropertyInstance(
125+
final PropertyBag propertyBag, final OutParam<ComplexProperty> complexProperty
126+
) {
127+
final ServiceObject owner = propertyBag.getOwner();
128+
final ExchangeService service = owner.getService();
129+
130+
if (!propertyBag.tryGetValue(this, complexProperty)
131+
|| !hasFlag(PropertyDefinitionFlags.ReuseInstance, service.getRequestedServerVersion())) {
132+
complexProperty.setParam(createPropertyInstance(owner));
133+
return true;
143134
}
144-
return retValue;
145-
135+
return false;
146136
}
147137

148138
/**

0 commit comments

Comments
 (0)