Saves an address making a copy in case it was already persisted. Then
returns the saved address.

@param AddressInterface $address The address to save

@return AddressInterface saved address.
435133
public function saveAddress(AddressInterface $address)
    {
        if ($address->getId()) {
            $addressToSave = clone $address;
            $addressToSave->setId(null);

            $this->addressObjectManager->refresh($address);
            $this->addressObjectManager->persist($addressToSave);
            $this->addressObjectManager->flush($addressToSave);

            $this->addressEventDispatcher->dispatchAddressOnCloneEvent(
                $address,
                $addressToSave
            );

            return $addressToSave;
        }

        $this
            ->addressObjectManager
            ->flush($address);

        return $address;
    }
674021
public function setAddress(array $address)
    {
        if (!empty($address) && is_array($address)) {
            $this->address = $address;
        }

        return $this;
    }
965613
public function match(AddressInterface $address)
    {
        foreach ($this->territories as $territory) {
            if ($territory->match($address)) {
                return true;
            }
        }
        return false;
    }
575923
public function offsetSet($name, $address)
    {
        if (!$address instanceof Address) {
            $address = new Address($address);
        }
        return $this->_data[$address->email()] = $address;
    }
310461
public function saveEntity(EntityInterface $entity)
    {
        $check = $this->storage->fetchEntityById($entity->getIdentifier());

        if ($check) {
            return $this->storage->updateEntity($entity);
        } else {
            return $this->storage->insertEntity($entity);
        }
    }
1319141
public function address(array $address)
    {
        if (! isset($this->data->addresses)) {
            $this->data->addresses = [];
        }

        return $this->data->addresses[] = (object) $address;
    }
119705
public function deleteAddress(Address $address)
    {
        if ($this !== $address->addressable()->first())
            return false;

        return $address->delete();
    }
121363
public function getEntry(Address $address)
    {
        try {
            $sth = $this->dbh->prepare('SELECT "event_id", "pool", "address", "value", "created", "expiration" FROM ' . $this->prefixTable('lcache_events') .' WHERE "address" = :address AND ("expiration" >= :now OR "expiration" IS NULL) ORDER BY "event_id" DESC LIMIT 1');
            $sth->bindValue(':address', $address->serialize(), \PDO::PARAM_STR);
            $sth->bindValue(':now', $_SERVER['REQUEST_TIME'], \PDO::PARAM_INT);
            $sth->execute();
        } catch (\PDOException $e) {
            $this->logSchemaIssueOrRethrow('Failed to search database for cache item', $e);
            return null;
        }
        //$last_matching_entry = $sth->fetchObject('LCacheEntry');
        $last_matching_entry = $sth->fetchObject();

        if (false === $last_matching_entry) {
            $this->misses++;
            return null;
        }

        // If last event was a deletion, miss.
        if (is_null($last_matching_entry->value)) {
            $this->misses++;
            return null;
        }

        $unserialized_value = @unserialize($last_matching_entry->value);

        // If unserialization failed, raise an exception.
        if (false === $unserialized_value && serialize(false) !== $last_matching_entry->value) {
            throw new UnserializationException($address, $last_matching_entry->value);
        }

        $last_matching_entry->value = $unserialized_value;
        $this->hits++;
        return $last_matching_entry;
    }
543141
public function copyFrom( MShop_Common_Item_Address_Interface $address )
	{
		$this->setAddressId( $address->getId() );
		$this->setCompany( $address->getCompany() );
		$this->setVatID( $address->getVatID() );
		$this->setSalutation( $address->getSalutation() );
		$this->setTitle( $address->getTitle() );
		$this->setFirstname( $address->getFirstname() );
		$this->setLastname( $address->getLastname() );
		$this->setAddress1( $address->getAddress1() );
		$this->setAddress2( $address->getAddress2() );
		$this->setAddress3( $address->getAddress3() );
		$this->setPostal( $address->getPostal() );
		$this->setCity( $address->getCity() );
		$this->setState( $address->getState() );
		$this->setCountryId( $address->getCountryId() );
		$this->setTelephone( $address->getTelephone() );
		$this->setEmail( $address->getEmail() );
		$this->setTelefax( $address->getTelefax() );
		$this->setWebsite( $address->getWebsite() );
		$this->setLanguageId( $address->getLanguageId() );
		$this->setFlag( $address->getFlag() );

		$this->setModified();
	}
139289
public function setAddress(\Sulu\Bundle\ContactBundle\Entity\Address $address)
    {
        $this->address = $address;

        return $this;
    }
1249274
protected function _execute($address) {
		/** @var \Geo\Model\Table\GeocodedAddressesTable|null $GeocodedAddresses */
		$GeocodedAddresses = null;
		if ($this->getConfig('cache')) {
			$GeocodedAddresses = TableRegistry::get('Geo.GeocodedAddresses');
			/** @var \Geo\Model\Entity\GeocodedAddress $result */
			$result = $GeocodedAddresses->find()->where(['address' => $address])->first();
			if ($result) {
				/** @var \Geocoder\Model\Address|null $data */
				$data = $result->data;
				return $data ?: null;
			}
		}

		try {
			$addresses = $this->_Geocoder->geocode($address);
		} catch (InconclusiveException $e) {
			$addresses = null;
		} catch (NotAccurateEnoughException $e) {
			$addresses = null;
		}
		$result = null;
		if ($addresses && $addresses->count() > 0) {
			$result = $addresses->first();
		}

		if ($this->getConfig('cache')) {
			/** @var \Geo\Model\Entity\GeocodedAddress $addressEntity */
			$addressEntity = $GeocodedAddresses->newEntity([
				'address' => $address
			]);
			if ($result) {
				$formatter = new StringFormatter();
				$addressEntity->formatted_address = $formatter->format($result, '%S %n, %z %L');
				$addressEntity->lat = $result->getLatitude();
				$addressEntity->lng = $result->getLongitude();
				$addressEntity->country = $result->getCountry()->getCode();
				$addressEntity->data = $result;
			}

			if (!$GeocodedAddresses->save($addressEntity, ['atomic' => false])) {
				throw new RuntimeException('Could not store geocoding cache data');
			}
		}

		return $result;
	}
707613
public function sameValueAs(ValueObjectInterface $address)
    {
        if (false === Util::classEquals($this, $address)) {
            return false;
        }

        return $this->getName()->sameValueAs($address->getName())             &&
               $this->getStreet()->sameValueAs($address->getStreet())         &&
               $this->getDistrict()->sameValueAs($address->getDistrict())     &&
               $this->getCity()->sameValueAs($address->getCity())             &&
               $this->getRegion()->sameValueAs($address->getRegion())         &&
               $this->getPostalCode()->sameValueAs($address->getPostalCode()) &&
               $this->getCountry()->sameValueAs($address->getCountry())
        ;
    }
151367
public function removeAddress(AddressInterface $address)
    {
        if (!$this->hasAddress($address)) {
            throw new \InvalidArgumentException('Trying to remove an address that does not belong to this contact');
        }

        $this->addresses->removeElement($address);

        if ($address === $this->defaultAddress) {
            if ($this->addresses->count() > 0) {
                $this->defaultAddress = $this->addresses->first();

                return;
            }

            $this->defaultAddress = null;
        }
    }
130064
public function removeAddress(AddressInterface $address): void
    {
        $this->addresses->removeElement($address);

        if ($address->getId() == $this->defaultAddress->getId()) {
            if ($this->addresses->count() > 0) {
                $this->defaultAddress = $this->addresses[0];
            } else {
                $this->defaultAddress = null;
            }
        }
    }
177374
public function getAddress( CustomerVault\Address $address )
    {
        $address->setRequiredFields(array(
            'profileID',
            'id'
        ));
        $address->checkRequiredFields();

        $request = new Request(array(
            'method' => Request::GET,
            'uri' => $this->prepareURI("/profiles/" . $address->profileID . "/addresses/" . $address->id),
        ));
        $response = $this->client->processRequest($request);
        $response['profileID'] = $address->profileID;

        return new CustomerVault\Address($response);
    }
408685
public function createAddress(Address $address, array $params = [])
    {
        $this->getClient()->createAccountAddress($this, $address, $params);
    }
1183187
public function getCoordinatesByString(string $address) : CoordinatesInterface
    {
        $url = $this->addressQuery($address);
        $json = $this->fetchUrl($url);

        // convert google data to coordinates
        $coordinates = CoordinatesBuild::create($json->results[0]);

        return $coordinates;
    }