Skip to content

Commit

Permalink
add generics, remove unnecessary casts, code
Browse files Browse the repository at this point in the history
  • Loading branch information
darkv committed May 1, 2012
1 parent 71eaed9 commit 0168864
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxModalContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public boolean shouldHandle(WOContext context) {
public WOActionResults invokeAction(WORequest worequest, WOContext wocontext) {
WOComponent component = wocontext.component();
if (!booleanValueForBinding("ajax", false, component)) {
WOAssociation action = (WOAssociation) associations().objectForKey("action");
WOAssociation action = associations().objectForKey("action");
if(action != null && wocontext.elementID().equals(wocontext.senderID())) {
return (WOActionResults) action.valueInComponent(component);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public WOActionResults handleRequest(WORequest request, WOContext context) {
WOComponent component = context.component();

WOResponse response = null;
WOAssociation action = (WOAssociation) associations().objectForKey("action");
WOAssociation action = associations().objectForKey("action");
if(action != null) {
action.valueInComponent(component);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ public void finishInitialization() {
ERXObjectStoreCoordinatorPool.initializeIfNecessary();
}

private static Map _qualifierKeys;
private static Map<String, Support> _qualifierKeys;

public static synchronized void registerSQLSupportForSelector(NSSelector selector, EOQualifierSQLGeneration.Support support) {
if(_qualifierKeys == null) {
_qualifierKeys = new HashMap();
_qualifierKeys = new HashMap<String, Support>();
EOQualifierSQLGeneration.Support old = EOQualifierSQLGeneration.Support.supportForClass(EOKeyValueQualifier.class);
EOQualifierSQLGeneration.Support.setSupportForClass(new KeyValueQualifierSQLGenerationSupport(old), EOKeyValueQualifier.class);
}
Expand All @@ -334,7 +334,7 @@ private EOQualifierSQLGeneration.Support supportForQualifier(EOQualifier qualifi
EOQualifierSQLGeneration.Support support = null;
if(qualifier instanceof EOKeyValueQualifier) {
synchronized (_qualifierKeys) {
support = (Support) _qualifierKeys.get(((EOKeyValueQualifier)qualifier).selector().name());
support = _qualifierKeys.get(((EOKeyValueQualifier)qualifier).selector().name());
}
}
if(support == null) {
Expand Down Expand Up @@ -491,7 +491,7 @@ public static boolean adaptorLogging() {
* @param onOff
*/
public static void setAdaptorLogging(boolean onOff) {
Boolean targetState = onOff ? Boolean.TRUE : Boolean.FALSE;
Boolean targetState = Boolean.valueOf(onOff);
if (NSLog.debugLoggingAllowedForGroups(NSLog.DebugGroupSQLGeneration|NSLog.DebugGroupDatabaseAccess) != targetState.booleanValue()) {
// Post a notification to give us a hook to perform other operations necessary to get logging going, e.g. change Logger settings, etc.
NSNotificationCenter.defaultCenter().postNotification(new NSNotification(eoAdaptorLoggingWillChangeNotification, targetState));
Expand Down Expand Up @@ -553,7 +553,7 @@ public static void sessionDidTimeOut(String sessionID) {
* @param ec to be retained.
*/
public static void retainEditingContextForCurrentSession(EOEditingContext ec) {
WOSession s=session();
WOSession s= ERXSession.session();
if (s != null) {
if (_editingContextsPerSession == null) {
_editingContextsPerSession = new NSMutableDictionary();
Expand Down Expand Up @@ -1086,7 +1086,7 @@ public static String addWosidFormValue(String url, WOSession s) {
*/
// MOVEME: Either ERXStringUtilities or fuzzy matching stuff
// FIXME: Should use a StringBuffer instead of creating strings all over the place.
public static String cleanString(String newString, NSArray toBeCleaneds) {
public static String cleanString(String newString, NSArray<String> toBeCleaneds) {
String result=newString;
if (newString!=null) {
for(Enumeration e = toBeCleaneds.objectEnumerator(); e.hasMoreElements();){
Expand Down Expand Up @@ -1454,7 +1454,7 @@ public static void initEOF(final File mainBundleFile, String[] args, boolean ass
}

ERXApplication.setup(args);
((ERXExtensions) ERXFrameworkPrincipal.sharedInstance(ERXExtensions.class)).bundleDidLoad(null);
ERXFrameworkPrincipal.sharedInstance(ERXExtensions.class).bundleDidLoad(null);
}
catch (Exception e) {
throw new NSForwardException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public abstract class ERXFrameworkPrincipal {
protected final Logger log = Logger.getLogger(getClass());

/** holds the mapping between framework principals classes and ERXFrameworkPrincipal objects */
protected static final NSMutableDictionary initializedFrameworks = new NSMutableDictionary();
protected static final NSMutableArray launchingFrameworks = new NSMutableArray();
protected static final NSMutableDictionary<String, ERXFrameworkPrincipal> initializedFrameworks = new NSMutableDictionary<String, ERXFrameworkPrincipal>();
protected static final NSMutableArray<ERXFrameworkPrincipal> launchingFrameworks = new NSMutableArray<ERXFrameworkPrincipal>();

public static class Observer {

Expand All @@ -92,8 +92,7 @@ public static class Observer {
*/
public final void willFinishInitialization(NSNotification n) {
NSNotificationCenter.defaultCenter().removeObserver(this, ERXApplication.ApplicationDidCreateNotification, null);
for (Enumeration enumerator = launchingFrameworks.objectEnumerator(); enumerator.hasMoreElements();) {
ERXFrameworkPrincipal principal = (ERXFrameworkPrincipal) enumerator.nextElement();
for (ERXFrameworkPrincipal principal : launchingFrameworks) {
principal.finishInitialization();
NSLog.debug.appendln("Finished initialization after launch: " + principal);
}
Expand All @@ -111,8 +110,7 @@ public final void willFinishInitialization(NSNotification n) {
*/
public final void didFinishInitialization(NSNotification n) {
NSNotificationCenter.defaultCenter().removeObserver(this);
for (Enumeration enumerator = launchingFrameworks.objectEnumerator(); enumerator.hasMoreElements();) {
ERXFrameworkPrincipal principal = (ERXFrameworkPrincipal) enumerator.nextElement();
for (ERXFrameworkPrincipal principal : launchingFrameworks) {
principal.didFinishInitialization();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,23 @@ public static NSArray fuzzyMatch(String name,
ERXFuzzyMatchCleaner cleaner,
NSArray sortOrderings ){
String eoKey = "eo";
NSMutableArray results = new NSMutableArray();
NSMutableArray<NSMutableDictionary<String, Object>> results = new NSMutableArray<NSMutableDictionary<String, Object>>();
EOFetchSpecification fs = new EOFetchSpecification( entityName, null, null );
fs.setFetchesRawRows( true );
NSArray pks = EOUtilities.entityNamed( ec, entityName ).primaryKeyAttributeNames();
NSMutableArray keyPaths = new NSMutableArray(pks);
NSArray<String> pks = EOUtilities.entityNamed( ec, entityName ).primaryKeyAttributeNames();
NSMutableArray<String> keyPaths = new NSMutableArray<String>(pks);
keyPaths.addObject( propertyKey );
if( synonymsKey != null )
keyPaths.addObject( synonymsKey );
//we use only the strictly necessary keys.
fs.setRawRowKeyPaths( keyPaths );
NSArray rawRows = ec.objectsWithFetchSpecification( fs );
NSArray<NSDictionary<String, Object>> rawRows = ec.objectsWithFetchSpecification( fs );
if(name == null)
name = "";
name = name.toUpperCase();
String cleanedName = cleaner.cleanStringForFuzzyMatching(name);
for(Enumeration e = rawRows.objectEnumerator(); e.hasMoreElements(); ){
NSMutableDictionary dico = ((NSDictionary)e.nextElement()).mutableClone();
NSMutableDictionary<String, Object> dico = ((NSDictionary)e.nextElement()).mutableClone();
Object value = dico.valueForKey(propertyKey);
boolean trySynonyms = true;
//First try to match with the name of the eo
Expand All @@ -254,7 +254,7 @@ public static NSArray fuzzyMatch(String name,
(distance(cleanedName, cleanedComparedString) <=
Math.min((double)cleanedName.length(), (double)cleanedComparedString.length())*adjustement)){
dico.setObjectForKey( new Double(distance(name, comparedString)), _DISTANCE );
NSDictionary pkValues = new NSDictionary( dico.objectsForKeys( pks, NSKeyValueCoding.NullValue ), pks );
NSDictionary<String, Object> pkValues = new NSDictionary<String, Object>(dico.objectsForKeys(pks, NSKeyValueCoding.NullValue ), pks);
dico.setObjectForKey( EOUtilities.faultWithPrimaryKey( ec, entityName, pkValues ), eoKey );
results.addObject( dico );
trySynonyms = false;
Expand All @@ -273,7 +273,7 @@ public static NSArray fuzzyMatch(String name,
(distance(cleanedName, comparedString) <=
Math.min((double)cleanedName.length(), (double)comparedString.length())*adjustement)){
dico.setObjectForKey( new Double(distance(name, comparedString)), _DISTANCE );
NSDictionary pkValues = new NSDictionary( dico.objectsForKeys( pks, NSKeyValueCoding.NullValue ), pks );
NSDictionary<String, Object> pkValues = new NSDictionary<String, Object>(dico.objectsForKeys(pks, NSKeyValueCoding.NullValue ), pks);
dico.setObjectForKey( EOUtilities.faultWithPrimaryKey( ec, entityName, pkValues ), eoKey );
results.addObject( dico );
break;
Expand All @@ -283,7 +283,7 @@ public static NSArray fuzzyMatch(String name,
}
}
if( sortOrderings != null ) {
results = (NSMutableArray)EOSortOrdering.sortedArrayUsingKeyOrderArray(results, sortOrderings);
results = (NSMutableArray<NSMutableDictionary<String, Object>>) EOSortOrdering.sortedArrayUsingKeyOrderArray(results, sortOrderings);
}
return (NSArray) results.valueForKey( eoKey );
}
Expand Down Expand Up @@ -1889,7 +1889,7 @@ public static String stringFromDictionary(NSDictionary dict) {
orderedKeys = ERXArrayUtilities.sortedArraySortedWithKey(orderedKeys, "toString.toLowerCase");
StringBuffer result = new StringBuffer();
for (Enumeration keys = orderedKeys.objectEnumerator(); keys.hasMoreElements();) {
Object key = (Object) keys.nextElement();
Object key = keys.nextElement();
Object value = dict.objectForKey(key);
String stringValue = NSPropertyListSerialization.stringFromPropertyList(value);
String stringKey = NSPropertyListSerialization.stringFromPropertyList(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public void run() {
catch (InterruptedException t) {
// ignore
}
InstantMessengerAdaptor.this.removeExpiredConversations();
removeExpiredConversations();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void appendToResponse(WOResponse response, WOContext context) {

@Override
public WOActionResults invokeAction(WORequest request, WOContext context) {
String s = null;
WOActionResults results = null;
if (context.elementID().equals(context.senderID())) {
actionInvoked(request, context);
Expand Down

0 comments on commit 0168864

Please sign in to comment.