Skip to content

Commit

Permalink
Change error user info contains() method to has().
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueRiverInteractive committed Jun 5, 2015
1 parent 4471175 commit 2ab24a1
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 56 deletions.
39 changes: 22 additions & 17 deletions cocoatouch/src/main/java/org/robovm/apple/cloudkit/CKError.java
Expand Up @@ -19,6 +19,7 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -49,6 +50,16 @@ protected CKError(SkipInit skipInit) {
/*<constructors>*//*</constructors>*/ /*<constructors>*//*</constructors>*/
/*<properties>*//*</properties>*/ /*<properties>*//*</properties>*/
/*<members>*//*</members>*/ /*<members>*//*</members>*/
private NSErrorUserInfo userInfo;

/* Convenience methods */
private NSErrorUserInfo getCachedUserInfo() {
if (userInfo == null) {
userInfo = getUserInfo();
}
return userInfo;
}

@Override @Override
public CKErrorCode getErrorCode() { public CKErrorCode getErrorCode() {
CKErrorCode code = null; CKErrorCode code = null;
Expand All @@ -60,45 +71,39 @@ public CKErrorCode getErrorCode() {
return code; return code;
} }


/* Convenience methods */
public NSDictionary<?, ?> getPartialErrors() { public NSDictionary<?, ?> getPartialErrors() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(CKErrorUserInfoKey.PartialErrorsByItemID)) {
if (data.contains(CKErrorUserInfoKey.PartialErrorsByItemID)) { NSDictionary<?, ?> val = (NSDictionary<?, ?>) getCachedUserInfo().get(CKErrorUserInfoKey.PartialErrorsByItemID);
NSDictionary<?, ?> val = (NSDictionary<?, ?>) data.get(CKErrorUserInfoKey.PartialErrorsByItemID);
return val; return val;
} }
return null; return null;
} }


public CKRecord getAncestorRecord() { public CKRecord getAncestorRecord() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(CKErrorUserInfoKey.AncestorRecord)) {
if (data.contains(CKErrorUserInfoKey.AncestorRecord)) { CKRecord val = (CKRecord) getCachedUserInfo().get(CKErrorUserInfoKey.AncestorRecord);
CKRecord val = (CKRecord) data.get(CKErrorUserInfoKey.AncestorRecord);
return val; return val;
} }
return null; return null;
} }
public CKRecord getServerRecord() { public CKRecord getServerRecord() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(CKErrorUserInfoKey.ServerRecord)) {
if (data.contains(CKErrorUserInfoKey.ServerRecord)) { CKRecord val = (CKRecord) getCachedUserInfo().get(CKErrorUserInfoKey.ServerRecord);
CKRecord val = (CKRecord) data.get(CKErrorUserInfoKey.ServerRecord);
return val; return val;
} }
return null; return null;
} }
public CKRecord getClientRecord() { public CKRecord getClientRecord() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(CKErrorUserInfoKey.ClientRecord)) {
if (data.contains(CKErrorUserInfoKey.ClientRecord)) { CKRecord val = (CKRecord) getCachedUserInfo().get(CKErrorUserInfoKey.ClientRecord);
CKRecord val = (CKRecord) data.get(CKErrorUserInfoKey.ClientRecord);
return val; return val;
} }
return null; return null;
} }


public double getRetryAfterTime() { public double retriesAfterTime() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(CKErrorUserInfoKey.RetryAfter)) {
if (data.contains(CKErrorUserInfoKey.RetryAfter)) { NSNumber val = (NSNumber) getCachedUserInfo().get(CKErrorUserInfoKey.RetryAfter);
NSNumber val = (NSNumber) data.get(CKErrorUserInfoKey.RetryAfter);
return val.doubleValue(); return val.doubleValue();
} }
return -1; return -1;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -48,6 +49,16 @@ protected CLError(SkipInit skipInit) {
/*<constants>*//*</constants>*/ /*<constants>*//*</constants>*/
/*<properties>*//*</properties>*/ /*<properties>*//*</properties>*/
/*<members>*//*</members>*/ /*<members>*//*</members>*/
private NSErrorUserInfo userInfo;

/* Convenience methods */
private NSErrorUserInfo getCachedUserInfo() {
if (userInfo == null) {
userInfo = getUserInfo();
}
return userInfo;
}

@Override @Override
public CLErrorCode getErrorCode() { public CLErrorCode getErrorCode() {
CLErrorCode code = null; CLErrorCode code = null;
Expand All @@ -60,9 +71,8 @@ public CLErrorCode getErrorCode() {
} }


public CLRegion getAlternateRegion() { public CLRegion getAlternateRegion() {
NSErrorUserInfo userInfo = getUserInfo(); if (getCachedUserInfo().has(CLErrorUserInfoKey.AlternateRegion)) {
if (userInfo.contains(CLErrorUserInfoKey.AlternateRegion)) { CLRegion val = (CLRegion)getCachedUserInfo().get(CLErrorUserInfoKey.AlternateRegion);
CLRegion val = (CLRegion)userInfo.get(CLErrorUserInfoKey.AlternateRegion);
return val; return val;
} }
return null; return null;
Expand Down
Expand Up @@ -101,15 +101,15 @@ public NSObject get(NSErrorUserInfoKey attribute) {
public <T extends NativeObject> T get(NSErrorUserInfoKey attribute, Class<T> type) { public <T extends NativeObject> T get(NSErrorUserInfoKey attribute, Class<T> type) {
return data.get(attribute.value(), type); return data.get(attribute.value(), type);
} }
public boolean contains(String attribute) { public boolean has(String attribute) {
return data.containsKey(new NSString(attribute)); return data.containsKey(new NSString(attribute));
} }
public boolean contains(NSErrorUserInfoKey attribute) { public boolean has(NSErrorUserInfoKey attribute) {
return data.containsKey(attribute.value()); return data.containsKey(attribute.value());
} }


public NSError getUnderlyingError() { public NSError getUnderlyingError() {
if (contains(NSCocoaErrorUserInfoKey.UnderlyingError)) { if (has(NSCocoaErrorUserInfoKey.UnderlyingError)) {
NSError val = (NSError)get(NSCocoaErrorUserInfoKey.UnderlyingError); NSError val = (NSError)get(NSCocoaErrorUserInfoKey.UnderlyingError);
return val; return val;
} }
Expand All @@ -120,7 +120,7 @@ public NSErrorUserInfo setUnderlyingError(NSError error) {
return this; return this;
} }
public String getLocalizedDescription() { public String getLocalizedDescription() {
if (contains(NSCocoaErrorUserInfoKey.LocalizedDescription)) { if (has(NSCocoaErrorUserInfoKey.LocalizedDescription)) {
NSString val = (NSString)get(NSCocoaErrorUserInfoKey.LocalizedDescription); NSString val = (NSString)get(NSCocoaErrorUserInfoKey.LocalizedDescription);
return val.toString(); return val.toString();
} }
Expand All @@ -131,7 +131,7 @@ public NSErrorUserInfo setLocalizedDescription(String description) {
return this; return this;
} }
public String getLocalizedFailureReason() { public String getLocalizedFailureReason() {
if (contains(NSCocoaErrorUserInfoKey.LocalizedFailureReason)) { if (has(NSCocoaErrorUserInfoKey.LocalizedFailureReason)) {
NSString val = (NSString)get(NSCocoaErrorUserInfoKey.LocalizedFailureReason); NSString val = (NSString)get(NSCocoaErrorUserInfoKey.LocalizedFailureReason);
return val.toString(); return val.toString();
} }
Expand All @@ -142,7 +142,7 @@ public NSErrorUserInfo setLocalizedFailureReason(String reason) {
return this; return this;
} }
public String getLocalizedRecoverySuggestion() { public String getLocalizedRecoverySuggestion() {
if (contains(NSCocoaErrorUserInfoKey.LocalizedRecoverySuggestion)) { if (has(NSCocoaErrorUserInfoKey.LocalizedRecoverySuggestion)) {
NSString val = (NSString)get(NSCocoaErrorUserInfoKey.LocalizedRecoverySuggestion); NSString val = (NSString)get(NSCocoaErrorUserInfoKey.LocalizedRecoverySuggestion);
return val.toString(); return val.toString();
} }
Expand All @@ -154,7 +154,7 @@ public NSErrorUserInfo setLocalizedRecoverySuggestion(String suggestion) {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<String> getLocalizedRecoveryOptions() { public List<String> getLocalizedRecoveryOptions() {
if (contains(NSCocoaErrorUserInfoKey.LocalizedRecoveryOptions)) { if (has(NSCocoaErrorUserInfoKey.LocalizedRecoveryOptions)) {
NSArray<NSString> val = (NSArray<NSString>)get(NSCocoaErrorUserInfoKey.LocalizedRecoveryOptions); NSArray<NSString> val = (NSArray<NSString>)get(NSCocoaErrorUserInfoKey.LocalizedRecoveryOptions);
return val.asStringList(); return val.asStringList();
} }
Expand All @@ -165,7 +165,7 @@ public NSErrorUserInfo setLocalizedRecoveryOptions(List<String> options) {
return this; return this;
} }
public NSErrorRecoveryAttempting getRecoveryAttempter() { public NSErrorRecoveryAttempting getRecoveryAttempter() {
if (contains(NSCocoaErrorUserInfoKey.RecoveryAttempter)) { if (has(NSCocoaErrorUserInfoKey.RecoveryAttempter)) {
NSErrorRecoveryAttempting val = (NSErrorRecoveryAttempting)get(NSCocoaErrorUserInfoKey.RecoveryAttempter); NSErrorRecoveryAttempting val = (NSErrorRecoveryAttempting)get(NSCocoaErrorUserInfoKey.RecoveryAttempter);
return val; return val;
} }
Expand All @@ -176,7 +176,7 @@ public NSErrorUserInfo setRecoveryAttempter(NSErrorRecoveryAttempting recovery)
return this; return this;
} }
public String getHelpAnchor() { public String getHelpAnchor() {
if (contains(NSCocoaErrorUserInfoKey.HelpAnchor)) { if (has(NSCocoaErrorUserInfoKey.HelpAnchor)) {
NSString val = (NSString)get(NSCocoaErrorUserInfoKey.HelpAnchor); NSString val = (NSString)get(NSCocoaErrorUserInfoKey.HelpAnchor);
return val.toString(); return val.toString();
} }
Expand All @@ -187,7 +187,7 @@ public NSErrorUserInfo setHelpAnchor(String help) {
return this; return this;
} }
public NSStringEncoding getStringEncoding() { public NSStringEncoding getStringEncoding() {
if (contains(NSCocoaErrorUserInfoKey.StringEncoding)) { if (has(NSCocoaErrorUserInfoKey.StringEncoding)) {
NSNumber val = (NSNumber)get(NSCocoaErrorUserInfoKey.StringEncoding); NSNumber val = (NSNumber)get(NSCocoaErrorUserInfoKey.StringEncoding);
return NSStringEncoding.valueOf(val.longValue()); return NSStringEncoding.valueOf(val.longValue());
} }
Expand All @@ -198,7 +198,7 @@ public NSErrorUserInfo setStringEncoding(NSStringEncoding encoding) {
return this; return this;
} }
public String getFilePath() { public String getFilePath() {
if (contains(NSCocoaErrorUserInfoKey.FilePath)) { if (has(NSCocoaErrorUserInfoKey.FilePath)) {
NSString val = (NSString)get(NSCocoaErrorUserInfoKey.FilePath); NSString val = (NSString)get(NSCocoaErrorUserInfoKey.FilePath);
return val.toString(); return val.toString();
} }
Expand All @@ -209,7 +209,7 @@ public NSErrorUserInfo setFilePath(String path) {
return this; return this;
} }
public NSURL getURL() { public NSURL getURL() {
if (contains(NSCocoaErrorUserInfoKey.URL)) { if (has(NSCocoaErrorUserInfoKey.URL)) {
NSURL val = (NSURL)get(NSCocoaErrorUserInfoKey.URL); NSURL val = (NSURL)get(NSCocoaErrorUserInfoKey.URL);
return val; return val;
} }
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -56,6 +57,16 @@ protected NSURLError(SkipInit skipInit) {
/*<constructors>*//*</constructors>*/ /*<constructors>*//*</constructors>*/
/*<properties>*//*</properties>*/ /*<properties>*//*</properties>*/
/*<members>*//*</members>*/ /*<members>*//*</members>*/
private NSErrorUserInfo userInfo;

/* Convenience methods */
private NSErrorUserInfo getCachedUserInfo() {
if (userInfo == null) {
userInfo = getUserInfo();
}
return userInfo;
}

@Override @Override
public NSURLErrorCode getErrorCode() { public NSURLErrorCode getErrorCode() {
NSURLErrorCode code = null; NSURLErrorCode code = null;
Expand All @@ -71,9 +82,8 @@ public NSURLErrorCode getErrorCode() {
* @since Available in iOS 4.0 and later. * @since Available in iOS 4.0 and later.
*/ */
public NSURL getFailingURL() { public NSURL getFailingURL() {
NSErrorUserInfo userInfo = getUserInfo(); if (getCachedUserInfo().has(NSURLErrorUserInfoKey.FailingURL)) {
if (userInfo.contains(NSURLErrorUserInfoKey.FailingURL)) { NSURL val = (NSURL)getCachedUserInfo().get(NSURLErrorUserInfoKey.FailingURL);
NSURL val = (NSURL)userInfo.get(NSURLErrorUserInfoKey.FailingURL);
return val; return val;
} }
return null; return null;
Expand All @@ -82,9 +92,8 @@ public NSURL getFailingURL() {
* @since Available in iOS 4.0 and later. * @since Available in iOS 4.0 and later.
*/ */
public String getFailingURLString() { public String getFailingURLString() {
NSErrorUserInfo userInfo = getUserInfo(); if (getCachedUserInfo().has(NSURLErrorUserInfoKey.FailingURLString)) {
if (userInfo.contains(NSURLErrorUserInfoKey.FailingURLString)) { NSString val = (NSString)getCachedUserInfo().get(NSURLErrorUserInfoKey.FailingURLString);
NSString val = (NSString)userInfo.get(NSURLErrorUserInfoKey.FailingURLString);
return val.toString(); return val.toString();
} }
return null; return null;
Expand All @@ -94,9 +103,8 @@ public String getFailingURLString() {
*/ */
@WeaklyLinked @WeaklyLinked
public SecTrust getFailingURLPeerTrust() { public SecTrust getFailingURLPeerTrust() {
NSErrorUserInfo userInfo = getUserInfo(); if (getCachedUserInfo().has(NSURLErrorUserInfoKey.FailingURLPeerTrust)) {
if (userInfo.contains(NSURLErrorUserInfoKey.FailingURLPeerTrust)) { SecTrust val = getCachedUserInfo().get(NSURLErrorUserInfoKey.FailingURLPeerTrust, SecTrust.class);
SecTrust val = userInfo.get(NSURLErrorUserInfoKey.FailingURLPeerTrust, SecTrust.class);
return val; return val;
} }
return null; return null;
Expand All @@ -107,9 +115,8 @@ public SecTrust getFailingURLPeerTrust() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<NSURLProperty> getUnsetProperties() { public List<NSURLProperty> getUnsetProperties() {
List<NSURLProperty> properties = new ArrayList<>(); List<NSURLProperty> properties = new ArrayList<>();
NSErrorUserInfo userInfo = getUserInfo(); if (getCachedUserInfo().has(NSURLErrorUserInfoKey.KeysOfUnsetValues)) {
if (userInfo.contains(NSURLErrorUserInfoKey.KeysOfUnsetValues)) { NSArray<NSString> val = (NSArray<NSString>)getCachedUserInfo().get(NSURLErrorUserInfoKey.KeysOfUnsetValues);
NSArray<NSString> val = (NSArray<NSString>)userInfo.get(NSURLErrorUserInfoKey.KeysOfUnsetValues);
for (NSString s : val) { for (NSString s : val) {
NSURLProperty p = NSURLProperty.valueOf(s); NSURLProperty p = NSURLProperty.valueOf(s);
if (p != null) properties.add(p); if (p != null) properties.add(p);
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -51,6 +52,16 @@ protected GLKTextureLoaderError (SkipInit skipInit) {
/*<constants>*//*</constants>*/ /*<constants>*//*</constants>*/
/*<properties>*//*</properties>*/ /*<properties>*//*</properties>*/
/*<members>*//*</members>*/ /*<members>*//*</members>*/
private NSErrorUserInfo userInfo;

/* Convenience methods */
private NSErrorUserInfo getCachedUserInfo() {
if (userInfo == null) {
userInfo = getUserInfo();
}
return userInfo;
}

@Override @Override
public GLKTextureLoaderErrorCode getErrorCode () { public GLKTextureLoaderErrorCode getErrorCode () {
GLKTextureLoaderErrorCode code = null; GLKTextureLoaderErrorCode code = null;
Expand All @@ -67,9 +78,8 @@ public GLKTextureLoaderErrorCode getErrorCode () {
* @since Available in iOS 5.0 and later. * @since Available in iOS 5.0 and later.
*/ */
public String getError() { public String getError() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(GLKErrorUserInfoKey.Error)) {
if (data.contains(GLKErrorUserInfoKey.Error)) { NSString val = (NSString) getCachedUserInfo().get(GLKErrorUserInfoKey.Error);
NSString val = (NSString) data.get(GLKErrorUserInfoKey.Error);
return val.toString(); return val.toString();
} }
return null; return null;
Expand All @@ -78,9 +88,8 @@ public String getError() {
* @since Available in iOS 5.0 and later. * @since Available in iOS 5.0 and later.
*/ */
public long getGLError() { public long getGLError() {
NSErrorUserInfo data = getUserInfo(); if (getCachedUserInfo().has(GLKErrorUserInfoKey.GLError)) {
if (data.contains(GLKErrorUserInfoKey.GLError)) { NSNumber val = (NSNumber) getCachedUserInfo().get(GLKErrorUserInfoKey.GLError);
NSNumber val = (NSNumber) data.get(GLKErrorUserInfoKey.GLError);
return val.longValue(); return val.longValue();
} }
return 0; return 0;
Expand Down
16 changes: 13 additions & 3 deletions cocoatouch/src/main/java/org/robovm/apple/homekit/HMError.java
Expand Up @@ -19,6 +19,7 @@
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
import java.util.*; import java.util.*;

import org.robovm.objc.*; import org.robovm.objc.*;
import org.robovm.objc.annotation.*; import org.robovm.objc.annotation.*;
import org.robovm.objc.block.*; import org.robovm.objc.block.*;
Expand Down Expand Up @@ -47,6 +48,16 @@ protected HMError(SkipInit skipInit) {
/*<constructors>*//*</constructors>*/ /*<constructors>*//*</constructors>*/
/*<properties>*//*</properties>*/ /*<properties>*//*</properties>*/
/*<members>*//*</members>*/ /*<members>*//*</members>*/
private NSErrorUserInfo userInfo;

/* Convenience methods */
private NSErrorUserInfo getCachedUserInfo() {
if (userInfo == null) {
userInfo = getUserInfo();
}
return userInfo;
}

@Override @Override
public HMErrorCode getErrorCode() { public HMErrorCode getErrorCode() {
HMErrorCode code = null; HMErrorCode code = null;
Expand All @@ -60,9 +71,8 @@ public HMErrorCode getErrorCode() {


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public NSDictionary<NSUUID, NSError> getFailedAccessories() { public NSDictionary<NSUUID, NSError> getFailedAccessories() {
NSErrorUserInfo userInfo = getUserInfo(); if (getCachedUserInfo().has(HMErrorUserInfoKey.FailedAccessories)) {
if (userInfo.contains(HMErrorUserInfoKey.FailedAccessories)) { NSDictionary<NSUUID, NSError> val = (NSDictionary<NSUUID, NSError>) getCachedUserInfo().get(HMErrorUserInfoKey.FailedAccessories);
NSDictionary<NSUUID, NSError> val = (NSDictionary<NSUUID, NSError>) userInfo.get(HMErrorUserInfoKey.FailedAccessories);
return val; return val;
} }
return null; return null;
Expand Down

0 comments on commit 2ab24a1

Please sign in to comment.