<commit_before>/**
 * 
 */
package org.vaadin.gwtgraphics.client;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.vaadin.gwtgraphics.client.impl.DrawImpl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseWheelEvent;
import com.google.gwt.event.dom.client.MouseWheelHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author <NAME>
 * 
 */
public abstract class AbstractDrawingContainer extends Panel implements Drawing, HasDrawings, Orderable {

	protected static final DrawImpl impl = GWT.create(DrawImpl.class);

	private List<Drawing> children = new ArrayList<>();

	public AbstractDrawingContainer() {
		setElement(impl.createElement(getType()));
	}

	protected DrawImpl getImpl() {
		return impl;
	}

	@Override
	public void add(Widget child) {
		if (child instanceof Drawing) {
			getImpl().add(getElement(), child.getElement(), child.isAttached());
			adopt(child);
			children.add((Drawing) child);
		}
	}

	@Override
	public Drawing addDrawing(Drawing drawing) {
		add(drawing.asWidget());

		return drawing;
	}

	@Override
	public Iterator<Drawing> drawingIterator() {
		return children.iterator();
	}

	@Override
	public Iterator<Widget> iterator() {
		List<Widget> widgets = new ArrayList<>();
		for (Drawing drawing : children) {
			widgets.add(drawing.asWidget());
		}
		return widgets.iterator();
	}

	@Override
	public boolean remove(Widget child) {
		if (child instanceof Drawing) {
			getElement().removeChild(child.getElement());
			orphan(child);
			children.remove(child);
			return true;
		}

		return false;
	}

	@Override
	public Drawing removeDrawing(Drawing drawing) {
		return remove(drawing.asWidget()) ? drawing : null;
	}

	@Override
	public void clear() {
		for (Drawing drawing : children) {
			getElement().removeChild(drawing.asWidget().getElement());
			orphan(drawing.asWidget());
		}

		children.clear();
	}

	@Override
	public Drawing insert(Drawing drawing, int beforeIndex) {
		if (beforeIndex < 0 || beforeIndex > getCount()) {
			throw new IndexOutOfBoundsException();
		}

		if (children.contains(drawing)) {
			children.remove(drawing);
		}

		getImpl().insert(getElement(), drawing.asWidget().getElement(), beforeIndex, drawing.asWidget().isAttached());<commit_msg>fixed client bug in use of orphan method<commit_after>/**
 * 
 */
package org.vaadin.gwtgraphics.client;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.vaadin.gwtgraphics.client.impl.DrawImpl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DoubleClickEvent;
import com.google.gwt.event.dom.client.DoubleClickHandler;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseWheelEvent;
import com.google.gwt.event.dom.client.MouseWheelHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author <NAME>
 * 
 */
public abstract class AbstractDrawingContainer extends Panel implements Drawing, HasDrawings, Orderable {

	protected static final DrawImpl impl = GWT.create(DrawImpl.class);

	private List<Drawing> children = new ArrayList<>();

	public AbstractDrawingContainer() {
		setElement(impl.createElement(getType()));
	}

	protected DrawImpl getImpl() {
		return impl;
	}

	@Override
	public void add(Widget child) {
		if (child instanceof Drawing) {
			getImpl().add(getElement(), child.getElement(), child.isAttached());
			adopt(child);
			children.add((Drawing) child);
		}
	}

	@Override
	public Drawing addDrawing(Drawing drawing) {
		add(drawing.asWidget());

		return drawing;
	}

	@Override
	public Iterator<Drawing> drawingIterator() {
		return children.iterator();
	}

	@Override
	public Iterator<Widget> iterator() {
		List<Widget> widgets = new ArrayList<>();
		for (Drawing drawing : children) {
			widgets.add(drawing.asWidget());
		}
		return widgets.iterator();
	}

	@Override
	public boolean remove(Widget child) {
		if (child instanceof Drawing) {
			getElement().removeChild(child.getElement());
			Widget parent = child.getParent();
			if (parent == this) {
				orphan(child);
			}
			children.remove(child);
			return true;
		}

		return false;
	}

	@Override
	public Drawing removeDrawing(Drawing drawing) {
		return remove(drawing.asWidget()) ? drawing : null;
	}

	@Override
	public void clear() {
		for (Drawing drawing : children) {
			getElement().removeChild(drawing.asWidget().getElement());
			Widget parent = drawing.asWidget().getParent();
			if (parent == this) {
				orphan(drawing.asWidget());
			}
		}

		children.clear();
	}

	@Override
	public Drawing insert(Drawing drawing, int beforeIndex) {
		if (beforeIndex < 0 || beforeIndex > getCount()) {
			throw new IndexOutOfBoundsException();
		}

		if (children.contains(drawing)) {
			children.remove(drawing);
		}

		getImpl().insert(getElement(), drawing.asWidget().getElement(), beforeIndex, drawing.asWidget().isAttached());
{'fraction_non_alphanumeric': 0.13320049049662783, 'fraction_numerical': 0.00030656039239730225, 'mean_word_length': 4.831099195710456, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '377627', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2044, 'n_words': 386}