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(); foreach (array_keys($this->fields) as $name) { if (!$this->fields[$name] instanceof ClassReference) { continue; } $set->add($this->fields[$name]); } return $set->toArray(); }
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 testRemoveAll() { // Remove the following lines when you implement this test. $col = new HashSet(); $col->add(89); $col->add(78978); $col->add(789); $col->add(456); $this->assertFalse($this->object->removeAll($col)); $col->add(4); $this->assertTrue($this->object->removeAll($col)); }
public function test_add_IntegerValuesAlreadyExistedInHash() { $h = new HashSet(['a', 'b', 3]); $h->add([3, 'c']); $this->assertSame(['a', 'b', 3, 'c'], $h->getKeys()); }