[Javamatch-cvs] javamatch/src/net/sourceforge/javamatch/query MatchQuery.java,1.1.1.1,1.2 Maximum.ja
Status: Pre-Alpha
Brought to you by:
iterson
From: Walter v. I. <it...@us...> - 2004-09-06 09:15:12
|
Update of /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21108 Modified Files: MatchQuery.java Maximum.java Minimum.java Log Message: Ranges are now from minimum to maximum, instead of median Expanded member retrieval (not yet complete) Index: Maximum.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/Maximum.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Maximum.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- Maximum.java 6 Sep 2004 09:14:30 -0000 1.2 *************** *** 80,91 **** public float getMatchValue(Object matchedObject) throws MatchException { double objectValue = getValue(matchedObject, memberName); - double median = (globalMinimum + globalMaximum) / 2; if (objectValue == globalMaximum) { return 1f; - } else if (objectValue > median) { - double range = globalMaximum - median; - return (float)((objectValue - median) / range); } else { ! return 0f; } } --- 80,88 ---- public float getMatchValue(Object matchedObject) throws MatchException { double objectValue = getValue(matchedObject, memberName); if (objectValue == globalMaximum) { return 1f; } else { ! double range = globalMaximum - globalMinimum; ! return (float)((objectValue - globalMinimum) / range); } } Index: MatchQuery.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/MatchQuery.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** MatchQuery.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- MatchQuery.java 6 Sep 2004 09:14:30 -0000 1.2 *************** *** 68,79 **** * @return the value that is returned by the member, wrapped into an object * if the member returned a primitive type */ protected Object getObjectValue(Object srcObject, String memberName) throws MatchException { try { ! String methodName = "get" + Character.toUpperCase(memberName.charAt(0)) + memberName.substring(1); Class clazz = srcObject.getClass(); Method method = clazz.getMethod(methodName, null); ! return method.invoke(srcObject, null); } catch (NoSuchMethodException nsme) { throw new MatchException("Error while retrieving number data", nsme); --- 68,114 ---- * @return the value that is returned by the member, wrapped into an object * if the member returned a primitive type + * @throws MatchException when the execution of the member failed */ protected Object getObjectValue(Object srcObject, String memberName) throws MatchException { try { ! int bracketOpen = memberName.indexOf("("); ! int dot = memberName.indexOf("."); ! if ((bracketOpen == -1) && (dot == -1)) { ! String methodName = "get" + Character.toUpperCase(memberName.charAt(0)) + memberName.substring(1); ! return invokeMethod(srcObject, methodName, null); ! } else if (dot == -1) { ! // TODO: parse arguments ! String methodName = memberName.substring(0, bracketOpen); ! return invokeMethod(srcObject, methodName, null); ! } else { // bracketOpen != -1; dot != -1 ! String methodName = memberName.substring(0, bracketOpen); ! // TODO: parse arguments ! String nextMember = memberName.substring(dot+1); ! Object nextObject = invokeMethod(srcObject, methodName, null); ! return getObjectValue(nextObject, nextMember); ! } ! } catch (NullPointerException npe) { ! throw new MatchException("Error while retrieving member data", npe); ! } ! } ! ! /** ! * Invokes the method with the given method name and the given method ! * arguments on the given source object ! * @param srcObject the object of which the member value is retrieved ! * @param methodName the name of the method that is executed ! * @param args the method's arguments ! * @return the value that is returned by the method, wrapped into an object ! * if the member returned a primitive type ! * @throws MatchException when the execution of the method failed ! */ ! private Object invokeMethod(Object srcObject, String methodName, Object[] args) ! throws MatchException { ! try { Class clazz = srcObject.getClass(); + // TODO: find and match method parameter types Method method = clazz.getMethod(methodName, null); ! return method.invoke(srcObject, args); } catch (NoSuchMethodException nsme) { throw new MatchException("Error while retrieving number data", nsme); *************** *** 82,87 **** } catch (InvocationTargetException ite) { throw new MatchException("Error while retrieving number data", ite); - } catch (NullPointerException npe) { - throw new MatchException("Error while retrieving number data", npe); } } --- 117,120 ---- Index: Minimum.java =================================================================== RCS file: /cvsroot/javamatch/javamatch/src/net/sourceforge/javamatch/query/Minimum.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Minimum.java 3 Sep 2004 08:21:22 -0000 1.1.1.1 --- Minimum.java 6 Sep 2004 09:14:30 -0000 1.2 *************** *** 80,91 **** public float getMatchValue(Object matchedObject) throws MatchException { double objectValue = getValue(matchedObject, memberName); - double median = (globalMinimum + globalMaximum) / 2; if (objectValue == globalMinimum) { return 1f; - } else if (objectValue < median) { - double range = median - globalMinimum; - return (float)((median - objectValue) / range); } else { ! return 0f; } } --- 80,88 ---- public float getMatchValue(Object matchedObject) throws MatchException { double objectValue = getValue(matchedObject, memberName); if (objectValue == globalMinimum) { return 1f; } else { ! double range = globalMaximum - globalMinimum; ! return (float)((globalMaximum - objectValue) / range); } } |