Java Code Examples for org.apache.commons.lang3.mutable.MutableObject#setValue()

The following examples show how to use org.apache.commons.lang3.mutable.MutableObject#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigValues.java    From SkyblockAddons with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <E extends Enum<?>> void deserializeEnumValueFromOrdinal(MutableObject<E> value, String path) {
    try {
        Class<? extends Enum<?>> enumClass = value.getValue().getDeclaringClass();
        Method method = enumClass.getDeclaredMethod("values");
        Object valuesObject = method.invoke(null);
        E[] values = (E[])valuesObject;

        if (settingsConfig.has(path)) {
            int ordinal = settingsConfig.get(path).getAsInt();
            if (values.length > ordinal) {
                E enumValue = values[ordinal];
                if (enumValue != null) {
                    value.setValue(values[ordinal]);
                }
            }
        }
    } catch (Exception ex) {
        SkyblockAddons.getInstance().getLogger().error("Failed to deserialize path: "+ path);
        ex.printStackTrace();
    }
}
 
Example 2
Source File: LocalContextTest.java    From flux with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldAllowSameMethodRegistrationFromDifferentThreads() throws Exception {

    final MutableObject<StateMachineDefinition> definitionOne = new MutableObject<>(null);
    final MutableObject<StateMachineDefinition> definitionTwo = new MutableObject<>(null);

    final Thread thread1 = new Thread(() -> {
        localContext.registerNew("fooBar", 1, "someDescription",
                "someContext", "defaultElbId");
        definitionOne.setValue(tlStateMachineDef.get());
    });
    final Thread thread2 = new Thread(() -> {
        localContext.registerNew("fooBar", 1, "someDescription",
                "someContext", "defaultElbId");
        definitionTwo.setValue(tlStateMachineDef.get());
    });
    thread1.start();
    thread2.start();

    thread1.join();
    thread2.join();

    assertThat(definitionOne.getValue()).isNotNull().isEqualTo(definitionTwo.getValue()).isEqualTo(new StateMachineDefinition(
            "someDescription", "fooBar", 1l, new HashSet<>(), new HashSet<>(),
            "someContext", "defaultElbId"));
}
 
Example 3
Source File: ManagedLedgerTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
private boolean updateCusorMetadataByCreatingMetadataLedger(MutableObject<ManagedCursorImpl> cursor2)
        throws InterruptedException {
    MutableObject<Boolean> failed = new MutableObject<>();
    failed.setValue(false);
    CountDownLatch createLedgerDoneLatch = new CountDownLatch(1);
    cursor2.getValue().createNewMetadataLedger(new VoidCallback() {

        @Override
        public void operationComplete() {
            createLedgerDoneLatch.countDown();
        }

        @Override
        public void operationFailed(ManagedLedgerException exception) {
            failed.setValue(true);
            createLedgerDoneLatch.countDown();
        }

    });
    createLedgerDoneLatch.await();
    return failed.getValue();
}
 
Example 4
Source File: InMemoryNodeModel.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a tracked node that has already been resolved to the specified data
 * object.
 *
 * @param current the current {@code TreeData} object
 * @param node the node in question
 * @param resolver the {@code NodeKeyResolver}
 * @param refSelector here the newly created {@code NodeSelector} is
 *        returned
 * @return the new {@code TreeData} instance
 */
private static TreeData updateDataWithNewTrackedNode(final TreeData current,
        final ImmutableNode node, final NodeKeyResolver<ImmutableNode> resolver,
        final MutableObject<NodeSelector> refSelector)
{
    final NodeSelector selector =
            new NodeSelector(resolver.nodeKey(node,
                    new HashMap<ImmutableNode, String>(), current));
    refSelector.setValue(selector);
    final NodeTracker newTracker =
            current.getNodeTracker().trackNodes(
                    Collections.singleton(selector),
                    Collections.singleton(node));
    return current.updateNodeTracker(newTracker);
}
 
Example 5
Source File: XMLConfiguration.java    From commons-configuration with Apache License 2.0 4 votes vote down vote up
/**
 * Helper method for building the internal storage hierarchy. The XML
 * elements are transformed into node objects.
 *
 * @param node a builder for the current node
 * @param refValue stores the text value of the element
 * @param element the current XML element
 * @param elemRefs a map for assigning references objects to nodes; can be
 *        <b>null</b>, then reference objects are irrelevant
 * @param trim a flag whether the text content of elements should be
 *        trimmed; this controls the whitespace handling
 * @param level the current level in the hierarchy
 * @return a map with all attribute values extracted for the current node;
 *         this map also contains the value of the trim flag for this node
 *         under the key {@value #ATTR_SPACE}
 */
private Map<String, String> constructHierarchy(final ImmutableNode.Builder node,
        final MutableObject<String> refValue, final Element element,
        final Map<ImmutableNode, Object> elemRefs, final boolean trim, final int level)
{
    final boolean trimFlag = shouldTrim(element, trim);
    final Map<String, String> attributes = processAttributes(element);
    attributes.put(ATTR_SPACE_INTERNAL, String.valueOf(trimFlag));
    final StringBuilder buffer = new StringBuilder();
    final NodeList list = element.getChildNodes();
    boolean hasChildren = false;

    for (int i = 0; i < list.getLength(); i++)
    {
        final org.w3c.dom.Node w3cNode = list.item(i);
        if (w3cNode instanceof Element)
        {
            final Element child = (Element) w3cNode;
            final ImmutableNode.Builder childNode = new ImmutableNode.Builder();
            childNode.name(child.getTagName());
            final MutableObject<String> refChildValue =
                    new MutableObject<>();
            final Map<String, String> attrmap =
                    constructHierarchy(childNode, refChildValue, child,
                            elemRefs, trimFlag, level + 1);
            final Boolean childTrim = Boolean.valueOf(attrmap.remove(ATTR_SPACE_INTERNAL));
            childNode.addAttributes(attrmap);
            final ImmutableNode newChild =
                    createChildNodeWithValue(node, childNode, child,
                            refChildValue.getValue(),
                            childTrim.booleanValue(), attrmap, elemRefs);
            if (elemRefs != null && !elemRefs.containsKey(newChild))
            {
                elemRefs.put(newChild, child);
            }
            hasChildren = true;
        }
        else if (w3cNode instanceof Text)
        {
            final Text data = (Text) w3cNode;
            buffer.append(data.getData());
        }
    }

    boolean childrenFlag = false;
    if (hasChildren || trimFlag)
    {
        childrenFlag = hasChildren || attributes.size() > 1;
    }
    final String text = determineValue(buffer.toString(), childrenFlag, trimFlag);
    if (text.length() > 0 || (!childrenFlag && level != 0))
    {
        refValue.setValue(text);
    }
    return attributes;
}