My favorites | Sign in
Project Logo
                
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
/*
Copyright [2007] Ernest.Micklei @ PhilemonWorks.com

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.philemonworks.flex.util
{
import mx.collections.ArrayCollection;

/**
* HashCollection implements a Hash in which the values are Bindable.
* This means that other objects can be notified when a value changes.
*
* @author Ernest.Micklei, 2007
*/
public class HashCollection extends ArrayCollection
{
public function HashCollection(source:Array=null)
{
super(source);
}
private var _keyToIndexHash:Object = new Object();

[Bindable("collectionChange")]
public function put(key:Object,value:Object):void {
var indexOrNull:* = _keyToIndexHash[key]
if (indexOrNull == undefined) {
var index:int = this.length
this.addItem(value)
_keyToIndexHash[key]=index
this.setItemAt(value,index)
} else {
this.setItemAt(value,indexOrNull as int)
}
}
[Bindable("collectionChange")]
public function get(key:Object):Object {
var indexOrNull:* = _keyToIndexHash[key]
if (indexOrNull == undefined) {
// no value for key so we return null
return null
}
var index:int = indexOrNull as int
return super.getItemAt(index)
}
/**
* Convenience method to access a String value
*/
[Bindable("collectionChange")]
public function getString(key:String):String {
var value:Object = this.get(key)
return value == null ? null : value as String
}
}
}
Show details Hide details

Change log

r44 by ernest.micklei on Aug 28, 2007   Diff
fix: if key is absent, put does not
dispatch event
Go to: 
Project members, sign in to write a code review

Older revisions

r38 by ernest.micklei on Aug 14, 2007   Diff
Added ClipboardHelper (DataGrid for
starters)
r19 by ernest.micklei on Aug 01, 2007   Diff
applied licence note
r11 by ernest.micklei on Jul 25, 2007   Diff
fixed put bug, added event annotation,
added getString
All revisions of this file

File info

Size: 2020 bytes, 65 lines
Hosted by Google Code