Ignore:
Timestamp:
12/01/15 10:59:02 (9 years ago)
Author:
bln4
Message:

When deciding what action to run Actions.java now considers actions with the same parameter list by emphasising some parameter types over others. Integer -> Double -> Float -> String -> All others

Now doesn't try to map in a item if the item for some reason has a null bounding_rect. A error message is displayed if it finds a null.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r975 r976  
    2424import java.lang.reflect.Modifier;
    2525import java.rmi.UnexpectedException;
     26import java.util.Arrays;
    2627import java.util.Collection;
    2728import java.util.Comparator;
     
    4243import org.expeditee.items.Item;
    4344import org.expeditee.items.ItemUtils;
    44 import org.expeditee.items.Text;
    4545import org.expeditee.reflection.PackageLoader;
    4646import org.expeditee.simple.SString;
     
    408408        public static Object PerformAction(final Frame source, final Item launcher,
    409409                        final String command) throws Exception {
    410                 System.err.println("Running action: " + command + " with floating: " + launcher);
    411410                final String actionName = getName(command);
    412411                final String parameters = command.substring(actionName.length()).trim();
     
    441440                        @Override
    442441                        public int compare(final Method m1, final Method m2) {
    443                                 return m2.getParameterCount() - m1.getParameterCount();
     442                                final int parameterCountDifference = m2.getParameterCount() - m1.getParameterCount();
     443                                if(parameterCountDifference == 0) {
     444                                        final Class<?>[] m1ParamTypes = m1.getParameterTypes();
     445                                        final Class<?>[] m2ParamTypes = m2.getParameterTypes();
     446                                        final List<Class<?>> typeOrder = Arrays.asList(Integer.TYPE, Double.TYPE, Float.TYPE, String.class);                                   
     447                                        for(int i = 0,o = 0; i < m1ParamTypes.length && o < m2ParamTypes.length; i++,o++) {
     448                                                final Class<?> m1ParamType = m1ParamTypes[i];
     449                                                final Class<?> m2ParamType = m2ParamTypes[o];
     450                                                final int m1ParamTypeIndex = typeOrder.indexOf(m1ParamType) != -1 ?
     451                                                                                typeOrder.indexOf(m1ParamType) : typeOrder.size();
     452                                                final int m2ParamTypeIndex = typeOrder.indexOf(m2ParamType) != -1 ?
     453                                                                                typeOrder.indexOf(m2ParamType) : typeOrder.size();
     454                                                final int paramMagnitude = m2ParamTypeIndex - m1ParamTypeIndex;
     455                                                if(paramMagnitude != 0) return paramMagnitude;
     456                                        }
     457                                }
     458                                return parameterCountDifference;
    444459                        }
    445460                });
Note: See TracChangeset for help on using the changeset viewer.