Given an array of two beans and a property, this method
swaps the value of the property.
This is handy if you need to swap the priority or orderNo
of an item (i.e. bug-tracking, page order).

@param array  $beans    beans
@param string $property property
549226
public static function swap( $beans, $property ) {
		$bean1 = array_shift($beans);
		$bean2 = array_shift($beans);
		$tmp = $bean1->$property;
		$bean1->$property = $bean2->$property;
		$bean2->$property = $tmp;
		RedBean_Facade::store($bean1);
		RedBean_Facade::store($bean2);
	}
128423
public function exchangeArray($data)
    {
        foreach ($data as $property => $value) {
            if (isset($this->$property)) {
                $method = 'set' . ucfirst($property);
                $this->$method($value);
            }
        }
    }
257289
public function setProperties($properties)
	{
		JLog::add('JException::setProperties is deprecated.', JLog::WARNING, 'deprecated');

		// Cast to an array
		$properties = (array) $properties;

		if (is_array($properties))
		{
			foreach ($properties as $k => $v)
			{
				$this->$k = $v;
			}

			return true;
		}

		return false;
	}
561409
public function unique($properties)
    {
        $properties = (array) $properties;

        foreach ($properties as $property)
        {
            $this->addCommand('unique', ['property' => $property]);
        }
    }
180727
public static Object setBeanProperties(MetaClass mc, Object bean, Map properties) {
        for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry) iter.next();
            String key = entry.getKey().toString();

            Object value = entry.getValue();
            mc.setProperty(bean, key, value);
        }
        return bean;
    }
1345004
public function getProperty($property)
    {
        $values = array();
        foreach ($this->columns as $key => $col) {
            if (isset($col[$property])) {
                $values[$key] = $col[$property];
            } else {
                $values[$key] = null;
            }
        }
    }
1208982
public function setProperty(PropertyInterface $property)
    {
        $this->property      = $property;
        $this->propertyType  = $property->type();
        $this->propertyIdent = $property->ident();

        $inputType = $property['input_type'];
        if ($inputType) {
            $this->inputType = $inputType;
        }

        $displayType = $property['display_type'];
        if ($displayType) {
            $this->displayType = $displayType;
        }

        return $this;
    }
802085
public function addProperty(Property $property)
    {
        $fieldName = $property->getName();

        // Check for empty field name
        if (empty($fieldName)) {
            throw MappingException::missingFieldName($this->className);
        }

        $property->setDeclaringClass($this);

        switch (true) {
            case $property instanceof VersionFieldMetadata:
                $this->validateAndCompleteFieldMapping($property);
                $this->validateAndCompleteVersionFieldMapping($property);
                break;

            case $property instanceof FieldMetadata:
                $this->validateAndCompleteFieldMapping($property);
                break;

            case $property instanceof OneToOneAssociationMetadata:
                $this->validateAndCompleteAssociationMapping($property);
                $this->validateAndCompleteToOneAssociationMetadata($property);
                $this->validateAndCompleteOneToOneMapping($property);
                break;

            case $property instanceof OneToManyAssociationMetadata:
                $this->validateAndCompleteAssociationMapping($property);
                $this->validateAndCompleteToManyAssociationMetadata($property);
                $this->validateAndCompleteOneToManyMapping($property);
                break;

            case $property instanceof ManyToOneAssociationMetadata:
                $this->validateAndCompleteAssociationMapping($property);
                $this->validateAndCompleteToOneAssociationMetadata($property);
                $this->validateAndCompleteManyToOneMapping($property);
                break;

            case $property instanceof ManyToManyAssociationMetadata:
                $this->validateAndCompleteAssociationMapping($property);
                $this->validateAndCompleteToManyAssociationMetadata($property);
                $this->validateAndCompleteManyToManyMapping($property);
                break;

            default:
                // Transient properties are ignored on purpose here! =)
                break;
        }

        $this->addDeclaredProperty($property);
    }
536683
public function setProperties(array $properties) {
        if (!isset($properties[self::DATA_PROPERTY_REQUIRED])){
            $properties[self::DATA_PROPERTY_REQUIRED] = array();
        }
        if (!isset($properties[self::DATA_PROPERTY_DEFAULTS])){
            $properties[self::DATA_PROPERTY_DEFAULTS] = array();
        }
        $this->properties = $properties;
        return $this;
    }
360700
public function checkProperty(&$property)
    {
        if (is_string($property)) {
            $property = Placeholder::replaceStringsAndComments($property);
            $property = Placeholder::removeCommentPlaceholders($property, true);
            $property = Placeholder::replaceStringPlaceholders($property, true);

            return true;
        } else {
            throw new \InvalidArgumentException(
                "Invalid type '" . gettype($property). "' for argument 'property' given."
            );
        }
    }
76926
protected function setFields($fields) 
    {
    	foreach ($fields as $name => $value) {
            $property = '_' . $name;
            if (property_exists($this, $property)) $this->$property = $value;
        }
    }
150601
public function setProperties(array $properties)
    {
        foreach ($properties as $property => $value) {
            $method = sprintf('set%s', str_replace('_', '', $property));

            if (!method_exists($this, $method)) {
                 throw SchemaException::invalidColumnProperty($this->getName(), $property);
            }

            $this->$method($value);
        }
    }
61531
public function configure(array $properties)
    {
        foreach ($properties as $name => $value) {
            $methodName = 'set' . ucfirst(strtolower($name));
            if (method_exists($this, $methodName)) {
                $this->$methodName($value);
            }
        }
    }
608423
public function sort($properties) {
		if (is_string($properties)) {
			if (strpos($properties, ',') === false) {
				$properties = [$properties];
			} else {
				$properties = explode(',', $properties);
			}
		}
		
		if (is_array($properties)) {
			$properties = array_map('trim', $properties);
		} else {
			throw new Exception('Uncnown property type "' . gettype($properties) . '"');
		}
		
		foreach ($properties as $property) {
			if (strpos($property, ' ') === false) {
				$this->_sort[$property] = self::MONGO_SORT_ASC;
			} else {
				list ($property, $sort) = explode(' ', $property);
				
				$sort = strtolower($sort);
				
				if ($sort === self::SORT_ASC) {
					$this->_sort[$property] = self::MONGO_SORT_ASC;
				} else if ($sort === self::SORT_DESC) {
					$this->_sort[$property] = self::MONGO_SORT_DESC;
				} else {
					throw new Exception('Uncnown sort condition "' . $sort . '"');
				}
			}
		}
		
		return $this;
	}
819632
public function addProperty($property)
    {
        $properties = $this->getProperties();
        array_push($properties, $property);
        $this->setProperties($properties);
    }
425415
public function getProperty($propertyName)
    {
        $className = $className = $this->getClass()->getName();

        if ($this->hasProperty($propertyName) === true) {

            try {
                return new BeanProperty($className, $propertyName);
            } catch (BeanException $e) {
                $msg = "The bean property with name '${propertyName}' in class '${className}' could not be retrieved.";
                throw new BeanException($msg, BeanException::NO_PROPERTY, $e);
            }
        } else {
            $msg = "No bean property with name '${propertyName}' in class '${className}'.";
            throw new BeanException($msg, BeanException::NO_PROPERTY);
        }
    }
906280
public static final Object removeList(Object bean, String property)
    {
        return doFor(
            bean, 
            property, 
            null,
            (Object a, int i)->{throw  new UnsupportedOperationException("not supported");},
            (List l, int i)->{return l.remove(i);},
            (Object b, Class c, String p)->{throw  new UnsupportedOperationException("not supported");},
            (Object b, Method m)->{throw  new UnsupportedOperationException("not supported");}
        );
    }