Replace the last element of an address with a static path element.

@param element the path element
@return the operation address transformer
9978
public static AliasOperationTransformer replaceLastElement(final PathElement element) {
        return create(new AddressTransformer() {
            @Override
            public PathAddress transformAddress(final PathAddress original) {
                final PathAddress address = original.subAddress(0, original.size() -1);
                return address.append(element);
            }
        });
    }
262284
public static <E> E last(Iterator<E> iterator) {
        return new LastElement<E>().apply(iterator);
    }
520215
protected
  void parse(Element element) {

    String rootElementName = element.getTagName();

    if (!rootElementName.equals(CONFIGURATION_TAG)) {
      if(rootElementName.equals(OLD_CONFIGURATION_TAG)) {
	LogLog.warn("The <"+OLD_CONFIGURATION_TAG+
		     "> element has been deprecated.");
	LogLog.warn("Use the <"+CONFIGURATION_TAG+"> element instead.");
      } else {
	LogLog.error("DOM element is - not a <"+CONFIGURATION_TAG+"> element.");
	return;
      }
    }

    String debugAttrib = subst(element.getAttribute(INTERNAL_DEBUG_ATTR));
      
    LogLog.debug("debug attribute= \"" + debugAttrib +"\".");
    // if the log4j.dtd is not specified in the XML file, then the
    // "debug" attribute is returned as the empty string.
    if(!debugAttrib.equals("") && !debugAttrib.equals("null")) {      
      LogLog.setInternalDebugging(OptionConverter.toBoolean(debugAttrib, true));
    } else {
      LogLog.debug("Ignoring " + INTERNAL_DEBUG_ATTR + " attribute.");
    }

      //
      //   reset repository before configuration if reset="true"
      //       on configuration element.
      //
    String resetAttrib = subst(element.getAttribute(RESET_ATTR));
    LogLog.debug("reset attribute= \"" + resetAttrib +"\".");
    if(!("".equals(resetAttrib)) &&
         OptionConverter.toBoolean(resetAttrib, false)) {
         repository.resetConfiguration();
    }


    String confDebug = subst(element.getAttribute(CONFIG_DEBUG_ATTR));
    if(!confDebug.equals("") && !confDebug.equals("null")) {      
      LogLog.warn("The \""+CONFIG_DEBUG_ATTR+"\" attribute is deprecated.");
      LogLog.warn("Use the \""+INTERNAL_DEBUG_ATTR+"\" attribute instead.");
      LogLog.setInternalDebugging(OptionConverter.toBoolean(confDebug, true));
    }

    String thresholdStr = subst(element.getAttribute(THRESHOLD_ATTR));
    LogLog.debug("Threshold =\"" + thresholdStr +"\".");
    if(!"".equals(thresholdStr) && !"null".equals(thresholdStr)) {
      repository.setThreshold(thresholdStr);
    }

    //Hashtable appenderBag = new Hashtable(11);

    /* Building Appender objects, placing them in a local namespace
       for future reference */

    // First configure each category factory under the root element.
    // Category factories need to be configured before any of
    // categories they support.
    //
    String   tagName = null;
    Element  currentElement = null;
    Node     currentNode = null;
    NodeList children = element.getChildNodes();
    final int length = children.getLength();

    for (int loop = 0; loop < length; loop++) {
      currentNode = children.item(loop);
      if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
	currentElement = (Element) currentNode;
	tagName = currentElement.getTagName();

	if (tagName.equals(CATEGORY_FACTORY_TAG) || tagName.equals(LOGGER_FACTORY_TAG)) {
	  parseCategoryFactory(currentElement);
	}
      }
    }
    
    for (int loop = 0; loop < length; loop++) {
      currentNode = children.item(loop);
      if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
	currentElement = (Element) currentNode;
	tagName = currentElement.getTagName();

	if (tagName.equals(CATEGORY) || tagName.equals(LOGGER)) {
	  parseCategory(currentElement);
	} else if (tagName.equals(ROOT_TAG)) {
	  parseRoot(currentElement);
	} else if(tagName.equals(RENDERER_TAG)) {
	  parseRenderer(currentElement);
	} else if (!(tagName.equals(APPENDER_TAG)
            || tagName.equals(CATEGORY_FACTORY_TAG)
            || tagName.equals(LOGGER_FACTORY_TAG))) {
        quietParseUnrecognizedElement(repository, currentElement, props);
    }
      }
    }
  }
520913
public void generateProxy(Element element) {
        try {
            getClassBuilder(element)
                    .buildProxyClass()
                    .build()
                    .writeTo(filer);
        } catch (Exception ex) {
            messager.printMessage(Diagnostic.Kind.WARNING, "Error while generating Proxy " + ex.getMessage());
        }
    }
523205
public static CmsInlineEditOverlay addOverlayForElement(Element element) {

        CmsInlineEditOverlay overlay = new CmsInlineEditOverlay(element);
        if (!m_overlays.isEmpty()) {
            m_overlays.get(m_overlays.size() - 1).setVisible(false);
        }
        m_overlays.add(overlay);
        RootPanel.get().add(overlay);
        overlay.updatePosition();
        overlay.checkZIndex();
        return overlay;
    }
1074388
public synchronized void addElement(@NonNull T element) {
        hashCached = false;
        this.elementsMap.put(element.getLabel(), element);
        this.elements.add(element);
    }
829696
public void addPathElement(QPathEntry element) {
       if (relPath == null)
          this.relPath = new QPath(new QPathEntry[]{element});
       else
          this.relPath = QPath.makeChildPath(relPath, element, element.getIndex());
    }
372903
public static DateFormat getDateFormat(final Element element) {
		if (XMLTags.FORMAT.equals(element.getName())) {
			return createDateFormat(element);
		}
		Element child = element.getChild(XMLTags.FORMAT);
		if (child != null) {
			return createDateFormat(child);
		}
		return getDateFormat(element.getParentElement());
	}
462158
private static <T> Extension<T> parseBinderExtensionElement(Element element) {

        @SuppressWarnings("unchecked")
		Class<T> providerClass = (Class<T>)lookupClass(element.getAttribute("class"));
        
        Class<?> implementationClass = lookupClass(element.getAttribute("implementationClass"));

        if (providerClass == null) {
            throw new IllegalStateException("Referenced class {" + element.getAttribute("class")
                    + "} could not be found");
        }
        if (implementationClass == null) {
            throw new IllegalStateException("Referenced implementation class {" + element.getAttribute("implementationClass")
                    + "} could not be found");
        }
        if (providerClass.isAssignableFrom(implementationClass)) {
            throw new IllegalStateException("Referenced class {" + element.getAttribute("class")
                    + "} did not implement BindingProvider");
        }

		try {
			@SuppressWarnings("unchecked")
			final Class<? extends T> myImplementationClass = (Class<T>) implementationClass.newInstance();
			return new Extension<T>(providerClass, myImplementationClass);
		} catch (InstantiationException e) {
            throw new IllegalStateException("Referenced implementation class {" + element.getAttribute("implementationClass")
                    + "} could not be instantiated");
		} catch (IllegalAccessException e) {
            throw new IllegalStateException("Referenced implementation class {" + element.getAttribute("implementationClass")
                    + "} could not be accessed");
		}
    }
721787
public long indexOf(final String element) {
        return doWithJedis(new JedisCallable<Long>() {
            @Override
            public Long call(Jedis jedis) {
                return doIndexOf(jedis, element);
            }
        });
    }
935684
public List<PathAddressTransformer> getPathTransformations(final PathAddress address, PlaceholderResolver placeholderResolver) {
        final List<PathAddressTransformer> list = new ArrayList<PathAddressTransformer>();
        final Iterator<PathElement> iterator = address.iterator();
        resolvePathTransformers(iterator, list, placeholderResolver);
        if(iterator.hasNext()) {
            while(iterator.hasNext()) {
                iterator.next();
                list.add(PathAddressTransformer.DEFAULT);
            }
        }
        return list;
    }
174715
public static CmsPositionBean generatePositionInfo(Element element) {

        CmsPositionBean result = new CmsPositionBean();
        result.setHeight(element.getOffsetHeight());
        result.setWidth(element.getOffsetWidth());
        result.setTop(element.getAbsoluteTop());
        result.setLeft(element.getAbsoluteLeft());
        return result;
    }
93497
public static <E> void rootElement(WebElement root, E element) {
		if (element == null || root == null) return;
		if (element instanceof WebElement) return;
		
		for (Class<?> clazz = element.getClass(); !clazz.equals(Object.class);
				clazz = clazz.getSuperclass()) {
			
			if (Enhancer.isEnhanced(clazz)) continue;
			
			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				setRootElementField(root, element, field);
			}
		}
	}
847802
public static function processAcmAddress(&$element, FormStateInterface $form_state, &$complete_form) {
    $default_address = (array) $element['#default_value'];
    $address = $default_address + static::$addressDefaults;
    $country = !empty($address['country_id']) ? $address['country_id'] : 'US';
    $countryRepository = \Drupal::service('address.country_repository');
    $subdivisionRepository = \Drupal::service('address.subdivision_repository');
    $addressFormatRepository = \Drupal::service('address.address_format_repository');
    $address_format = $addressFormatRepository->get($country);
    $labels = LabelHelper::getFieldLabels($address_format);

    if (!empty($element['#include_address_id'])) {
      $element['address_id'] = [
        '#type' => 'hidden',
        '#default_value' => $address['address_id'],
      ];
    }

    if (!empty($element['#display_title'])) {
      $element['title'] = [
        '#type' => 'acm_title_select',
        '#title' => t('Title'),
        '#default_value' => empty($address['title']) ? NULL : $address['title'],
        '#required' => TRUE,
        '#placeholder' => t('Title*'),
      ];
    }

    if (!empty($element['#display_firstname'])) {
      $element['firstname'] = [
        '#type' => 'textfield',
        '#title' => t('First Name'),
        '#default_value' => $address['firstname'],
        '#required' => TRUE,
        '#placeholder' => t('First Name*'),
      ];
    }

    if (!empty($element['#display_lastname'])) {
      $element['lastname'] = [
        '#type' => 'textfield',
        '#title' => t('Last Name'),
        '#default_value' => $address['lastname'],
        '#required' => TRUE,
        '#placeholder' => t('Last Name*'),
      ];
    }

    if (!empty($element['#display_telephone'])) {
      $element['telephone'] = [
        '#type' => 'textfield',
        '#title' => t('Telephone'),
        '#default_value' => $address['telephone'],
        '#required' => TRUE,
        '#placeholder' => t('Telephone*'),
      ];
    }

    $element['street'] = [
      '#type' => 'textfield',
      '#title' => t('Address Line 1'),
      '#default_value' => $address['street'],
      '#required' => TRUE,
      '#placeholder' => t('Address Line 1*'),
    ];

    $element['street2'] = [
      '#type' => 'textfield',
      '#title' => t('Address Line 2'),
      '#default_value' => $address['street2'],
      '#required' => FALSE,
      '#placeholder' => t('Address Line 2'),
    ];

    $element['dynamic_parts'] = [
      '#type' => 'container',
      '#attributes' => [
        'id' => ['dynamic_parts'],
      ],
      '#parents' => $element['#parents'],
    ];

    $element['dynamic_parts']['city'] = [
      '#type' => 'textfield',
      '#title' => $labels['locality'],
      '#default_value' => $address['city'],
      '#required' => TRUE,
      '#placeholder' => $labels['locality'],
    ];

    $dynamic_parts = self::calculateDynamicParts($country);
    $regions = $subdivisionRepository->getList([$country]);

    $possiblyMatchingRegion = "";
    // If address has region and this country has regions to choose from
    // then try to fix the region mess, otherwise set region to "".
    if ($address['region'] && $dynamic_parts['region']['#access']) {
      // Some e-commerce back-ends send back region as an abbreviation and some
      // don't. If we don't have an abbreviation we'll need to flip the regions
      // array in order to find the default value to use.
      $possiblyMatchingRegion = AcmAddress::fixRegionMess($address['region'], $regions);
    }
    $default_region = $possiblyMatchingRegion;

    $element['dynamic_parts']['region'] = [
      '#type' => 'select',
      '#title' => $labels['administrativeArea'],
      '#options' => $regions,
      '#default_value' => $default_region,
      '#empty_option' => '- ' . $labels['administrativeArea'] . ' -',
      '#required' => TRUE,
      '#validated' => TRUE,
    ];

    $element['dynamic_parts']['postcode'] = [
      '#type' => 'textfield',
      '#title' => $labels['postalCode'],
      '#default_value' => $address['postcode'],
      '#required' => TRUE,
      '#placeholder' => $labels['postalCode'],
    ];

    $element['dynamic_parts']['country_id'] = [
      '#type' => 'select',
      '#title' => t('Country'),
      '#options' => $countryRepository->getList(),
      '#default_value' => $country,
      '#required' => TRUE,
      '#ajax' => [
        'callback' => [get_called_class(), 'addressAjaxCallback'],
        'wrapper' => 'dynamic_parts',
        'options' => [
          'query' => [
            'element_parents' => implode('/', $element['#array_parents']),
          ],
        ],
      ],
    ];

    // We created the dynamic parts as we may want them,
    // But now we calculate what is hidden or showing or required
    // and what labels are translated based on the country (not the locale...)
    $element['dynamic_parts'] = array_replace_recursive($element['dynamic_parts'], $dynamic_parts);

    if (!empty($element['#display_billing'])) {
      $element['default_billing'] = [
        '#type' => 'checkbox',
        '#title' => t('Default billing address'),
        '#default_value' => $address['default_billing'],
      ];
    }

    if (!empty($element['#display_shipping'])) {
      $element['default_shipping'] = [
        '#type' => 'checkbox',
        '#title' => t('Default shipping address'),
        '#default_value' => $address['default_shipping'],
      ];
    }

    // TODO (Malachy): Consider adding 'save address to address book' here.
    if (!empty($element['#validate_address'])) {
      $element['#element_validate'] = [[get_called_class(), 'validateAddress']];
      if (!isset($element['#address_review_text'])) {
        $element['#address_review_text'] = t('Address validation suggested a different address.');
      }
      if (!isset($element['#address_failed_text'])) {
        $element['#address_failed_text'] = t('Address validation failed.');
      }
    }

    $element['#tree'] = TRUE;

    return $element;
  }
1063554
private XmlElementFinder getElementFinder(final Element element) {
		if (elementFinder == null) {
			elementFinder = new XmlElementFinder(element.getDocument());
		}
		return elementFinder;
	}
906968
public static String getClass(String element) {
        Preconditions.checkNotNull(element,"argument 'element' can not be null");
        return element.substring(element.lastIndexOf('.') + 1);
    }
750300
FieldBuilder getFieldBuilder(Element element) {
        FieldBuilder fieldBuilder = new FieldBuilder(messager, element);
        fieldBuilder.setBindingManager(this);
        return fieldBuilder;
    }