/** * Processes cell value * * @param var in * @return var * @throws lang.FormatException */ public function process($in) { try { return $this->proceed(Enum::valueOf($this->enum, $in)); } catch (\lang\IllegalArgumentException $e) { throw new \lang\FormatException($e->getMessage()); } }
public function abstract_enum_with_one_member() { $class = self::define('abstract enum', 'PartialOperation', null, '{ plus { public int evaluate(int $x, int $y) { return $x + $y; } }; public abstract int evaluate(int $x, int $y); }'); $this->assertEquals('SourcePartialOperation', $class->getName()); $this->assertTrue($class->isEnum()); $plus = Enum::valueOf($class, 'plus'); $this->assertEquals(2, $plus->evaluate(1, 1)); }
/** * Constructor */ public function __construct() { $this->marshallers = create('new util.collections.HashTable<lang.Type, webservices.rest.TypeMarshaller>'); // Deprecated! if (PHP_VERSION < 7 && ClassLoader::getDefault()->providesPackage('lang.types')) { $strings = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->toString(); }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $integers = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->intValue(); }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $decimals = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->doubleValue(); }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $booleans = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return (bool) $t->value; }, 'unmarshal' => function (Type $target, $in) { return $target->newInstance($in); }]); $this->marshallers[XPClass::forName('lang.types.String')] = $strings; $this->marshallers[XPClass::forName('lang.types.Character')] = $strings; $this->marshallers[XPClass::forName('lang.types.Long')] = $integers; $this->marshallers[XPClass::forName('lang.types.Integer')] = $integers; $this->marshallers[XPClass::forName('lang.types.Short')] = $integers; $this->marshallers[XPClass::forName('lang.types.Byte')] = $integers; $this->marshallers[XPClass::forName('lang.types.Float')] = $decimals; $this->marshallers[XPClass::forName('lang.types.Double')] = $decimals; $this->marshallers[XPClass::forName('lang.types.Boolean')] = $booleans; } $this->marshallers[XPClass::forName('lang.Enum')] = newinstance('webservices.rest.TypeMarshaller', [], ['marshal' => function ($t) { return $t->name(); }, 'unmarshal' => function (Type $target, $in) { return Enum::valueOf($target, (string) $in); }]); }
public function minus() { $this->assertEquals(-1, Enum::valueOf(self::$fixture, 'minus')->evaluate(1, 2)); }
public function diff($type, $strdate1, $strdate2) { return DateMath::diff(Enum::valueOf(XPClass::forName('util.TimeInterval'), strtoupper($type)), new Date($strdate1), new Date($strdate2)); }
public function monday_is_not_a_weekend() { $this->assertFalse(Enum::valueOf(self::$fixture, 'MON')->isWeekend()); }
public function member_color($name, $ordinal, $color) { $this->assertEquals($color, Enum::valueOf(self::$fixture, $name)->color()); }
public function staticMemberNotWithEnumValueOf() { \lang\Enum::valueOf(\lang\XPClass::forName('net.xp_framework.unittest.core.Profiling'), 'fixture'); }
/** * Return a field type * * @return unittest.web.Fields */ public static function forTag($type) { return parent::valueOf(\lang\XPClass::forName('unittest.web.Fields'), strtoupper($type)); }
/** * Returns a operation member by a specified name, case-insensitively * * @param string $name * @return text.json.patch.Operations */ public static function named($name) { return parent::valueOf(new XPClass(self::class), strtoupper($name)); }
/** * Gets the currency instance for a given currency code * * @param string code ISO 4217 code * @return self * @throws lang.IllegalArgumentException */ public static function getInstance($code) { return parent::valueOf(new XPClass(__CLASS__), $code); }
/** * Gets the currency instance for a given currency code * * @param string code ISO 4217 code * @return self * @throws lang.IllegalArgumentException */ public static function getInstance($code) { return parent::valueOf(new XPClass(self::class), $code); }