| 1 |
/* |
|---|
| 2 |
* Copyright(c) 2006-2007 the Spark project. |
|---|
| 3 |
* |
|---|
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 5 |
* you may not use this file except in compliance with the License. |
|---|
| 6 |
* You may obtain a copy of the License at |
|---|
| 7 |
* |
|---|
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 9 |
* |
|---|
| 10 |
* Unless required by applicable law or agreed to in writing, software |
|---|
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
|---|
| 13 |
* either express or implied. See the License for the specific language |
|---|
| 14 |
* governing permissions and limitations under the License. |
|---|
| 15 |
*/ |
|---|
| 16 |
|
|---|
| 17 |
package org.libspark.utils |
|---|
| 18 |
{ |
|---|
| 19 |
import flash.utils.Dictionary; |
|---|
| 20 |
|
|---|
| 21 |
/** |
|---|
| 22 |
* Dictionary クラスのためのユーティリティクラスです |
|---|
| 23 |
*/ |
|---|
| 24 |
public class DictionaryUtil |
|---|
| 25 |
{ |
|---|
| 26 |
|
|---|
| 27 |
/** |
|---|
| 28 |
* |
|---|
| 29 |
* @param d |
|---|
| 30 |
* @param value |
|---|
| 31 |
* @return |
|---|
| 32 |
* @author michi at seyself.com |
|---|
| 33 |
*/ |
|---|
| 34 |
public static function getKey(d:Dictionary, value:*):* |
|---|
| 35 |
{ |
|---|
| 36 |
for (var key:Object in d) |
|---|
| 37 |
if (d[key] == value) return key; |
|---|
| 38 |
return null; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
/** |
|---|
| 42 |
* |
|---|
| 43 |
* @param d |
|---|
| 44 |
* @return |
|---|
| 45 |
* @author michi at seyself.com |
|---|
| 46 |
*/ |
|---|
| 47 |
public static function getKeys(d:Dictionary):Array |
|---|
| 48 |
{ |
|---|
| 49 |
var a:Array = new Array(); |
|---|
| 50 |
for (var key:Object in d) a.push(key); |
|---|
| 51 |
return a; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
/** |
|---|
| 55 |
* |
|---|
| 56 |
* @param d |
|---|
| 57 |
* @return |
|---|
| 58 |
* @author michi at seyself.com |
|---|
| 59 |
*/ |
|---|
| 60 |
public static function getValues(d:Dictionary):Array |
|---|
| 61 |
{ |
|---|
| 62 |
var a:Array = new Array(); |
|---|
| 63 |
for each (var value:Object in d) a.push(value); |
|---|
| 64 |
return a; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
/** |
|---|
| 68 |
* |
|---|
| 69 |
* @param d |
|---|
| 70 |
* @param keys |
|---|
| 71 |
* @return |
|---|
| 72 |
* @author michi at seyself.com |
|---|
| 73 |
*/ |
|---|
| 74 |
public static function getValuesOfKeys(d:Dictionary, keys:Array):Array |
|---|
| 75 |
{ |
|---|
| 76 |
var a:Array = new Array(); |
|---|
| 77 |
var n:uint = keys.length; |
|---|
| 78 |
for (var i:uint = 0; i < n; i++) a.push(d[keys[i]]); |
|---|
| 79 |
return a; |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
/** |
|---|
| 83 |
* |
|---|
| 84 |
* @param d |
|---|
| 85 |
* @return |
|---|
| 86 |
* @author michi at seyself.com |
|---|
| 87 |
*/ |
|---|
| 88 |
public static function length(d:Dictionary):uint |
|---|
| 89 |
{ |
|---|
| 90 |
var a:Array = new Array(); |
|---|
| 91 |
for (var key:Object in d) a.push(key); |
|---|
| 92 |
return a.length; |
|---|
| 93 |
} |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
} |
|---|
| 97 |
} |
|---|