{@inheritDoc}
@return
518347
@Override
    public E last()
    {
        if (list.isEmpty())
        {
            throw new NoSuchElementException();
        }
        return list.get(list.size()-1);
    }
199463
public function php() {
    $cr = "\n";
    
    $php = $this->phpDocBlock(0);
    
    $ms = array(self::MODIFIER_ABSTRACT => 'abstract',
                self::MODIFIER_FINAL => 'final'
               );
    
    foreach ($ms as $const => $modifier) {
      if (($const & $this->modifiers) == $const)
        $php .= $modifier.' ';
    }
    
    $php .= 'class '.$this->getClassName().' ';
    
    /* Extends */
    if (isset($this->parentClass)) {
      if ($this->parentClass->getNamespace() === $this->getNamespace()) {
        $php .= 'extends '.$this->parentClass->getClassName().' '; // don't prefix namespace
      } else {
        $php .= 'extends '.'\\'.$this->parentClass->getFQN().' ';
      }
    }
    
    /* Interfaces */
    if (count($this->getInterfaces()) > 0) {
      $php .= 'implements ';
      $that = $this;
      $php .= A::implode($this->getInterfaces(), ', ', function (GClass $iClass) use ($that) {
        if ($that->getNamespace() === $iClass->getNamespace()) {
          return $iClass->getClassName();
        } else {
          return '\\'.$iClass->getFQN();
        }
      });
      $php .= ' ';
    }
    
    $php .= '{'.$cr;
    /* Die Funktionen machen immer den Abstand nach oben. Also vor jedem Property und jeder Methode macht dies ein "\n" */

    /* Constants */
    $php .= A::joinc($this->getConstants(), '  '.$cr.'%s;'.$cr, function ($constant) {
      return $constant->php(2);
    });
    
    /* Properties */
    $php .= A::joinc($this->getProperties(), '  '.$cr.'%s;'.$cr, function ($property) {
      return $property->php(2); // hier jetzt auch wegen DocBlock einrücken
    });

    /* Methods */
    $php .= A::joinc($this->getMethods(), '  '.$cr.'%s'.$cr, function ($method) {
      return $method->php(2); // rückt selbst zwischen den Klammern ein, aber wir wollen ja den body z.b. auf 4 haben nicht auf 2
    });
    
    $php .= '}'; // kein umbruch hinten, immer abstand nach oben!
    return $php;
  }
436677
public function remove($key)
    {
        if (!isset($this->map[$key])) {
            return null;
        }

        $removed = $this->map[$key];
        unset($this->map[$key]);
        if ($removed instanceof AbstractCriterion) {
            return $removed->getValue();
        }

        return $removed;
    }
281603
public function process() {
        $className = new $this->_annotation['class'];
        $class = new $className();

        foreach ($this->_annotation['properties'] as $property => $value) {
            $class->$property = $value;
        }

        return $class;
    }
1066609
public static function getInstance($id = '0')
    {
        self::$id = $id;
        if (isset(self::$instances[self::$id])) {
            return self::$instances[self::$id];
        }

        return self::$instances[self::$id] = new self;
    }
1318578
public function find($id = NULL)
    {
        if ($id !== NULL)
        {
            $data             = $this->getData();
            $this->currentId  = $id;
            $this->currentKey = $this->getRowKey($id);
            foreach ($data[$this->currentKey] as $field => $value)
            {
                $this->setField($field, $value);
            }
        }
        else
        {
            $this->limit(1)->findAll();
            $data = $this->data;
            if (count($data))
            {
                foreach ($data[0] as $field => $value)
                {
                    $this->setField($field, $value);
                }

                $this->currentId  = $this->getField('id');
                $this->currentKey = $this->getRowKey($this->currentId);
            }
        }
        return clone $this;
    }
265231
public function toValue() {
    $ret = array();
    foreach ($this->elements->getItems() as $element) {
      if ($element instanceof ArrayNode) {
        $ref[] = $element->toValue();
      }
      elseif ($element instanceof ArrayPairNode) {
        $key = $element->getKey();
        $value = $element->getValue();
        $value_convertable = $value instanceof ScalarNode || $value instanceof ArrayNode;
        if (!($key instanceof ScalarNode && $value_convertable)) {
          throw new \BadMethodCallException('Can only convert scalar arrays.');
        }
        $ret[$key->toValue()] = $value->toValue();
      }
      elseif ($element instanceof ScalarNode || $element instanceof ArrayNode) {
        /** @var ScalarNode|ArrayNode $element */
        $ret[] = $element->toValue();
      }
      else {
        throw new \BadMethodCallException('Can only convert scalar arrays.');
      }
    }
    return $ret;
  }
214862
public function get($id = null)
    {
        if ($id == null)
            return false;
        $this->currentId        = $id;
        $this->currentKey       = $this->getRowKey($id);
        $this->setDocuments($this->getData()[$this->currentKey]);
        foreach ($this->documentEntries as $field => $value)
            $this->tableFields->{$field} = $value;
        return $this;
    }
1012542
@Override
  public Iterator<T> iterator() {
    return new Iterator<T>() {

      /** The index of the next item. */
      private int next = ArrayQueue.this.next;

      /* (non-Javadoc)
       * @see java.util.Iterator#hasNext()
       */
      public boolean hasNext() {
        return next < items.length;
      }

      /* (non-Javadoc)
       * @see java.util.Iterator#next()
       */
      public T next() {
        if (next >= items.length) {
          throw new NoSuchElementException();
        }
        return items[next++];
      }

      /* (non-Javadoc)
       * @see java.util.Iterator#remove()
       */
      public void remove() {
        throw new UnsupportedOperationException();
      }

    };
  }
1350788
public function c ()
    {
        $fields = array();
        foreach ($this->getFields() as $field)
            /* @var $field Field */
            if ($field->getCollectData())
                $fields[] = $field;
        return $fields;
    }
69753
public function get(string $class)
    {
        if (isset($this->instantiated[$class]) && $this->shared[$class]) {
            return $this->instantiated[$class];
        }

        $args = $this->services[$class];

        switch (count($args)) {
            case 0:
                $object = new $class();
                break;
            case 1:
                $object = new $class($args[0]);
                break;
            case 2:
                $object = new $class($args[0], $args[1]);
                break;
            case 3:
                $object = new $class($args[0], $args[1], $args[2]);
                break;
            default:
                throw new \OutOfRangeException('Too many arguments given');
        }

        if ($this->shared[$class]) {
            $this->instantiated[$class] = $object;
        }

        return $object;
    }
1230981
public function get($key, $id)
    {
        if (is_null($this->schema)) {
            throw SystemException::forNoSchema();
        }

        $search = $this
            ->resource
            ->search($this->schema->getName())
            ->addFilter($key . ' = %s', $id);

        // get json fields
        $fields = $this->schema->getJsonFieldNames();

        //get 1:1 relations
        $relations = $this->schema->getRelations(1);

        foreach ($relations as $table => $relation) {
            $search
                ->innerJoinUsing(
                    $table,
                    $relation['primary1']
                )
                ->innerJoinUsing(
                    $relation['name'],
                    $relation['primary2']
                );

            $relatedJson = Schema::i($relation['name'])->getJsonFieldNames();
            $fields = array_merge($fields, $relatedJson);
        }

        $results = $search->getRow();

        if (!$results) {
            return $results;
        }

        //we need to update the real key and id
        $key = $this->schema->getPrimaryFieldName();
        $id = $results[$key];

        foreach ($fields as $field) {
            if (isset($results[$field]) && $results[$field]) {
                $results[$field] = json_decode($results[$field], true);
            } else {
                $results[$field] = [];
            }
        }

        //get 1:0 relations
        $relations = $this->schema->getRelations(0);
        foreach ($relations as $table => $relation) {
            $row = $this
                ->resource
                ->search($table)
                ->innerJoinUsing($relation['name'], $relation['primary2'])
                ->addFilter($relation['primary1'] . ' = %s', $id)
                ->getRow();

            $fields = Schema::i($relation['name'])->getJsonFieldNames();

            foreach ($fields as $field) {
                if (isset($row[$field]) && trim($row[$field])) {
                    $row[$field] = json_decode($row[$field], true);
                } else {
                    $row[$field] = [];
                }
            }

            $results[$relation['name']] = $row;
        }

        //get 1:N, N:N relations
        $relations = array_merge(
            $this->schema->getRelations(2),
            $this->schema->getRelations(3)
        );

        foreach ($relations as $table => $relation) {
            $schema = $this->schema;
            $rows = $this
                ->resource
                ->search($table)
                ->when(
                    //we need to case for post_post for example
                    $relation['name'] === $this->schema->getName(),
                    //this is the post_post way
                    function () use (&$schema, &$relation) {
                        $on = sprintf(
                            '%s = %s',
                            $schema->getPrimaryFieldName(),
                            $relation['primary2']
                        );
                        $this->innerJoinOn($relation['name'], $on);
                    },
                    //this is the normal way
                    function () use (&$relation, &$fields) {
                        $this->innerJoinUsing($relation['name'], $relation['primary2']);

                        $relationSchema = Schema::i($relation['name']);
                        $relationRelations = $relationSchema->getRelations(1);

                        foreach ($relationRelations as $table2 => $relation2) {
                            $this
                                ->innerJoinUsing(
                                    $table2,
                                    $relation2['primary1']
                                )
                                ->innerJoinUsing(
                                    $relation2['name'],
                                    $relation2['primary2']
                                );

                            $relatedJson = $relationSchema->getJsonFieldNames();
                            $fields = array_merge($fields, $relatedJson);
                        }
                    }
                )
                ->addFilter($relation['primary1'] . ' = %s', $id)
                ->getRows();

            $fields = Schema::i($relation['name'])->getJsonFieldNames();

            foreach($rows as $i => $row) {
                foreach ($fields as $field) {
                    if (isset($row[$field]) && trim($row[$field])) {
                        $row[$field] = json_decode($row[$field], true);
                    } else {
                        $row[$field] = [];
                    }
                }

                //custom formats & formulas
                foreach(Schema::i($relation['name'])->getFields() as $field) {
                    if($field['detail']['format'] === 'formula') {
                        $helper = cradle('global')
                            ->handlebars()
                            ->getHelper('formula');

                        $row[$field['name']] = $helper(
                            $field['detail']['parameters'],
                            $row,
                            false
                        );

                        continue;
                    }

                    if($field['detail']['format'] === 'custom') {
                        $helper = cradle('global')
                            ->handlebars()
                            ->getHelper('compile');

                        $row[$field['name']] = $helper(
                            $field['detail']['parameters'],
                            $row
                        );

                        continue;
                    }
                }

                $rows[$i] = $row;
            }

            $results[$relation['name']] = $rows;
        }

        //custom formats & formulas
        foreach($this->schema->getFields() as $field) {
            if($field['detail']['format'] === 'formula') {
                $helper = cradle('global')
                    ->handlebars()
                    ->getHelper('formula');

                $results[$field['name']] = $helper(
                    $field['detail']['parameters'],
                    $results,
                    false
                );
            }

            if($field['detail']['format'] === 'custom') {
                $helper = cradle('global')
                    ->handlebars()
                    ->getHelper('compile');

                $results[$field['name']] = $helper(
                    $field['detail']['parameters'],
                    $results
                );
            }
        }

        return $results;
    }
1155000
@SuppressWarnings("unchecked")
	public T getInstance() {
		if(beanClassName == null) {
			return null;
		} else try {
			T beanInstance;
			Class<T> beanClass = null;
			try {
				try {
					ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
					beanClass = (Class<T>)Class.forName(beanClassName, true, classLoader);
				} catch(ClassNotFoundException cnfe) {
					throw new RuntimeException("Unknown class " + beanClassName, cnfe);
				}
				// Instancjonowanie i inicjalizcja w oparciu o konstruktor inicjujący:
				Constructor<T> constructor = (Constructor<T>)beanClass.getConstructor(Collection.class);
				beanInstance = constructor.newInstance(properties);
			} catch(NoSuchMethodException nsme) {
				// Instancjonowanie i inicjalizacja w oparciu o konstruktor bezargumentowy
				// i publiczne setter'y Java Beans:
				beanInstance = beanClass.newInstance();

				if(properties != null && !properties.isEmpty()) {
					BeanInfo validatorInfo = Introspector.getBeanInfo(beanClass);
					PropertyDescriptor[] propertyDescriptors = validatorInfo.getPropertyDescriptors();
					for(BeanProperty beanProperty : properties) {
						String propertyName = beanProperty.getPropertyName();
						Method writeMethod = null;
						for(PropertyDescriptor propertyDescriptor : propertyDescriptors) {
							if(propertyDescriptor.getName().equals(propertyName)) {
								writeMethod = propertyDescriptor.getWriteMethod();
								break;
							}
						}
						if(writeMethod == null) {
							throw new RuntimeException("No public setter found for property '" + propertyName + "' "
									+ "in validator class " + beanClass.getCanonicalName());
						}
						Class<?> parameterType = writeMethod.getParameterTypes()[0];
						if(BeanProperty.class.equals(parameterType)) {
							writeMethod.invoke(beanInstance, beanProperty);
						} else if(String.class.equals(parameterType)) {
							if(beanProperty.hasAttributes()) {
								throw new RuntimeException("BeanProperty '" + propertyName + "' setter should has "
										+ Parameter.class.getSimpleName() + " type parameter");
							}
							writeMethod.invoke(beanInstance, beanProperty.getPropertyValue());
						}
					}
				}
			}
			return beanInstance;
		} catch(Exception e) {
			throw new RuntimeException(e);
		}
	}
270452
public function getInputsFromServiceId($conditionServiceId)
    {
        if (!$this->container->has($conditionServiceId)) {
            return false;
        }

        /** @var ConditionInterface $condition */
        $condition = $this->container->get($conditionServiceId);

        return $this->getInputsFromConditionInterface($condition);
    }
46076
public function fields(string $fields): object
    {
        if (empty($this->container[$this->id]['s']['fields'])) {
            $this->container[$this->id]['s']['fields'] = "$fields";
        } else if ($this->container[$this->id]['s']['fields'] != '*') {
            $this->container[$this->id]['s']['fields'] .= ",$fields";
        }
        if ($fields == '*') {
            $this->container[$this->id]['s']['fields'] = '*';
        }
        return $this;
    }
831889
public static function &getInstance( $instance = null )
	{
		if ( is_null( self::$instance ) )
		{
			self::$instance = $instance ? $instance : new self();
			// if ( $callback ) $callback( self::$instance );
		}
		return self::$instance;
	}
241532
public function get($id) {
		$source = $id;
		while (is_string($source) && isset($this->getter[$source])) {
			$source = $this->getter[$source];
		}
		if (!is_string($source)) {
			if ($source instanceof \Closure) {
				$source->bindTo($this);
				return $source();
			} elseif (is_object($source)) {
				return $source;
			} else {
				throw new NotFoundException("Class $id not found");
			}
		}
		if (isset($this->instance[$source])) {
			if (!isset($this->multi[$source])) {
				return $this->instance[$source];
			} elseif ($this->multi[$source] === self::MULTI_CLONE) {
				return clone $this->instance[$source];
			}
		}
		if (!class_exists($source)) {
			throw new NotFoundException("Class $id not found");
		}
		// Check cyclic dependency
		if (isset($this->creating[$source])) {
			throw new CyclicDependencyException("Found cyclic dependency of $id");
		}
		$this->creating[$source] = true;
		$ref = new ReflectionClass($source);
		if (!$ref->isInstantiable()) {
			throw new InvalidClassException("Can not create instance of $id");
		}
		// constructor
		$constructor = $ref->getConstructor();
		if ($constructor !== null) {
			// Read comment for getter
			$comment = $constructor->getDocComment();
			$is_autowire = preg_match_all('/@Autowired\s+([\w\\\\]+)\s+([\w\\\\]+)\s+/', $comment, $autowire_matches);
			$getter = [];
			if ($is_autowire && count($autowire_matches[1]) > 0) {
				foreach ($autowire_matches[1] as $k => $v) {
					$getter[$v] = $autowire_matches[2][$k];
				}
			}
			$params = $constructor->getParameters();
			$init_params = [];
			foreach ($params as $param) {
				if ($param->isOptional()) {
					$init_params[] = $param->getDefaultValue();
				} elseif (isset($getter[$param->getName()])) {
					$typeName = $getter[$param->getName()];
					$init_params[] = $this->get($typeName);
				} elseif ($param->hasType()) {
					$type = $param->getType();
					if (class_exists('ReflectionNamedType') && $type instanceof \ReflectionNamedType) {
						$typeName = $type->getName();
					} else {
						$typeName = $type->__toString();
					}
					if ($type->isBuiltin()) {
						$value = null;
						settype($value, $typeName);
						$init_params[] = $value;
					} else {
						$init_params[] = $this->get($typeName);
					}
				} else {
					$init_params[] = null;
				}
			}
			$instance = $ref->newInstance(...$init_params);
		} else {
			$instance = $ref->newInstance();
		}
		// properties
		$properties = $ref->getProperties();
		foreach ($properties as $property) {
			if ($property->isStatic()) {
				continue;
			}
			// Using getter and setter
			$propertyName = $property->getName();
			$setter = 'set' . ucfirst($propertyName);
			$getter = 'get' . ucfirst($propertyName);
			if (method_exists($instance, $setter) && method_exists($instance, $getter)) {
				if ($instance->$getter() === null) {
					$setter_ref = $ref->getMethod($setter);
					$is_autowire = preg_match('/@Autowired\s+([\w\\\\]+)\s+/', $setter_ref->getDocComment(), $autowire);
					if ($is_autowire) {
						$instance->$setter($this->get($autowire[1]));
					} else {
						$params = $setter_ref->getParameters();
						$param = $params[0];
						if ($param->hasType()) {
							$type = $param->getType();
							if (class_exists('ReflectionNamedType') && $type instanceof \ReflectionNamedType) {
								$typeName = $type->getName();
							} else {
								$typeName = $type->__toString();
							}
							$instance->$setter($this->get($typeName));
						}
					}
				}
			} else {
				$comment = $property->getDocComment();
				$is_autowire = preg_match('/@Autowired\s+([\w\\\\]+)\s+/', $comment, $autowire);
				if ($is_autowire) {
					$is_public = $property->isPublic();
					if (!$is_public) {
						$property->setAccessible(true);
					}
					if ($property->getValue($instance) === null) {
						$property->setValue($instance, $this->get($autowire[1]));
					}
					if (!$is_public) {
						$property->setAccessible(false);
					}
				}
			}
		}
		// put into instance
		if (!isset($this->multi[$source]) || $this->multi[$source] === self::MULTI_CLONE) {
			$this->instance[$source] = $instance;
		}
		unset($this->creating[$source]);
		return $instance;
	}