/*
Find the first child of the switch that passes the feature tests and render only that child.
177136
private void render(SVG.Switch obj)
   {
      debug("Switch render");

      updateStyleForElement(state, obj);

      if (!display())
         return;

      if (obj.transform != null) {
         canvas.concat(obj.transform);
      }

      checkForClipPath(obj);

      boolean  compositing = pushLayer();

      renderSwitchChild(obj);

      if (compositing)
         popLayer(obj);

      updateParentBoundingBox(obj);
   }
3519
function(element, options) {
    return Element.findChildren(
      element, options.only, options.tree ? true : false, options.tag);
  }
395735
function(e) {
    e = e || window.event;
    e.preventDefault ? e.preventDefault() : (e.returnValue = false);

    var eTarget = e.target || e.srcElement;

    // find root element of slide
    var clickedListItem = closest(eTarget, function(el) {
      //console.log(el.getAttribute('ui-gallery-item'));
      return el.getAttribute('ui-gallery-item') != null;
    });

    if (!clickedListItem) {
      return;
    }

    var parentNode = closest(eTarget, function(el) {
      return el.getAttribute('ui-gallery') != null;
    });

    if (!parentNode) {
      return;
    }

    var childNodes = parentNode.querySelectorAll('[ui-gallery-item]');

    // find index of clicked item by looping through all child nodes
    // alternatively, you may define index via data- attribute
    var clickedGallery = parentNode,
      numChildNodes = childNodes.length,
      nodeIndex = 0,
      index;

    for (var i = 0; i < numChildNodes; i++) {
      if (childNodes[i].nodeType !== 1) {
        continue;
      }

      if (childNodes[i] === clickedListItem) {
        index = nodeIndex;
        break;
      }
      nodeIndex++;
    }
    if (index >= 0) {
      // open PhotoSwipe if valid index found
      openPhotoSwipe(index, clickedGallery);
    }
    return false;
  }
797191
function()
	{
		var boundView, i, l, el, a;
		var lastView, lastChild, parentNode, item;
		var insertBefore = defaultInsertBefore;
		var removeChild = defaultRemoveChild;
		var oldCollection = this.collection;

		if(this.animate)
		{
			insertBefore = this.view.scope[this.animate]['insert'];
			removeChild = this.view.scope[this.animate]['remove'];
		}

		this.rebindCollection();

		// This will speed up rendering but requires strictly immutable collections
		if(settings.immutableCollections && oldCollection === this.collection) return;

		if(this.boundViews === null) this.boundViews = [];

		if(this.boundViews.length === 0)
		{
			// Fast initial rendering:
			l = this.collection.length;
			if(l > 0)
			{
				a = this.collection;
				lastChild = this.anchor;
				if(this.anchor && this.anchor.parentNode)
				{
					parentNode = this.anchor.parentNode;
					for(i = 0; i < l; i++)
					{
						boundView = this.createBoundView(a[i]);
						this.boundViews[i].runAll();
						this.boundViews[i].afterRunAll();
						el = boundView.element;
						insertBefore(parentNode, lastChild.nextSibling, el);
						lastChild = el;
					}
				}
			}
		}
		else
		{
			// Diff based rendering:
			var newCollection = this.collection;
			var newBoundViews = [];
			var recycledViews = [];
			var oldCollectionKeyMap;
			var newCollectionKeyMap;
			if(this.keyProp)
			{
				oldCollectionKeyMap = {};
				for(i = 0, l = oldCollection.length; i < l; i++)
				{
					oldCollectionKeyMap[oldCollection[i][this.keyProp]] = i;
				}

				newCollectionKeyMap = {};
				for(i = 0, l = newCollection.length; i < l; i++)
				{
					newCollectionKeyMap[newCollection[i][this.keyProp]] = i;
				}
			}

			// Merge old and new bound view arrays:
			var tempBoundViews = [];
			for(i = 0, l = Math.max(oldCollection.length, newCollection.length); i < l; i++)
			{
				if(oldCollection[i] && getKeyedItemIndex(newCollection, oldCollection[i], this.keyProp, newCollectionKeyMap) === -1)
				{
					// Item is in the old collection but not in the new one
					boundView = this.boundViews[i];
					if(this.animate)
					{
						tempBoundViews.push(boundView);
						lastView = boundView;
					}
					else lastView = null;
					recycledViews.push(boundView);
				}
				if(newCollection[i])
				{
					// Item is in the new collection
					var oldIndex = getKeyedItemIndex(oldCollection, newCollection[i], this.keyProp, oldCollectionKeyMap);
					if(oldIndex !== -1)
					{
						// Item is already rendered, reuse its view
						boundView = this.boundViews[oldIndex];
						tempBoundViews.push(boundView);
						boundView.scope['*'] = this.cursor.refine([i]);
						if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*'];
						boundView.setBindingIndex(i);
						newBoundViews.push(boundView);
						lastView = boundView;
					}
					else
					{
						// Item is new, create new binding view
						if(this.animate || recycledViews.length === 0)
						{
							boundView = this.createBoundView(newCollection[i]);
							boundView.scope['*'] = this.cursor.refine([i]);
							if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*'];
							boundView.setBindingIndex(i);
							boundView.runAll();
							boundView.afterRunAll();
						}
						else
						{
							boundView = recycledViews.shift();
							boundView.scope['*'] = this.cursor.refine([i]);
							if(this.view._itemAlias) boundView.scope[this.view._itemAlias] = boundView.scope['*'];
							boundView.setBindingIndex(i);
						}
						tempBoundViews.push(boundView);
						newBoundViews.push(boundView);
						lastView = null;
					}
				}
			}

			if(lastView)
			{
				// Reordering elements from the last one:
				lastChild = lastView.element;
				i = tempBoundViews.length - 1;

				el = tempBoundViews[i].element;
				if(el !== lastChild && lastChild.parentNode && lastChild.parentNode.nodeType === 1 && el !== lastChild.nextSibling)
				{
					insertBefore(lastChild.parentNode, lastChild.nextSibling, el);
					lastChild = el;
				}

				for(; i >= 0; i--)
				{
					el = tempBoundViews[i].element;
					var nextSibling = el.nextSibling;
					if(el !== lastChild && nextSibling !== lastChild && lastChild.parentNode && lastChild.parentNode.nodeType === 1)
					{
						insertBefore(lastChild.parentNode, lastChild, el);
					}
					lastChild = el;
					tempBoundViews[i].refreshIndexedBinders(true);
				}
			}
			else
			{
				// Add elements after anchor text node:
				lastChild = this.anchor;
				if(this.anchor.parentNode)
				{
					parentNode = this.anchor.parentNode;
				}
				for(i = 0, l = tempBoundViews.length; i < l; i++)
				{
					el = tempBoundViews[i].element;

					if(el !== lastChild.nextSibling)
					{
						insertBefore(parentNode, lastChild.nextSibling, el);
					}
					tempBoundViews[i].refreshIndexedBinders(true);
					lastChild = el;
				}
			}
			this.boundViews = newBoundViews;

			// Remove old views:
			for(i = 0, l = recycledViews.length; i < l; i++)
			{
				var viewToRemove = recycledViews[i];
				if(viewToRemove.element && viewToRemove.element.parentNode)
				{
					removeNodeAsync(viewToRemove, removeChild);
				}
			}
		}
	}
263471
function getNextChild(child) {
         var index = this.children.indexOf(child) - 1;

         if (index >= 0 && index < this.children.length) {
           return this.getChildAt(index);
         }

         return undefined;
       }
3994
function(node) {
        var simple = true;
        for(var child=node.firstChild; child; child=child.nextSibling) {
            if(child.nodeType === 1) {
                simple = false;
                break;
            }
        }
        return simple;
    }
665278
def first_child_found_in(self, *tagnames):
        
        for tagname in tagnames:
            child = self.find(qn(tagname))
            if child is not None:
                return child
        return None
500052
function(childNode) {
        if (this.hasChildren()) {
            var sib = this.children[this.children.length - 1];
            sib.nextSibling = childNode;
            childNode.previousSibling = sib;
        }
        this.children[this.children.length] = childNode;
        childNode.applyParent(this);

        // part of the IE display issue workaround. If child nodes
        // are added after the initial render, and the node was
        // instantiated with expanded = true, we need to show the
        // children div now that the node has a child.
        if (this.childrenRendered && this.expanded) {
            this.getChildrenEl().style.display = "";
        }

        return childNode;
    }
935165
protected boolean firstChild(final Parse child, final Parse parent) {
    return ShiftReduceParser.collapsePunctuation(parent.getChildren(),
        this.punctSet)[0] == child;
  }
585485
function getFirstChildElement(parent) {
  var cursor = parent.firstChild;

  while (cursor && cursor.nodeType !== 1) {
    cursor = cursor.nextSibling;
  }
  return cursor;
}
281228
def getFirstChildElementByTagName(self, tagName):
    
    for child in self.childNodes:
        if isinstance(child, Element):
            if child.tagName == tagName:
                return child
    return None
234237
public function getFirst()
    {
        if (count($this->children)) {
            reset($this->children);
            return current($this->children);
        } else {
            return null;
        }
    }
356788
public static UIComponent findChildByTagId(UIComponent parent, String id)
    {
        Iterator<UIComponent> itr = null;
        if (parent.getChildCount() > 0)
        {
            for (int i = 0, childCount = parent.getChildCount(); i < childCount; i ++)
            {
                UIComponent child = parent.getChildren().get(i);
                if (id.equals(child.getAttributes().get(MARK_CREATED)))
                {
                    return child;
                }
            }
        }
        if (parent.getFacetCount() > 0)
        {
            itr = parent.getFacets().values().iterator();
            while (itr.hasNext())
            {
                UIComponent facet = itr.next();
                // check if this is a dynamically generated UIPanel
                if (Boolean.TRUE.equals(facet.getAttributes()
                             .get(FACET_CREATED_UIPANEL_MARKER)))
                {
                    // only check the children and facets of the panel
                    if (facet.getChildCount() > 0)
                    {
                        for (int i = 0, childCount = facet.getChildCount(); i < childCount; i ++)
                        {
                            UIComponent child = facet.getChildren().get(i);
                            if (id.equals(child.getAttributes().get(MARK_CREATED)))
                            {
                                return child;
                            }
                        }
                    }
                    if (facet.getFacetCount() > 0)
                    {
                        Iterator<UIComponent> itr2 = facet.getFacets().values().iterator();
                        while (itr2.hasNext())
                        {
                            UIComponent child = itr2.next();
                            if (id.equals(child.getAttributes().get(MARK_CREATED)))
                            {
                                return child;
                            }
                        }
                    }
                }
                else if (id.equals(facet.getAttributes().get(MARK_CREATED)))
                {
                    return facet;
                }
            }
        }

        return null;
    }
1195769
def firstElementChild(self) -> Optional[AbstractNode]:
        
        for child in self.childNodes:
            if child.nodeType == Node.ELEMENT_NODE:
                return child
        return None
461820
private boolean firstChild(Parse child, Parse parent) {
    return ParserME.collapsePunctuation(parent.getChildren(),punctSet)[0] == child;
  }
772054
public function getFirst()
    {
        $first = null;

        if (count($this->renderers) > 0) {
            $first = reset($this->renderers);
        }

        return $first;
    }
294052
function search(root, test, skip, callback) {
  var index = -1
  var children = root.children
  var length = children.length
  var depth = null
  var start = null
  var end = null
  var nodes
  var clean
  var child

  while (++index < length) {
    child = children[index]

    if (closing(child, depth)) {
      end = index
      break
    }

    if (opening(child, depth, test)) {
      start = index
      depth = child.depth
    }
  }

  if (start !== null) {
    if (end === null) {
      end = length
    }

    if (skip) {
      while (end > start) {
        child = children[end - 1]

        if (!definition(child)) {
          break
        }

        end--
      }
    }

    nodes = callback(
      children[start],
      children.slice(start + 1, end),
      children[end],
      {
        parent: root,
        start: start,
        end: children[end] ? end : null
      }
    )

    clean = []
    index = -1
    length = nodes && nodes.length

    // Ensure no empty nodes are inserted.  This could be the case if `end` is
    // in `nodes` but no `end` node exists.
    while (++index < length) {
      if (nodes[index]) {
        clean.push(nodes[index])
      }
    }

    if (nodes) {
      splice.apply(children, [start, end - start + 1].concat(clean))
    }
  }
}