Example usage for java.util LinkedList isEmpty

List of usage examples for java.util LinkedList isEmpty

Introduction

In this page you can find the example usage for java.util LinkedList isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:org.diorite.config.impl.NestedNodesHelper.java

@SuppressWarnings("unchecked")
@Nullable//  w  ww . ja  va 2  s  .c  om
static Object get(Object object, LinkedList<String> path) {
    while (true) {
        if (path.isEmpty()) {
            throw new IllegalArgumentException("Empty path given");
        }
        String current = path.removeFirst();
        try {
            Object val;
            if (object instanceof Config) {
                val = ((Config) object).get(current);
            } else if (object instanceof Map) {
                val = ((Map<Object, Object>) object).get(current);
            } else if (object instanceof List) {
                val = ((List<Object>) object).get(Integer.parseInt(current));
            } else {
                Class<?> type = object.getClass();
                CacheKey cacheKey = new CacheKey(type, current);
                ReflectedProperty<?> property = propertyCache.computeIfAbsent(cacheKey,
                        k -> DioriteReflectionUtils.getReflectedProperty(current, type));
                val = property.get(object);
            }
            if (path.isEmpty()) {
                return val;
            }
            Validate.notNull(val, "Value on: " + current + " in " + object + " is null");
            object = val;
        } catch (Exception e) {
            throw new IllegalStateException("Can't find property: " + current + " (" + path + ") in: " + object,
                    e);
        }
    }
}

From source file:Main.java

/**
 * Normalize a uri containing ../ and ./ paths.
 *
 * @param uri The uri path to normalize//from  www.j  av a2 s. c om
 * @return The normalized uri
 */
public static String normalize(String uri) {
    if ("".equals(uri)) {
        return uri;
    }
    int leadingSlashes;
    for (leadingSlashes = 0; leadingSlashes < uri.length()
            && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) {
    }
    boolean isDir = (uri.charAt(uri.length() - 1) == '/');
    StringTokenizer st = new StringTokenizer(uri, "/");
    LinkedList clean = new LinkedList();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if ("..".equals(token)) {
            if (!clean.isEmpty() && !"..".equals(clean.getLast())) {
                clean.removeLast();
                if (!st.hasMoreTokens()) {
                    isDir = true;
                }
            } else {
                clean.add("..");
            }
        } else if (!".".equals(token) && !"".equals(token)) {
            clean.add(token);
        }
    }
    StringBuffer sb = new StringBuffer();
    while (leadingSlashes-- > 0) {
        sb.append('/');
    }
    for (Iterator it = clean.iterator(); it.hasNext();) {
        sb.append(it.next());
        if (it.hasNext()) {
            sb.append('/');
        }
    }
    if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') {
        sb.append('/');
    }
    return sb.toString();
}

From source file:com.codenvy.commons.lang.TarUtils.java

private static void addDirectoryRecursively(TarArchiveOutputStream tarOut, String parentPath, File dir,
        long modTime, FilenameFilter filter) throws IOException {
    final int parentPathLength = parentPath.length() + 1;
    final LinkedList<File> q = new LinkedList<>();
    q.add(dir);//  w  w w  . j  ava2 s  .co  m
    while (!q.isEmpty()) {
        final File current = q.pop();
        final File[] list = current.listFiles();
        if (list != null) {
            for (File f : list) {
                if (filter.accept(current, f.getName())) {
                    final String entryName = f.getAbsolutePath().substring(parentPathLength).replace('\\', '/');
                    if (f.isDirectory()) {
                        addDirectoryEntry(tarOut, entryName, f, modTime);
                        q.push(f);
                    } else if (f.isFile()) {
                        addFileEntry(tarOut, entryName, f, modTime);
                    }
                }
            }
        }
    }
}

From source file:org.dswarm.common.model.util.AttributePathUtil.java

public static String generateAttributePath(final LinkedList<Attribute> attributes) {

    if (attributes == null || attributes.isEmpty()) {

        return null;
    }/*  www. ja va2 s. c om*/

    final StringBuilder sb = new StringBuilder();

    for (int i = 0; i < attributes.size(); i++) {

        sb.append(attributes.get(i));

        if (i < (attributes.size() - 1)) {

            sb.append(DMPStatics.ATTRIBUTE_DELIMITER);
        }
    }

    return sb.toString();
}

From source file:org.diorite.config.impl.NestedNodesHelper.java

@SuppressWarnings("unchecked")
static void set(Object object, LinkedList<String> path, @Nullable Object newValue) {
    String last = path.removeLast();
    Object preLast;//from  w  w w.  j  av  a  2  s.  c o m
    if (path.isEmpty()) {
        preLast = object;
    } else {
        preLast = get(object, path);
    }

    Validate.notNull(preLast);

    try {
        if (preLast instanceof Config) {
            ((Config) preLast).set(last, newValue);
        } else if (preLast instanceof Map) {
            ((Map<Object, Object>) preLast).put(last, newValue);
        } else if (preLast instanceof List) {
            List<Object> list = (List<Object>) preLast;
            int size = list.size();
            int index = Integer.parseInt(last);
            if (index == size) {
                list.add(newValue);
            } else if (index > size) {
                while (index > size++) {
                    list.add(null);
                }
                list.add(newValue);
            } else {
                list.set(index, newValue);
            }
        } else {
            Class<?> type = preLast.getClass();
            CacheKey cacheKey = new CacheKey(type, last);
            ReflectedProperty<?> property = propertyCache.computeIfAbsent(cacheKey,
                    k -> DioriteReflectionUtils.getReflectedProperty(last, type));
            property.set(preLast, newValue);
        }
    } catch (Exception e) {
        throw new IllegalStateException("Can't find property: " + last + " (" + path + ") in: " + preLast, e);
    }
}

From source file:org.jbpm.db.JbpmSession.java

/**
 * @deprecated use {@link org.jbpm.JbpmConfiguration#getCurrentJbpmContext()} instead.
 *//* ww  w.j  a  va  2s .  c o  m*/
public static JbpmSession getCurrentJbpmSession() {
    JbpmSession jbpmSession = null;
    LinkedList stack = (LinkedList) currentJbpmSessionStack.get();
    if ((stack != null) && (!stack.isEmpty())) {
        jbpmSession = (JbpmSession) stack.getFirst();
    }
    return jbpmSession;
}

From source file:org.nuxeo.ecm.platform.sync.utils.ImportUtils.java

/**
 * Returns the list of transition names to follow to go from one particular state to another.
 *
 * @param lifeCycle - the lifecycle/*from ww w .  j a v a 2  s . c  om*/
 * @param origState - the origin state
 * @param destState - the destination state
 * @return the list of transition names
 */
public static List<String> getLifeCycleTransitions(LifeCycle lifeCycle, String origState, String destState)
        throws LifeCycleException {
    List<String> path = new ArrayList<String>();
    LinkedList<List<String>> paths = new LinkedList<List<String>>();
    paths.add(path);

    LinkedList<String> fifo = new LinkedList<String>();
    fifo.add(origState);

    ArrayList<String> marked = new ArrayList<String>();
    marked.add(origState);

    while (!fifo.isEmpty()) {
        String state = fifo.removeFirst();
        path = paths.removeFirst();
        if (state.equals(destState)) {
            break;
        }
        for (String transitionName : lifeCycle.getAllowedStateTransitionsFrom(state)) {
            LifeCycleTransition transition = lifeCycle.getTransitionByName(transitionName);
            String nextState = transition.getDestinationStateName();
            if (!marked.contains(nextState)) {
                marked.add(nextState);
                fifo.addLast(nextState);
                List<String> nextPath = new ArrayList<String>(path);
                nextPath.add(transitionName);
                paths.addLast(nextPath);
            }
        }
    }

    return path;
}

From source file:org.apache.axis2.jaxws.util.WSDLExtensionUtils.java

/**
 * This method will search for all wsdl extensibility elements marked as required=true in wsdl:bindings
 * As per the wsdl 2.2 specification section 2.5 here is how a wsdl:binding is defined:
 * <wsdl:definitions .... >/*w  w w .j  av  a 2 s  . c  o m*/
 *      <wsdl:binding name="nmtoken" type="qname"> *
 *       <-- extensibility element (1) --> *
 *       <wsdl:operation name="nmtoken"> *
 *          <-- extensibility element (2) --> *
 *          <wsdl:input name="nmtoken"? > ?
 *              <-- extensibility element (3) --> 
 *          </wsdl:input>
 *          <wsdl:output name="nmtoken"? > ?
 *              <-- extensibility element (4) --> *
 *          </wsdl:output>
 *          <wsdl:fault name="nmtoken"> *
 *              <-- extensibility element (5) --> *
 *          </wsdl:fault>
 *       </wsdl:operation>
 *   </wsdl:binding>
 * </wsdl:definitions>
 * we will look for wsdl extensions in binding root, wsdl:operation, wsdl:input, wsdl:output and wsdl:fault.
 * If the extensibility element is defines outside of these sections it will not be picked up by this method.
 * 
 * @param wsdlBinding - WSDLBinding Object read from WSDL Definition.
 * @param set - Set that will be filled with list of required=true extension elements.
 * @return
 */
public static void search(WSDLElement element, Set<WSDLValidatorElement> set, List<QName> unusedExtensions) {
    if (log.isDebugEnabled()) {
        log.debug("Start Searching for WSDLExtensions");
    }
    if (element == null) {
        return;
    }
    //This search method uses a simple BFS technique to search for Extension elements in WSDLBindings.
    //I will Queue all available WSDLElements starting in wsdl:binding and traverse them looking for 
    //extensions. Queue will be empty when I have processed everything.
    //NOTE:Binding, Operation, OperationInput, OperationOutput and OperationFault are all WSDLElements.
    LinkedList<WSDLElement> queue = new LinkedList<WSDLElement>();
    queue.offer(element);

    while (!queue.isEmpty()) {
        WSDLElement wsdlElement = queue.remove();
        //WSDLElement in Queue could be wsdl Binding, BindingOperations, Input, Output or Fault
        //Find Extensibility Elements in wsdlElement.
        processWSDLElement(wsdlElement, set, unusedExtensions);
        //check if we are dealing with wsdlBinding;
        //store all BindingOpeations from wsdlBindings
        if (wsdlElement instanceof Binding) {
            //lets get all operations and add to queue
            //TODO: WSDLDef API's don't use generics, hence we use Iterator below and type cast.
            List operations = ((Binding) wsdlElement).getBindingOperations();
            Iterator iter = operations.iterator();
            while (iter.hasNext()) {
                BindingOperation op = (BindingOperation) iter.next();
                queue.offer(op);
            }
        }
        //check if we are dealing with Bindingoperations
        //Store all input, output and faults.
        if (wsdlElement instanceof BindingOperation) {
            BindingInput bi = ((BindingOperation) wsdlElement).getBindingInput();
            queue.offer(bi);
            BindingOutput bo = ((BindingOperation) wsdlElement).getBindingOutput();
            queue.offer(bo);
            Map map = ((BindingOperation) wsdlElement).getBindingFaults();
            Collection c = map.values();
            Iterator iter = c.iterator();
            while (iter.hasNext()) {
                Object o = iter.next();
                if (o instanceof BindingFault) {
                    BindingFault bf = (BindingFault) o;
                    queue.offer(bf);
                }
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("End Searching for WSDLExtensions");
    }
}

From source file:it.cnr.istc.iloc.gui.StateVariableVisualizer.java

private static String toString(Atom atom) {
    StringBuilder sb = new StringBuilder();
    sb.append(atom.type.name).append("(");
    LinkedList<Type> queue = new LinkedList<>();
    queue.add(atom.type);//w ww.  j  a  v a2  s. c  o m
    while (!queue.isEmpty()) {
        Type c_type = queue.pollFirst();
        queue.addAll(c_type.getSuperclasses());
        for (Field field : c_type.getFields()) {
            if (!field.synthetic && !field.name.equals(SCOPE)) {
                IItem item = atom.get(field.name);
                sb.append(", ").append(field.name);
                switch (field.type.name) {
                case BOOL:
                    sb.append(" = ").append(((IBoolItem) item).getBoolVar().evaluate());
                    break;
                case REAL:
                    sb.append(" = ").append(atom.core.evaluate(((IArithItem) item).getArithVar()));
                    break;
                case STRING:
                    sb.append(" = ").append(((IStringItem) item).getValue());
                    break;
                }
            }
        }
    }
    sb.append(")");
    return sb.toString().replace("(, ", "(");
}

From source file:Main.java

public static int deepHashCode(Object obj) {
    Set visited = new HashSet();
    LinkedList<Object> stack = new LinkedList<Object>();
    stack.addFirst(obj);/* w  ww.  j  a  va 2  s.c om*/
    int hash = 0;

    while (!stack.isEmpty()) {
        obj = stack.removeFirst();
        if (obj == null || visited.contains(obj)) {
            continue;
        }

        visited.add(obj);

        if (obj.getClass().isArray()) {
            int len = Array.getLength(obj);
            for (int i = 0; i < len; i++) {
                stack.addFirst(Array.get(obj, i));
            }
            continue;
        }

        if (obj instanceof Collection) {
            stack.addAll(0, (Collection) obj);
            continue;
        }

        if (obj instanceof Map) {
            stack.addAll(0, ((Map) obj).keySet());
            stack.addAll(0, ((Map) obj).values());
            continue;
        }

        if (hasCustomHashCode(obj.getClass())) {
            hash += obj.hashCode();
            continue;
        }

        Collection<Field> fields = getDeepDeclaredFields(obj.getClass());
        for (Field field : fields) {
            try {
                stack.addFirst(field.get(obj));
            } catch (Exception ignored) {
            }
        }
    }
    return hash;
}