Example usage for java.util Queue clear

List of usage examples for java.util Queue clear

Introduction

In this page you can find the example usage for java.util Queue clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this collection (optional operation).

Usage

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Get all nested children of a given component.
 *
 * @param component The component to search.
 * @return All nested children of the component.
 * @see ViewLifecycleUtils#getElementsForLifecycle(LifecycleElement)
 *//*from   ww  w . ja  v a  2  s.  co  m*/
public static List<Component> getAllNestedComponents(Component component) {
    if (component == null) {
        return Collections.emptyList();
    }

    List<Component> components = Collections.emptyList();
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    elementQueue.offer(component);

    try {
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();

            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof Component && currentElement != component) {
                if (components.isEmpty()) {
                    components = new ArrayList<Component>();
                }

                components.add((Component) currentElement);
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }

    return components;
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

public static void prefixBindingPathNested(Component component, String addBindingPrefix) {
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    elementQueue.offer(component);//from w w  w .j  a va2s  .c o  m

    try {
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();
            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof DataBinding) {
                if (LOG.isDebugEnabled()) {
                    LOG.info("setting nested binding prefix '" + addBindingPrefix + "' on " + currentElement);
                }
                prefixBindingPath((DataBinding) currentElement, addBindingPrefix);
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:com.nearinfinity.hbase.dsl.HBase.java

private void flushPuts(byte[] tableName, Queue<Put> puts) {
    HTableInterface table = pool.getTable(tableName);
    try {/* w w w .j a  v a 2  s  .  co  m*/
        table.put(new ArrayList<Put>(puts));
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            pool.putTable(table);
        } catch (IOException e) {
            LOG.error("pool table ", e);
        }
    }
    puts.clear();
}

From source file:com.nearinfinity.hbase.dsl.HBase.java

private void flushDeletes(byte[] tableName, Queue<Delete> deletes) {
    HTableInterface table = pool.getTable(tableName);
    try {//from w ww .  j ava2 s.c  o  m
        table.delete(new ArrayList<Delete>(deletes));
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            pool.putTable(table);
        } catch (IOException e) {
            LOG.error("pool table ", e);
        }

    }
    deletes.clear();
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Replace all IDs from a component and its children with new generated ID values.
 *
 * <p>If there are features that depend on a static id of this
 * component, this call may cause errors.</p>
 *
 * @param components A list of component to clear all IDs from.
 * @see AssignIdsTask For a complete description of the algorithm.
 *//*  ww w  . ja v  a  2s.c om*/
public static void clearAndAssignIds(List<? extends Component> components) {
    if (components == null || components.isEmpty()) {
        return;
    }

    int hash = 1;
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> toClear = RecycleUtils.getInstance(LinkedList.class);
    toClear.addAll(components);
    try {
        while (!toClear.isEmpty()) {
            LifecycleElement element = toClear.poll();

            hash = generateId(element, hash);

            for (LifecycleElement nested : ViewLifecycleUtils.getElementsForLifecycle(element).values()) {
                if (nested != null) {
                    toClear.add(nested);
                }
            }

            if (element instanceof Component) {
                List<Component> propertyReplacerComponents = ((Component) element)
                        .getPropertyReplacerComponents();
                if (propertyReplacerComponents == null) {
                    continue;
                }

                for (Component nested : propertyReplacerComponents) {
                    if (nested != null) {
                        toClear.add(nested);
                    }
                }
            }
        }
    } finally {
        toClear.clear();
        RecycleUtils.recycle(toClear);
    }
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Traverse a component tree, setting a property on all components for which the property is writable.
 *
 * @param <T> component type/*from w  w w .j  av a2s. co m*/
 * @param <T> component type
 * @param components The components to traverse.
 * @param propertyPath The property path to set.
 * @param propertyValue The property value to set.
 * @see ObjectPropertyUtils#isWritableProperty(Object, String)
 * @see ObjectPropertyUtils#setPropertyValue(Object, String, Object)
 */
public static <T extends Component> void setComponentsPropertyDeep(List<T> components, String propertyPath,
        Object propertyValue) {
    if (components == null || components.isEmpty()) {
        return;
    }

    Set<Class<?>> skipTypes = null;
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    elementQueue.addAll(components);

    try {
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();
            if (currentElement == null) {
                continue;
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());

            Class<?> componentClass = currentElement.getClass();
            if (skipTypes != null && skipTypes.contains(componentClass)) {
                continue;
            }

            if (!ObjectPropertyUtils.isWritableProperty(currentElement, propertyPath)) {
                if (skipTypes == null) {
                    skipTypes = new HashSet<Class<?>>();
                }
                skipTypes.add(componentClass);
                continue;
            }

            ObjectPropertyUtils.setPropertyValue(currentElement, propertyPath, propertyValue, true);
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:com.mtgi.analytics.XmlBehaviorEventPersisterImpl.java

public void persist(Queue<BehaviorEvent> events) {
    try {/*  www  .j av a  2s. com*/
        BehaviorEventSerializer serializer = new BehaviorEventSerializer();

        for (BehaviorEvent event : events) {
            if (event.getId() == null)
                event.setId(randomUUID());

            BehaviorEvent parent = event.getParent();
            if (parent != null && parent.getId() == null)
                parent.setId(randomUUID());

            synchronized (this) {
                serializer.serialize(writer, event);
                writer.writeCharacters("\n");
            }
        }

        synchronized (this) {
            writer.flush();
            stream.flush();
        }

    } catch (Exception error) {
        log.error("Error persisting events; discarding " + events.size() + " events without saving", error);
        events.clear();
    }
}

From source file:org.kuali.rice.krad.uif.element.ValidationMessages.java

/**
 * Adds all group keys of this component (starting from this component itself) by calling getKeys on each of
 * its nested group's ValidationMessages and adding them to the list.
 *
 * @param keyList/*ww  w .  j  ava2s . c o  m*/
 * @param component
 */
protected void addNestedGroupKeys(Collection<String> keyList, Component component) {
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    try {
        elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(component).values());
        while (!elementQueue.isEmpty()) {
            LifecycleElement element = elementQueue.poll();

            ValidationMessages ef = null;
            if (element instanceof ContainerBase) {
                ef = ((ContainerBase) element).getValidationMessages();
            } else if (element instanceof FieldGroup) {
                ef = ((FieldGroup) element).getGroup().getValidationMessages();
            }

            if (ef != null) {
                keyList.addAll(ef.getKeys((Component) element));
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(element).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:candr.yoclip.ParserTest.java

@Test
public void getParsedOptionProperty() {
    final ParserOption<ParserTest> mockOptionProperty = createMockOptionProperty("T");
    final List<ParserOption<ParserTest>> parserOptions = Arrays.asList(mockOptionProperty);

    final ParserOptions<ParserTest> mockParserOptions = createMockParserParameters("++");
    when(mockParserOptions.get()).thenReturn(parserOptions);
    when(mockParserOptions.get("T")).thenReturn(mockOptionProperty);

    final Queue<String> parameters = new LinkedList<String>();

    final Parser<ParserTest> testCase = new Parser<ParserTest>(mockParserOptions,
            createMockParserHelpFactory());
    assertThat("empty queue", testCase.getParsedOptionProperty(parameters), nullValue());

    final String expectedArgument = "argument";
    parameters.add(expectedArgument);//from w  w  w.jav a 2 s.  c  om
    assertThat("parsed parameter with argument", testCase.getParsedOptionProperty(parameters), nullValue());
    assertThat("queue size after parsed parameter error", parameters.size(), is(1));

    parameters.clear();
    parameters.add("++Tfoo=bar");
    final ParsedOption<ParserTest> parsedOption = testCase.getParsedOptionProperty(parameters);
    assertThat("ParsedOption error", parsedOption.isError(), is(false));
    assertThat("parser option", parsedOption.getParserOption(), is(mockOptionProperty));
    assertThat("value", parsedOption.getValue(), is("foo=bar"));
    assertThat("queue size after parsed parameter", parameters.size(), is(0));

    parameters.add("++Dfoo=bar");
    assertThat("property not matched", testCase.getParsedOptionProperty(parameters), nullValue());
}

From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java

private void emptyRecycler() {
    if (null != mRecycleBin) {
        while (mRecycleBin.size() > 0) {
            Queue<View> recycler = mRecycleBin.remove(0);
            recycler.clear();
        }/*from   w  ww .  ja v a  2 s  .c o m*/
        mRecycleBin.clear();
    }
}