非确定性有限自动机的HashMap错误(containsKey(字符串)不兼容?(HashMap error for Nondeterministic finite automata (contain

编程入门 行业动态 更新时间:2024-10-28 06:22:44
非确定性有限自动机的HashMap错误(containsKey(字符串)不兼容?(HashMap error for Nondeterministic finite automata (containsKey(string) incompatible?)

我在大学任务中偶然发现了一些编译错误。 经过一段时间的尝试修复它,我真的找不到解决方案来纠正它们。

以下是实现非确定性有限自动机的程序的构造函数。 在这种情况下,我正在使用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>

I stumbled across some compiler-errors for my university assignment. After some time of trying to fix it, I don't really find a solution to correct them.

The following is the constructor for a program that implements a Nondeterministic Finite Automata. I am working with Hashsets and Hashmaps in this case.

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]); } } }

the function call is in my readIn method which pulls the construction data for the NFA from a file.

result = new NFA(states, transitions, start, end);

The compiler-errors javac announces are the following:

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>

Furthermore, I get an error from the eclipse-ide:

The method containsKey(String) is undefined for the type Set<String>

最满意答案

您需要对集合使用contains(String value) 。 在Set<T> ,没有键值关系

You need to use contains(String value) for sets. In a Set<T>, there is no key-value relation.

更多推荐

本文发布于:2023-04-27 16:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327340.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动机   确定性   字符串   不兼容   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!