clear
Usage - $map->clear()
Returns - none
Args - none
Function - removes all mappings from this map
contains_key
Usage - $map->contains_key($key)
Returns - 1 (true) if this map contains a mapping for the specified key
Args - a key whose presence in this map is to be tested
Function - checks if this map contains a mapping for the specified key
contains_value
Usage - $map->contains_value($value)
Returns - 1 (true) if this map maps one or more keys to the specified value
Args - a value whose presence in this map is to be tested
Function - checks if this map maps one or more keys to the specified value
equals
Usage - $map->equals($another_map)
Returns - either 1 (true) or 0 (false)
Args - the map (OBO::Util::Map) to compare with
Function - tells whether this map is equal to the given one
get
Usage - $map->get($key)
Returns - the value to which this map maps the specified key
Args - a key whose associated value is to be returned
Function - gets the value to which this map maps the specified key
is_empty
Usage - $map->is_empty()
Returns - true if this map contains no key-value mappings
Args - none
Function - checks if this map contains no key-value mappings
key_set
Usage - $map->key_set()
Returns - a set (OBO::Util::Set) view of the keys contained in this map
Args - none
Function - gets a set view of the keys contained in this map
put
Usage - $map->put("GO", "Gene Ontology")
Returns - previous value associated with specified key, or undef if there was no mapping for key
Args - a key (string) with which the specified value is to be associated and a value to be associated with the specified key.
Function - associates the specified value with the specified key in this map (optional operation)
Remark - if the map previously contained a mapping for this key, the old value is replaced by the specified value
put_all
Usage - $map->put_all($my_other_map)
Returns - none
Args - a map (OBO::Util::Map) to be stored in this map
Function - copies all of the mappings from the specified map to this map (optional operation)
Remark - the effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map
remove
Usage - $map->remove($key)
Returns - the previous value associated with specified key, or undef if there was no mapping for the given key
Args - a key whose mapping is to be removed from the map
Function - removes the mapping for this key from this map if it is present (optional operation)
size
Usage - $map->size()
Returns - the size of this map
Args - none
Function - tells the number of elements held by this map
values
Usage - $map->values()
Returns - a collection view of the values contained in this map
Args - none
Function - gets a collection view of the values contained in this map
NAME
OBO::Util::Map - An implementation of a map (key -> value).
SYNOPSIS
use OBO::Util::Map;
use strict;
my $my_map = OBO::Util::Map->new();
if(!$my_map->contains_key("GO")) { print "doesn't contain key: GO"; }
if(!$my_map->contains_value("Gene Ontology")) { print "doesn't contain value: Gene Ontology"; }
if ($my_map->size() == 0) { print "empty map"; }
if ($my_map->is_empty()) { print "empty map"; }
$my_map->put("GO", "Gene Ontology");
if ($my_map->contains_key("GO")) { print "contains key: GO"; }
if ($my_map->contains_value("Gene Ontology")) { print "contains value: Gene Ontology"; }
if ($my_map->size() == 1) { print "map size is 1"; }
if (!$my_map->is_empty()) { print "map is not empty"; }
$my_map->put("APO", "Application Ontology");
$my_map->put("PO", "Plant Ontology");
$my_map->put("SO", "Sequence Ontology");
if ($my_map->size() == 4) { print "map size is 4"; }
if ($my_map->equals($my_map)) { print "my map is identical to itself"; }
my $my_map2 = OBO::Util::Map->new();
if (!$my_map->equals($my_map2)) { print "my map is not identical to map2"; }
if (!$my_map2->equals($my_map)) { print "map2 is not identical to my map"; }
$my_map2->put("APO", "Application Ontology");
$my_map2->put("PO", "Plant Ontology");
$my_map2->put("SO", "Sequence Ontology");
if (!$my_map2->equals($my_map)) { print "map2 is not identical to my map"; }
if (!$my_map->equals($my_map2)) { print "my map is not identical to map2"; }
$my_map2->put("GO", "Gene Ontology");
if ($my_map2->equals($my_map)) { print "map2 is not identical to my map"; }
if ($my_map->equals($my_map2)) { print "my map is not identical to map2"; }
if ($my_map2->get("GO") eq "Gene Ontology") { print "get GO"}
if ($my_map2->get("APO") eq "Application Ontology") { print "get APO"}
if ($my_map2->get("PO") eq "Plant Ontology") { print "get PO"}
if ($my_map2->get("SO") eq "Sequence Ontology") { print "get SO"}
$my_map2->put("TO", "Trait Ontology");
if (!$my_map->equals($my_map2)) { print "my map is not identical to map2"; }
if (!$my_map2->equals($my_map)) { print "map2 is not identical to my map"; }
if ($my_map2->size() == 5) { print "map size is 5"; }
$my_map->clear();
if ($my_map->size() == 0) { print "map size is 0"; }
$my_map->put_all($my_map2);
if ($my_map->equals($my_map2)) { print "my map is identical to map2"; }
if ($my_map2->equals($my_map)) { print "map2 is identical to my map"; }
if ($my_map->size() == 5) { print "map size is 5"; }
my $UD = $my_map->remove("XO");
my $GO = $my_map->remove("GO");
if (!$my_map->contains_key("GO") && !$my_map->contains_value("Gene Ontology")) { print "GO is gone"}
print $GO; # "Gene Ontology"
if ($my_map->size() == 4) { print "map size is 4"; }
DESCRIPTION
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
AUTHOR
Erick Antezana, <erick.antezana -@- gmail.com>
COPYRIGHT AND LICENSE
Copyright (c) 2006-2015 by Erick Antezana. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.