java - 非确定性有限自动机(containsKey(string)不兼容的HashMap错误?

标签 java compiler-errors

我偶然发现了一些关于大学作业的编译器错误。经过一段时间的尝试修复后,我真的没有找到纠正它们的解决方案。

以下是实现非确定性有限自动机的程序的构造函数。在这种情况下,我正在使用Hashsets和Hashmaps。

public NFA(Set<String> states, Set<String[]> transitions, String start, Set<String> end) {
    this.start = start;
    this.end = end;
    this.active = this.start;
    Map<String, String> x = new HashMap<String, String>(); //create placeholder map

    //Insert states into map
    for (String s: states) {
        this.states.put(s, x); //Placeholder map used for this line  
    }

    //Assign transitions to corresponding states.
    for (String[] t: transitions) {
        //this line throws the error.
        if (!states.containsKey(t[0]) || !states.containsKey(t[2])) {
            throw new IllegalArgumentException("Transition Data Corrupted!");
        } else {
            this.states.get(t[0]).put(t[1], t[2]);
        }
    }
}

函数调用在我的readIn方法中,该方法从文件中提取NFA的构造数据。
result = new NFA(states, transitions, start, end);

javac宣布的编译器错误如下:

NFA.java:27: error: cannot find symbol
            if (!states.containsKey(t[0]) || !states.containsKey(t[2])) {
                       ^
  symbol:   method containsKey(String)
  location: variable states of type Set<String>

NFA.java:27: error: cannot find symbol
            if (!states.containsKey(t[0]) || !states.containsKey(t[2])) {
                                                    ^
  symbol:   method containsKey(String)
  location: variable states of type Set<String>


此外,我从eclipse-ide中得到一个错误:
The method containsKey(String) is undefined for the type Set<String>

最佳答案

您需要使用contains(String value)进行设置。在Set<T>中,没有键值关系。

关于java - 非确定性有限自动机(containsKey(string)不兼容的HashMap错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24355660/

相关文章:

c# - IntPtr.operator +(IntPtr,int)无法调用运算符或访问器

c++ - 为什么编译不会失败?

c# - 缺少装配引用

java - 如何测试 JavaFX (MVC) Controller 逻辑?

java - 为 SELECT 语句使用 JPA 值得吗?

Java 编译错误 : Method reference in combination with overloading

groovy - 使用poi.jar作为数据接收器脚本时出现Groovy编译错误

java - 如何查找hashmap中是否有空键?

Java 默认字符串哈希函数在单个字符串上产生冲突

java - java.lang.String 中存在的 contains() 方法在某些情况下无法正常运行,有人可以解释一下这种行为吗