Created
February 26, 2011 01:13
-
-
Save ifedotov/844815 to your computer and use it in GitHub Desktop.
Object collection class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent output="false"> | |
<cffunction name="init" access="public" returntype="Collection" output="false"> | |
<cfscript> | |
variables.container = arrayNew(1); | |
variables.currentIndex = 0; | |
return this; | |
</cfscript> | |
</cffunction> | |
<cffunction name="add" access="public" output="false" returntype="void"> | |
<cfargument name="Object" type="Any" required="true" /> | |
<cfscript> | |
arrayAppend(variables.container, arguments.object); | |
variables.currentIndex = this.count(); | |
</cfscript> | |
</cffunction> | |
<cffunction name="clear" access="public" returntype="Void" output="false"> | |
<cfscript> | |
variables.container = arrayNew(1); | |
variables.currentIndex = this.count(); | |
</cfscript> | |
</cffunction> | |
<cffunction name="count" access="public" output="false" returntype="Numeric"> | |
<cfreturn arrayLen(variables.container) /> | |
</cffunction> | |
<cffunction name="getAt" access="public" output="false" returntype="Any"> | |
<cfargument name="index" type="Numeric" required="true" /> | |
<cfreturn variables.container[arguments.index] /> | |
</cffunction> | |
<cffunction name="getBy" access="public" output="false" returntype="Any"> | |
<cfargument name="property" type="String" required="true" /> | |
<cfargument name="value" type="Any" required="true" /> | |
<cfscript> | |
var i = 0; | |
var o = ''; | |
for (i=1; i LTE count() ; i=i+1) { | |
o = variables.container[i]; | |
if(isObject(o) and o.hasProperty(arguments.property) and o.get(arguments.property) is arguments.value) { | |
return variables.container[i]; | |
} | |
} | |
return null; | |
</cfscript> | |
</cffunction> | |
<cffunction name="removeAt" access="public" output="false" returntype="boolean"> | |
<cfargument name="index" type="Numeric" required="true" /> | |
<cfscript> | |
if(arguments.index LTE this.count()) { | |
arrayDeleteAt(variables.container,arguments.index); | |
return true; | |
} else { | |
return false; | |
} | |
</cfscript> | |
</cffunction> | |
<cffunction name="removeBy" access="public" output="false" returntype="boolean"> | |
<cfargument name="property" type="String" required="true" /> | |
<cfargument name="value" type="Any" required="true" /> | |
<cfscript> | |
var i = 0; | |
var o = ''; | |
for (i=1; i LTE count() ; i=i+1) { | |
o = variables.container[i]; | |
if(isObject(o) and o.hasProperty(arguments.property) and o.get(arguments.property) is arguments.value) { | |
arrayDeleteAt(variables.container,i); | |
return true; | |
} | |
} | |
return false; | |
</cfscript> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment