forked from markmandel/JavaLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringLenComparator.cfc
More file actions
70 lines (54 loc) · 2.82 KB
/
Copy pathStringLenComparator.cfc
File metadata and controls
70 lines (54 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<cfcomponent output="false">
<!--- match methods to java.util.Comparator interface --->
<!------------------------------------------- PUBLIC ------------------------------------------->
<!---
Apologies for the convoluted use on onMissingMethod. This is only done because 'equals' and 'compare' are reserved
words in ColdFusion, and we can't declare methods with those names.
If your Java interface does not have any conflicts with ColdFusion's reserved function names, you don't need to take this approach, and
can simply define your functions normally.
--->
<cffunction name="onMissingMethod" access="public" returntype="any" output="false" hint="Since 'compare' and 'equals' are reserved method names, we have to escape them">
<cfargument name="missingMethodName" type="string" required="true" hint="" />
<cfargument name="missingMethodArguments" type="struct" required="true" hint=""/>
<cfset var local = {}>
<cfif structKeyExists(arguments.missingMethodArguments, "__fromMissingMethod")>
<!--- we've been here before --->
<cfthrow type="MethodNotFoundException" message="The method '#arguments.missingMethodName#' could not be found."
detail="The method '#arguments.missingMethodName#' could not be found in component '#getMetadata(this).name#'">
</cfif>
<!--- add in an extra argument, so we can catch onMissingMethod based stack overflows --->
<cfset arguments.missingMethodArguments.__fromMissingMethod = true>
<!--- call the same method name, just with an $ before it, so ColdFusion doesn't get upset --->
<cfinvoke component="#this#" method="$#arguments.missingMethodName#" argumentcollection="#arguments.missingMethodArguments#" returnvariable="local.result">
<cfif structKeyExists(local, "result")>
<cfreturn local.result />
</cfif>
</cffunction>
<cffunction name="$compare" hint="compares 2 objects" access="public" returntype="numeric" output="false">
<cfargument name="obj1" hint="the first object" type="string" required="Yes">
<cfargument name="obj2" hint="the second object" type="string" required="Yes">
<cfscript>
var len1 = Len(arguments.obj1);
var len2 = Len(arguments.obj2);
var result = 0;
if(len1 lt len2)
{
result = -1;
}
else if(len1 gt len2)
{
result = 1;
}
//have to java cast to make sure it corresponds to the interface
return JavaCast("int", result);
</cfscript>
</cffunction>
<!--- we probably don't need the below function but to fulfil the inerface' --->
<cffunction name="$equals" hint=" Indicates whether some other object is 'equal to' this comparator." access="public" returntype="boolean" output="false">
<cfscript>
return false;
</cfscript>
</cffunction>
<!------------------------------------------- PACKAGE ------------------------------------------->
<!------------------------------------------- PRIVATE ------------------------------------------->
</cfcomponent>