@param \ShopgateAddress $address

@return \Magento\Directory\Model\Region
970892
public function getMageRegionByAddress($address)
    {
        $map = $this->getIsoToMagentoMapping();

        $state = preg_replace("/{$address->getCountry()}\-/", "", $address->getState());

        /** @var \Magento\Directory\Model\ResourceModel\Region\Collection $set */
        /** @var \Magento\Directory\Model\Region $region */
        $set    = $this->regionFactory->create()->getCollection();
        $region = $set->addCountryFilter($address->getCountry())
                      ->addFieldToFilter('main_table.code', $state)
                      ->getFirstItem();

        // If no region was found
        if (!$region->getId() && !empty($state) && isset($map[$address->getCountry()][$state])) {
            $regionCode = $map[$address->getCountry()][$state];

            $set    = $this->regionFactory->create()->getCollection();
            $region = $set->addRegionCodeFilter($regionCode)->addCountryFilter($address->getCountry())->getFirstItem();
        }

        if (!$region->getId()) {
            $this->logger->error('Region not found, state provided: ' . $state . ' country: ' . $address->getCountry());
        }

        return $region;
    }
1301794
private function getShippingAddress($address, $shipping = null)
    {
        if (!is_null($address) or !empty($adress))
            return $address;
        if ($shipping)
            return \UOL\PagSeguro\Helper\Data::addressConfig($shipping['street']);
        return null;
    }
1280050
public function cleanCustomerAddress(array $address) {
    if (isset($address['customer_address_id']) && empty($address['address_id'])) {
      $address['address_id'] = $address['customer_address_id'];
    }

    return $this->cleanAddress($address);
  }
1226788
private function updateAddressFromComponent(Address $address, $component) : Address
    {
        foreach ($component->types as $type) {
            switch ($type) {
                case 'postal_code':
                    $address->setPostalCode($component->long_name);
                    break;
                case 'locality':
                case 'postal_town':
                    $address->setLocality($component->long_name);
                    break;
                case 'country':
                    $address->setCountry($component->long_name);
                    $address->setCountryCode($component->short_name);
                    break;
                case 'street_number':
                    $address->setStreetNumber($component->long_name);
                    break;
                case 'route':
                    $address->setStreetName($component->long_name);
                    break;
                case 'administrative_area_level_1':
                case 'administrative_area_level_2':
                case 'administrative_area_level_3':
                case 'administrative_area_level_4':
                case 'administrative_area_level_5':
                case 'sublocality':
                case 'sublocality_level_1':
                case 'sublocality_level_2':
                case 'sublocality_level_3':
                case 'sublocality_level_4':
                case 'sublocality_level_5':
                case 'street_address':
                case 'intersection':
                case 'political':
                case 'colloquial_area':
                case 'ward':
                case 'neighborhood':
                case 'premise':
                case 'subpremise':
                case 'natural_feature':
                case 'airport':
                case 'park':
                case 'point_of_interest':
                case 'establishment':
                    // TODO implements method
                    break;
                default:
            }
        }

        return $address;
    }
801322
protected function mapTheliaAddress($address, $locale = null)
    {
        $country = $address->getCountry();
        if (null === $locale) {
            $locale = Lang::getDefaultLanguage()->getLocale();
        }
        $customerTitle = $address->getCustomerTitle()
            ->setLocale($this->denormalizeLocale($locale))
            ->getShort()
        ;

        $addressModel = new Address();
        $addressModel = $addressModel
            ->withCountryCode($country->getIsoalpha2())
            ->withAddressLine1($address->getAddress1())
            ->withAddressLine2($address->getAddress2())
            ->withPostalCode($address->getZipcode())
            ->withLocality($address->getCity())
            ->withOrganization($address->getCompany())
            ->withRecipient(
                sprintf(
                    '%s %s %s',
                    $customerTitle,
                    $address->getLastname(),
                    $address->getFirstname()
                )
            )
        ;


        if ($country->getHasStates() && \intval($address->getStateId()) !== 0) {
            $addressModel = $addressModel->withAdministrativeArea(
                sprintf(
                    '%s-%s',
                    $country->getIsoalpha2(),
                    $address->getState()->getIsocode()
                )
            );
        }

        return $addressModel;
    }
1010434
protected function formatAddress($address)
    {
        if (is_array($address)) {
            $email = is_int(key($address)) ? current($address) : key($address);
            return array($email => current($address));
        }

        return array($address => $address);
    }
280818
private function checkIfAddressExists($address)
    {
        $oldAddress = $this->addressRepository->findOneByEmailIgnoreHidden( $address );

        return isset($oldAddress) && $oldAddress ? $oldAddress : null;
    }
35838
private function justAddress($address)
    {
        if (($pos = strpos($address, '<')) === false) {
            return $address;
        }

        $n = strlen($address);
        if ($address[$n - 1] == '>') {
            $address = substr($address, $pos + 1, -1);
        }

        return $address;
    }
250882
private function setAddress($quoteAddress, $address)
    {
        $address = $this->cartHelper->handleSpecialAddressCases($address);

        $region = $this->regionModel->loadByName(@$address->region, @$address->country_code);

        $addressData = [
            'firstname'    => @$address->first_name,
            'lastname'     => @$address->last_name,
            'street'       => trim(@$address->street_address1 . "\n" . @$address->street_address2),
            'city'         => @$address->locality,
            'country_id'   => @$address->country_code,
            'region'       => @$address->region,
            'postcode'     => @$address->postal_code,
            'telephone'    => @$address->phone_number,
            'region_id'    => $region ? $region->getId() : null,
            'company'      => @$address->company,
        ];

        if ($this->cartHelper->validateEmail(@$address->email_address)) {
            $addressData['email'] = $address->email_address;
        }

        // discard empty address fields
        foreach ($addressData as $key => $value) {
            if (empty($value)) {
                unset($addressData[$key]);
            }
        }

        $quoteAddress->setShouldIgnoreValidation(true);
        $quoteAddress->addData($addressData)->save();
    }
549987
private function setAddress($address) {

        if(!$this->formatter) {
            $this->formatter = new StringFormatter();
        }

        $this->address = trim($this->formatter->format($address, '%S %n %z %L %C'));

        return $this;
    }
813822
public static function locate($address)
	{
		$ip = false;
		if (filter_var($address, FILTER_VALIDATE_IP))
		{
			$ip = true;
		}

		$adapter  = new \Geocoder\HttpAdapter\CurlHttpAdapter();

		$p = array();

		// Get a list of providers
		if ($providers = \Event::trigger('geocode.onGeocodeProvider', array('geocode.locate', $adapter, $ip)))
		{
			foreach ($providers as $provider)
			{
				if ($provider)
				{
					$p[] = $provider;
				}
			}
		}

		if (!count($p))
		{
			return '';
		}

		// Instantiate the Geocoder service and pass it the list of providers
		$geocoder = new \Geocoder\Geocoder();
		$geocoder->registerProvider(new \Geocoder\Provider\ChainProvider($p));

		// Try to get some data...
		return $geocoder->geocode($address);
	}
1011048
public function at($address)
    {
        if (AddressValidator::validate($address) === false) {
            throw new InvalidArgumentException('Please make sure address is valid.');
        }
        $this->toAddress = AddressFormatter::format($address);

        return $this;
    }
1028965
protected function getAddressZoneId(array $address)
    {
        $result = array();

        foreach (array('state_id', 'city_id', 'country') as $field) {

            if (empty($address[$field])) {
                continue;
            }

            if ($field === 'city_id') {
                $data = $this->city->get($address[$field]);
            } else if ($field === 'state_id') {
                $data = $this->state->get($address[$field]);
            } else if ($field === 'country') {
                $data = $this->country->get($address[$field]);
            }

            if (!empty($data['zone_id'])) {
                $result[] = $data['zone_id'];
            }
        }

        return $result;
    }
226018
public function retrieve($address) {
		/** @var \Geo\Model\Entity\GeocodedAddress $entity */
		$entity = $this->find()->where(['address' => $address])->first();
		if ($entity) {
			return $entity;
		}

		$result = $this->_execute($address);
		$address = $this->newEntity([
			'address' => $address
		]);
		if ($result) {
			$address->lat = $result->getLatitude();
			$address->lng = $result->getLongitude();
			$address->country = $result->getCountry()->getCode();

			$formatter = new StringFormatter();
			$address->formatted_address = $formatter->format($result, '%S %n, %z %L');
			$address->data = $result;
		}

		return $this->save($address);
	}
718867
public static function normalizeMailAddress($address) {
		if (self::isBrokenEmailEnvironment() && FALSE !== ($pos1 = strrpos($address, '<'))) {
			$pos2 = strpos($address, '>', $pos1);
			$address = substr($address, $pos1 + 1, ($pos2 ? $pos2 : strlen($address)) - $pos1 - 1);
		}
		return $address;
	}
683803
private function trimAddress($address)
    {
        if (is_array($address)) {
            $fields  = oxNew(FormFields::class, $address);
            $trimmer = oxNew(FormFieldsTrimmer::class);

            $address = (array)$trimmer->trim($fields);
        }

        return $address;
    }
1137980
public function setAddress(Address $address)
    {
        $address->setContext(Moip::SUBSCRIPTION);
        $this->data->address = $address->getData();

        return $this;
    }