Skip to content

Commit

Permalink
Merge pull request #52 from hprange/bugfix/wonder6And7Incompatibility
Browse files Browse the repository at this point in the history
Fix binary incompatibility between Wonder 6 and 7
  • Loading branch information
hprange authored Nov 28, 2017
2 parents 9ceb9ee + 2eb1a57 commit 5fa785a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/wounit/rules/MockEditingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.wounit.rules;

import static com.wounit.rules.WOUnitUtils.arrayMinusArray;

import java.lang.reflect.Field;

import com.webobjects.eoaccess.EOAttribute;
Expand All @@ -40,7 +42,6 @@
import er.extensions.eof.ERXModelGroup;
import er.extensions.eof.ERXQ;
import er.extensions.eof.ERXS;
import er.extensions.foundation.ERXArrayUtilities;

/**
* <code>MockEditingContext</code> is a subclass of
Expand Down Expand Up @@ -264,7 +265,7 @@ public void insertSavedObject(EOEnterpriseObject eo) {
@Override
public NSArray<EOEnterpriseObject> objectsWithFetchSpecification(EOFetchSpecification fetchSpecification, EOEditingContext editingContext) {
@SuppressWarnings("unchecked")
NSArray<EOEnterpriseObject> availableObjects = ERXArrayUtilities.arrayMinusArray(registeredObjects(), deletedObjects());
NSArray<EOEnterpriseObject> availableObjects = arrayMinusArray(registeredObjects(), deletedObjects());

String entityName = fetchSpecification.entityName();

Expand Down Expand Up @@ -321,7 +322,7 @@ public void objectWillChange(Object object) {
@Override
public void saveChanges() {
@SuppressWarnings("unchecked")
NSArray<EOEnterpriseObject> insertedObjects = ERXArrayUtilities.arrayMinusArray(insertedObjects(), deletedObjects());
NSArray<EOEnterpriseObject> insertedObjects = arrayMinusArray(insertedObjects(), deletedObjects());

super.saveChanges();

Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/wounit/rules/WOUnitUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (C) 2009 hprange <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package com.wounit.rules;

import java.util.Enumeration;

import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSMutableArray;
import com.webobjects.foundation.NSSet;

/**
* This class was created to avoid a binary incompatibility between Wonder 6 and
* 7 and make WOUnit compatible with both versions.
*
* @author <a href="mailto:[email protected]">Henrique Prange</a>
* @since 1.2
*/
class WOUnitUtils {
/**
* Subtracts the contents of one array from another. The order of the array
* should be preseved.
*
* @param main
* array to have values removed from it.
* @param minus
* array of values to remove from the main array
* @return array after performing subtraction.
*/
static <T> NSArray<T> arrayMinusArray(NSArray<T> main, NSArray<?> minus) {
NSSet<Object> minusSet = new NSSet<Object>(minus);
NSMutableArray<T> mutableResult = new NSMutableArray<T>(main.count());
Enumeration<T> e = main.objectEnumerator();

while (e.hasMoreElements()) {
T obj = e.nextElement();

if (!minusSet.containsObject(obj)) {
mutableResult.addObject(obj);
}
}

return mutableResult.immutableClone();
}

private WOUnitUtils() {
// Cannot be instantiated
}
}

0 comments on commit 5fa785a

Please sign in to comment.