Example usage for com.google.common.collect Queues newArrayDeque

List of usage examples for com.google.common.collect Queues newArrayDeque

Introduction

In this page you can find the example usage for com.google.common.collect Queues newArrayDeque.

Prototype

public static <E> ArrayDeque<E> newArrayDeque() 

Source Link

Document

Creates an empty ArrayDeque .

Usage

From source file:org.apache.drill.exec.store.mapr.db.util.FieldPathHelper.java

/**
 * Returns {@link FieldPath} equivalent of the specified {@link SchemaPath}.
 *
 * @param schemaPath {@link SchemaPath} instance that should be converted
 * @return {@link FieldPath} equivalent of the specified {@link SchemaPath}.
 *///from  w w  w. jav a2  s.co  m
public static FieldPath schemaPathToFieldPath(SchemaPath schemaPath) {
    Deque<PathSegment> pathSegments = Queues.newArrayDeque();
    PathSegment pathSegment = schemaPath.getRootSegment();
    while (pathSegment != null) {
        pathSegments.push(pathSegment);
        pathSegment = pathSegment.getChild();
    }

    FieldSegment child = null;
    while (!pathSegments.isEmpty()) {
        pathSegment = pathSegments.pop();
        if (pathSegment.isNamed()) {
            child = new FieldSegment.NameSegment(((PathSegment.NameSegment) pathSegment).getPath(), child,
                    false);
        } else {
            child = new FieldSegment.IndexSegment(
                    String.valueOf(((PathSegment.ArraySegment) pathSegment).getIndex()), child);
        }
    }
    return new FieldPath((FieldSegment.NameSegment) child);
}

From source file:co.cask.common.DirUtils.java

/**
 * Wipes out all the a directory starting from a given directory.
 * @param directory to be cleaned//from ww  w.j  av a  2  s  .co  m
 * @throws java.io.IOException
 */
public static void deleteDirectoryContents(File directory) throws IOException {
    Preconditions.checkArgument(directory.isDirectory(), "Not a directory: %s", directory);
    Deque<File> stack = Queues.newArrayDeque();
    stack.add(directory);

    while (!stack.isEmpty()) {
        File file = stack.peekLast();
        File[] files = file.listFiles();
        if (files == null || files.length == 0) {
            file.delete();
            stack.pollLast();
        } else {
            Collections.addAll(stack, files);
        }
    }
}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.Resolver.java

public static void preresolve(ResolutionBase base) {
    Queue<ResolutionBase> toResolve = Queues.newArrayDeque();
    toResolve.add(base);//  w w w .j  a v  a  2  s  .  c o m
    while (!toResolve.isEmpty()) {
        toResolve.addAll(preresolveBase(toResolve.remove()));
    }
}

From source file:cuchaz.enigma.mapping.MappingsReader.java

public Mappings read(BufferedReader in) throws IOException, MappingParseException {
    Mappings mappings = new Mappings();
    Deque<Object> mappingStack = Queues.newArrayDeque();

    int lineNumber = 0;
    String line = null;/* ww w.  j  av a  2s  .c o  m*/
    while ((line = in.readLine()) != null) {
        lineNumber++;

        // strip comments
        int commentPos = line.indexOf('#');
        if (commentPos >= 0) {
            line = line.substring(0, commentPos);
        }

        // skip blank lines
        if (line.trim().length() <= 0) {
            continue;
        }

        // get the indent of this line
        int indent = 0;
        for (int i = 0; i < line.length(); i++) {
            if (line.charAt(i) != '\t') {
                break;
            }
            indent++;
        }

        // handle stack pops
        while (indent < mappingStack.size()) {
            mappingStack.pop();
        }

        String[] parts = line.trim().split("\\s");
        try {
            // read the first token
            String token = parts[0];

            if (token.equalsIgnoreCase("CLASS")) {
                ClassMapping classMapping;
                if (indent <= 0) {
                    // outer class
                    classMapping = readClass(parts, false);
                    mappings.addClassMapping(classMapping);
                } else {

                    // inner class
                    if (!(mappingStack.peek() instanceof ClassMapping)) {
                        throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!");
                    }

                    classMapping = readClass(parts, true);
                    ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping);
                }
                mappingStack.push(classMapping);
            } else if (token.equalsIgnoreCase("FIELD")) {
                if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
                    throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!");
                }
                ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts));
            } else if (token.equalsIgnoreCase("METHOD")) {
                if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
                    throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!");
                }
                MethodMapping methodMapping = readMethod(parts);
                ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping);
                mappingStack.push(methodMapping);
            } else if (token.equalsIgnoreCase("ARG")) {
                if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) {
                    throw new MappingParseException(lineNumber, "Unexpected ARG entry here!");
                }
                ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts));
            }
        } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) {
            throw new MappingParseException(lineNumber, "Malformed line:\n" + line);
        }
    }

    return mappings;
}

From source file:org.terasology.input.lwjgl.LwjglKeyboardDevice.java

@Override
public Queue<InputAction> getInputQueue() {
    Queue<InputAction> result = Queues.newArrayDeque();

    while (Keyboard.next()) {
        ButtonState state;/*from   w  w w. j  a v  a2  s  . c o m*/
        if (Keyboard.isRepeatEvent()) {
            state = ButtonState.REPEAT;
        } else {
            state = (Keyboard.getEventKeyState()) ? ButtonState.DOWN : ButtonState.UP;
        }
        result.add(new InputAction(InputType.KEY.getInput(Keyboard.getEventKey()), state,
                Keyboard.getEventCharacter()));
    }

    return result;
}

From source file:org.terasology.input.device.nulldevices.NullMouseDevice.java

@Override
public Queue<InputAction> getInputQueue() {
    return Queues.newArrayDeque();
}

From source file:com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap.java

private static ImmutableCollection<TargetKey> getTransitiveDependencies(TargetKey targetKey,
        TargetMap targetMap) {/*from   w  w w. j  a v a 2  s.c o m*/
    Queue<TargetKey> targetsToVisit = Queues.newArrayDeque();
    Set<TargetKey> transitiveDependencies = Sets.newHashSet();
    targetsToVisit.add(targetKey);
    while (!targetsToVisit.isEmpty()) {
        TargetIdeInfo currentTarget = targetMap.get(targetsToVisit.remove());
        if (currentTarget == null) {
            continue;
        }
        List<TargetKey> newDependencies = currentTarget.dependencies.stream()
                .map(d -> TargetKey.forPlainTarget(d.targetKey.label))
                // Get rid of the ones we've already seen.
                .filter(r -> !transitiveDependencies.contains(r)).collect(Collectors.toList());
        targetsToVisit.addAll(newDependencies);
        transitiveDependencies.addAll(newDependencies);
    }
    return ImmutableSet.copyOf(transitiveDependencies);
}

From source file:org.terasology.input.lwjgl.LwjglMouseDevice.java

@Override
public Queue<InputAction> getInputQueue() {
    Queue<InputAction> result = Queues.newArrayDeque();

    while (Mouse.next()) {
        if (Mouse.getEventButton() != -1) {
            ButtonState state = (Mouse.getEventButtonState()) ? ButtonState.DOWN : ButtonState.UP;
            result.add(new InputAction(InputType.MOUSE_BUTTON.getInput(Mouse.getEventButton()), state,
                    getPosition()));//www  . j  av  a 2s.  co  m
        }
        if (Mouse.getEventDWheel() != 0) {
            int id = (Mouse.getEventDWheel() > 0) ? 1 : -1;
            result.add(new InputAction(InputType.MOUSE_WHEEL.getInput(id), id * Mouse.getEventDWheel() / 120,
                    getPosition()));
        }
    }

    return result;
}

From source file:cuchaz.enigma.mapping.io.reader.MappingsLegacyReader.java

@Override
public Mappings read(BufferedReader in) throws IOException, MappingParseException {
    Mappings mappings = new Mappings();
    Deque<Object> mappingStack = Queues.newArrayDeque();

    int lineNumber = 0;
    String line = null;/*from www. j  a va2 s. c  o m*/
    while ((line = in.readLine()) != null) {
        lineNumber++;

        // strip comments
        int commentPos = line.indexOf('#');
        if (commentPos >= 0) {
            line = line.substring(0, commentPos);
        }

        // skip blank lines
        if (line.trim().length() <= 0) {
            continue;
        }

        // get the indent of this line
        int indent = 0;
        for (int i = 0; i < line.length(); i++) {
            if (line.charAt(i) != '\t') {
                break;
            }
            indent++;
        }

        // handle stack pops
        while (indent < mappingStack.size()) {
            mappingStack.pop();
        }

        String[] parts = line.trim().split("\\s");
        try {
            // read the first token
            String token = parts[0];

            if (token.equalsIgnoreCase("CLASS")) {
                ClassMapping classMapping;
                if (indent <= 0) {
                    // outer class
                    classMapping = readClass(parts, false);
                    mappings.addClassMapping(classMapping);
                } else {

                    // inner class
                    if (!(mappingStack.peek() instanceof ClassMapping)) {
                        throw new MappingParseException(lineNumber, "Unexpected CLASS entry here!");
                    }

                    classMapping = readClass(parts, true);
                    ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping);
                }
                mappingStack.push(classMapping);
            } else if (token.equalsIgnoreCase("FIELD")) {
                if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
                    throw new MappingParseException(lineNumber, "Unexpected FIELD entry here!");
                }
                ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts));
            } else if (token.equalsIgnoreCase("METHOD")) {
                if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) {
                    throw new MappingParseException(lineNumber, "Unexpected METHOD entry here!");
                }
                MethodMapping methodMapping = readMethod(parts);
                ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping);
                mappingStack.push(methodMapping);
            } else if (token.equalsIgnoreCase("ARG")) {
                if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) {
                    throw new MappingParseException(lineNumber, "Unexpected ARG entry here!");
                }
                ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts));
            }
        } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) {
            throw new MappingParseException(lineNumber, "Malformed line:\n" + line);
        }
    }

    return mappings;
}

From source file:core.FollowedByAgent.java

public FollowedByAgent(String info, String IDinputTerminalL, String IDinputTerminalR, String IDoutputTerminal) {
    super();/*from   w ww.j a  v a 2 s  . c  o  m*/
    this.setName(this.getName() + "@" + Relayer.getInstance().getAddress().toString());
    this._info = info;
    this._type = "FollowedBy";
    this._receivers[0] = new TopicReceiver();
    this._receivers[1] = new TopicReceiver();
    inputTerminalL = new IOTerminal(IDinputTerminalL, "input channel " + _type, _receivers[0], this);
    inputTerminalR = new IOTerminal(IDinputTerminalR, "input channel " + _type, _receivers[1], this);
    outputTerminal = new IOTerminal(IDoutputTerminal, "output channel " + _type, this);
    _outputNotifier = new OQNotifier(this, QoSTuner.NOTIFICATION_PRIORITY);
    Queue<EventBean> selectedL = Queues.newArrayDeque();
    _selectedEvents[0] = selectedL;
    Queue<EventBean> selectedR = Queues.newArrayDeque();
    _selectedEvents[1] = selectedR;
    logger = new MyLogger("FollowedByMeasures", FollowedByAgent.class.getName());
    logger.log("Operator, isProduced, Processing Time, InputQ Size, OutputQ Size ");
}