function testAddSameElementTwice() { $set = new HashSet("string"); $set->add("Hello there"); $set->add("Hello there"); $this->assertEqual(1, $set->size()); $this->assertEqual("Hello there", $set->get(0)); }
public function doesNotEqualSetWithDifferentContents() { $other = new HashSet(); $this->set->add(new String('blue')); $other->add(new String('yellow')); $this->assertFalse($this->set->equals($other)); }
/** * @depends test_count_sizeN_returnsN */ function testDifferenceSelf() { $a = new HashSet(); $a->add(0); $diff = $a->difference($a); $this->assertInstanceOf(__NAMESPACE__ . '\\HashSet', $diff); $this->assertNotSame($diff, $a); $this->assertCount(0, $diff); }
/** * Retrieve a set of classes used in this interface * * @return remote.ClassReference[] */ public function classSet() { $set = new HashSet(); for ($i = 0; $i < $this->methods->length; $i++) { $set->addAll($this->methods[$i]->classSet()); } return $set->toArray(); }
/** * Retrieve a set of classes used in this interface * * @return remote.ClassReference[] */ public function classSet() { $set = new HashSet(); foreach (array_keys($this->fields) as $name) { if (!$this->fields[$name] instanceof ClassReference) { continue; } $set->add($this->fields[$name]); } return $set->toArray(); }
static function __static() { self::$iterate = newinstance('Iterator', array(), '{ private $i= 0, $v; public function on($v) { $self= new self(); $self->v= $v; return $self; } public function current() { return current($this->v); } public function key() { return $this->i; } public function next() { next($this->v); $this->i++; } public function rewind() { reset($this->v); $this->i= 0; } public function valid() { return $this->i < sizeof($this->v); } }'); }
public static function loadFromStream($filename, GenericList $classNotFoundExceptions) { if (is_null($filename)) { throw new NullPointerException('InputStream'); } $whitelistSer = new HashMap(); $whitelistDeser = new HashMap(); $typeIds = new HashMap(); $clientFields = new HashMap(); $br = new BufferedReader($filename); $line = $br->readLine(); $lineNum = 1; while (!is_null($line)) { $line = trim($line); if (mb_strlen($line) > 0) { $components = explode(',', $line); if ($components[0] === self::CLIENT_FIELDS_KEYWORD) { /* * Lines starting with '@ClientFields' list potentially serializable fields known to * client code for classes that may be enhanced with additional fields on the server. * If additional server fields are found, they will be serizalized separately from the * normal RPC process and transmitted to the client as an opaque blob of data stored * in a WeakMapping associated with the object instance. */ $binaryTypeName = trim($components[1]); try { $clazz = Classes::classOf($binaryTypeName); $fieldNames = new HashSet(); for ($i = 2; $i < count($components); $i++) { $fieldNames->add($components[$i]); } $clientFields->put($clazz, $fieldNames); } catch (ClassNotFoundException $e) { // Ignore the error, but add it to the list of errors if one was // provided. if (!is_null($classNotFoundExceptions)) { $classNotFoundExceptions->add($e); } } } else { if (count($components) != 2 && count($components) != 7) { throw new ParseException(self::FORMAT_ERROR_MESSAGE, $lineNum); } for ($i = 0; $i < count($components); $i++) { $components[$i] = trim($components[$i]); if (mb_strlen($components[$i]) == 0) { throw new ParseException(self::FORMAT_ERROR_MESSAGE, $lineNum); } } $binaryTypeName = trim($components[0]); if (count($components) == 2) { $fieldSer = $fieldDeser = true; $instantSer = $instantDeser = Boolean::valueOf($components[1]); $typeId = $binaryTypeName; } else { $idx = 1; // TODO: Validate the instantiable string better $fieldSer = Boolean::valueOf($components[$idx++]); $instantSer = Boolean::valueOf($components[$idx++]); $fieldDeser = Boolean::valueOf($components[$idx++]); $instantDeser = Boolean::valueOf($components[$idx++]); $typeId = $components[$idx++]; if (!$fieldSer && !$fieldDeser && TypeNameObfuscator::SERVICE_INTERFACE_ID != $typeId) { throw new ParseException('Type ' . $binaryTypeName . ' is neither field serializable, field deserializable ' . 'nor the service interface : ', $lineNum); } } try { $clazz = Classes::classOf($binaryTypeName); if ($fieldSer) { $whitelistSer->put($clazz, $instantSer); } if ($fieldDeser) { $whitelistDeser->put($clazz, $instantDeser); } $typeIds->put($clazz, $typeId); } catch (ClassNotFoundException $e) { // Ignore the error, but add it to the list of errors if one was // provided. if (!is_null($classNotFoundExceptions)) { $classNotFoundExceptions->add($e); } } } } $line = $br->readLine(); $lineNum++; } return new StandardSerializationPolicy($whitelistSer, $whitelistDeser, $typeIds, $clientFields); }
public function classImplementsComparatorInterface() { $class = $this->classloader->loadClass($this->classname); $interface = XPClass::forName('util.Comparator'); $interfaces = new HashSet(); $interfaces->addAll($class->getInterfaces()); $this->assertTrue($interfaces->contains($interface)); }
public function testToArray() { // Remove the following lines when you implement this test. $this->assertTrue(\is_array($this->object->toArray())); }
public function hashSetUsableInForeach() { $s = new HashSet(); $s->addAll(array(new String('0'), new String('1'), new String('2'))); foreach ($s as $i => $element) { $this->assertEquals(new String($i), $element); } }
public function test_ArrayAccess_SetValue() { $h = new HashSet(['a', 'b', 1]); $h['d'] = true; $h['a'] = false; $this->assertTrue($h->has('d')); $this->assertFalse($h->has('a')); }