在我的Html模拟器程序上出错?

时间:2016-02-20 17:46:29

标签: java html stack queue simulator

我收到此错误:

The method get(int) is undefined for the type Queue<HtmlTag> on line 57

以下是该计划:

有没有人知道该怎么做,因为我完全迷失了,这是我需要做的最后一件事来完成我的代码

任何帮助将不胜感激!

package HTML;

import java.util.LinkedList;
import java.util.Stack;
import java.util.Queue;

public class HtmlValidator {
    private Queue<HtmlTag> list = new LinkedList<HtmlTag> ();

    public HtmlValidator() {
        Queue<HtmlTag> list = new LinkedList<HtmlTag> ();
    }

    public HtmlValidator(Queue<HtmlTag> tags) {
        Queue<HtmlTag> list = new LinkedList<HtmlTag> (tags);
        if (tags == null) {
            throw new IllegalArgumentException(" Invalid ");
        }
    }

    public void addTag(HtmlTag tag) {
        if (tag == null) {
            throw new IllegalArgumentException(" Invalid ");
        }
        list.add(tag);
    }

    public Queue<HtmlTag> getTags() {
        return list;
    }

    public void removeAll(String element) {
        int i;
        for (i = 0; i <= list.size(); i++) {
            list.get(i).getElement().equals(element);
            list.remove(i);
            if (element == null) {
                throw new IllegalArgumentException(" Invalid ");
            }
        }
    }

    public void validate() {
        int indent = 0;
        Stack<HtmlTag> t = new Stack<HtmlTag> ();
        HtmlTag currentTag = null;

        for (int i = 0; i < list.size(); i++) {
            currentTag = list.remove();
            list.add(currentTag);

            if (currentTag.isSelfClosing()) {
                indents(indent);
                System.out.println(currentTag);
            } else {
                System.out.println("Error: Unexpected tag: " + currentTag);
            }

            if (currentTag.isOpenTag()) {
                t.push(currentTag);
                indents(indent);
                System.out.println(currentTag);
                indent++;
            } else {
                indent--;
                indents(indent);
                System.out.println(currentTag);
                t.pop();
            }
        }

        while (!t.isEmpty()) {
            System.out.println("Error unclosed tag: " + t.pop());
        }
    }

    private void indents(int space) {
        for (int i = 0; i < space; i++) {
            System.out.println("    ");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

java.util.Queue接口没有定义方法get(int)。如果您想要具有此类访问权限的集合,则应使用java.util.List。

观察您的删除代码可能根本不起作用 - 您应该使用Iterator或更改代码以使用java8 Streams。