本文整理汇总了PHP中ArrayList::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayList::newInstance方法的具体用法?PHP ArrayList::newInstance怎么用?PHP ArrayList::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayList
的用法示例。
在下文中一共展示了ArrayList::newInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: map
/**
* ArrayList::map() extension
*
* @param lang.types.ArrayList self
* @return lang.types.ArrayList mapped
*/
public static function map(ArrayList $self, $block)
{
$mapped = ArrayList::newInstance($self->length);
foreach ($self->values as $i => $value) {
$mapped[$i] = $block($value);
}
return $mapped;
}
示例2: valueOf
/**
* Returns a value for the given serialized string
*
* @param server.protocol.Serializer serializer
* @param remote.protocol.SerializedData serialized
* @param [:var] context default array()
* @return var
*/
public function valueOf($serializer, $serialized, $context = array())
{
$a = ArrayList::newInstance($serialized->consumeSize());
$serialized->consume('{');
for ($i = 0; $i < $a->length; $i++) {
$a[$i] = $serializer->valueOf($serialized, $context);
}
$serialized->consume('}');
return $a;
}
示例3: valueOf
/**
* Returns a value for the given serialized string
*
* @param server.protocol.Serializer serializer
* @param remote.protocol.SerializedData serialized
* @param [:var] context default array()
* @return var
*/
public function valueOf($serializer, $serialized, $context = array())
{
$a = ArrayList::newInstance($serialized->consumeSize());
$serialized->offset++;
// Opening "{"
for ($i = 0; $i < $a->length; $i++) {
$a[$i] = $serializer->valueOf($serialized, $context);
}
$serialized->offset++;
// Closing "}"
return $a;
}
示例4: main
/**
* Main method
*
* @param string[] args
*/
public static function main($args)
{
$sorted = ArrayList::newInstance($args)->sorted();
Console::writeLine('create(new ArrayList(array(', implode(', ', $args), ')))->sorted()= ', $sorted);
}
示例5: boxed
/**
* Boxes a type - that is, turns primitives into Generics
*
* @param var in
* @return lang.Generic the Generic if not already generic
* @throws lang.IllegalArgumentException in case in cannot be boxed.
*/
public static function boxed($in)
{
if (NULL === $in || $in instanceof Generic) {
return $in;
}
$t = gettype($in);
if ('string' === $t) {
return new String($in);
}
if ('integer' === $t) {
return new Integer($in);
}
if ('double' === $t) {
return new Double($in);
}
if ('boolean' === $t) {
return new Boolean($in);
}
if ('array' === $t) {
return ArrayList::newInstance($in);
}
// deprecated
throw new IllegalArgumentException('Cannot box ' . xp::typeOf($in));
}
示例6: unmarshall
/**
* Deserialize a single node
*
* @param xml.Node child
* @param string context default NULL
* @param webservices.soap.xp.XPSoapMapping mapping
* @return var result
*/
public function unmarshall($child, $context = NULL)
{
// DEBUG Console::writeLine('Unmarshalling ', $child->name, ' (', var_export($child->attribute, 1), ') >>> ', $child->content, '<<<', "\n"); // DEBUG
if ($child->hasAttribute($this->namespaces[XMLNS_XSI] . ':null') or $child->hasAttribute($this->namespaces[XMLNS_XSI] . ':nil')) {
return NULL;
}
// References
if ($child->hasAttribute('href')) {
$body = $this->_bodyElement();
foreach (array_keys($body->getChildren()) as $idx) {
if (0 != strcasecmp(@$body->nodeAt($idx)->getAttribute('id'), substr($child->getAttribute('href'), 1))) {
continue;
}
// Create a copy and pass name to it
$c = $body->nodeAt($idx);
$c->setName($child->getName());
return $this->unmarshall($c, $context);
break;
}
}
// Update namespaces list
foreach ($child->getAttributes() as $key => $val) {
if (0 == strncmp('xmlns:', $key, 6)) {
$this->namespaces[$val] = substr($key, 6);
}
}
// Type dependant
if (!$child->hasAttribute($this->namespaces[XMLNS_XSI] . ':type') || !preg_match('#^([^:]+):([^\\[]+)(\\[[0-9+]\\])?$#', $child->getAttribute($this->namespaces[XMLNS_XSI] . ':type'), $regs)) {
// E.g.: SOAP-ENV:Fault
$regs = array(0, 'xsd', 'string');
}
// SOAP-ENC:arrayType="xsd:anyType[4]"
if ($child->hasAttribute($this->namespaces[XMLNS_SOAPENC] . ':arrayType')) {
$regs[1] = $child->getAttribute($this->namespaces[XMLNS_SOAPENC] . ':arrayType');
$regs[2] = 'Array';
}
switch (strtolower($regs[2])) {
case 'array':
// Check for specific type information
@(list($ns, $typeSpec) = explode(':', $regs[1]));
if (2 == sscanf($typeSpec, '%[^[][%d]', $childType, $length) && 'anyType' != $childType) {
// Arrays of XP objects
// ~~~~~~~~~~~~~~~~~~~~
// <item
// xsi:type="SOAP-ENC:Array"
// xmlns:xp="http://xp-framework.net/xmlns/xp"
// SOAP-ENC:arrayType="xp:de.schlund.db.irc.IrcChannel[2]"
// >
//
// vs.
//
// Arrays of other types
// ~~~~~~~~~~~~~~~~~~~~~
// <item SOAP-ENC:arrayType="xsd:int[4]"/>
if ($this->namespaces[XMLNS_XP] == $ns) {
$result = ArrayList::newInstance($length);
foreach ($this->_recurseData($child, FALSE, 'ARRAY') as $i => $val) {
$result[$i] = $val;
}
break;
} else {
for ($i = 0; $i < $length; ++$i) {
$child->nodeAt($i)->setAttribute($this->namespaces[XMLNS_XSI] . ':type', $ns . ':' . $childType);
}
}
}
// Break missing intentionally
// Break missing intentionally
case 'vector':
$result = $this->_recurseData($child, FALSE, 'ARRAY');
break;
case 'map':
// <old_data xmlns:ns4="http://xml.apache.org/xml-soap" xsi:type="ns4:Map">
// <item>
// <key xsi:type="xsd:string">Nachname</key>
// <value xsi:type="xsd:string">Braun</value>
// </item>
// <item>
// <key xsi:type="xsd:string">PLZ</key>
// <value xsi:type="xsd:string">76135</value>
// </item>
// <item>
if (!$child->hasChildren()) {
break;
}
foreach ($child->getChildren() as $item) {
$key = $item->nodeAt(0)->getContent($this->getEncoding(), $this->namespaces);
$result[$key] = !$item->nodeAt(1)->hasChildren() && !$item->nodeAt(1)->hasAttribute('href') ? $item->nodeAt(1)->getContent($this->getEncoding(), $this->namespaces) : $this->unmarshall($item->nodeAt(1), 'MAP');
}
break;
case 'soapstruct':
case 'struct':
//.........这里部分代码省略.........
示例7: newInstanceArray
public function newInstanceArray()
{
$a = ArrayList::newInstance(array(1, 2, 3, 4));
$this->assertEquals(4, $a->length);
$this->assertEquals(1, $a[0]);
$this->assertEquals(2, $a[1]);
$this->assertEquals(3, $a[2]);
$this->assertEquals(4, $a[3]);
}
示例8: emptyArray
public function emptyArray()
{
$this->assertEquals(ArrayList::newInstance(0), Arrays::$EMPTY);
}