temp.equals("J")
时间: 2023-11-05 16:45:05 浏览: 34
As an AI language model, I cannot determine the context of this statement. It seems to be a comparison of the value of the variable "temp" with the string "J". The result of this comparison would be a boolean value (either true or false) depending on whether the two values are equal or not.
相关问题
private HashMap<String,Vector<String>> graphs =new HashMap<String,Vector<String>>(); public Graphs() { } public Graphs(HashMap<String, Vector<String>> graphs) { this.graphs = graphs; } public void creatGraphs(Vector<String> userTemp/* allusers */, Vector<String> linksTemp/* links */) { for(int i=0;i<userTemp.size();i++) { Vector<String> vecLinksTemp=new Vector<String>();//创建当前user能够激活的links容器 for(int j=0;j<linksTemp.size();j++) { if(((String)linksTemp.get(j)).split(" ")[0].equals(userTemp.get(i)))//判断与user的匹配的links vecLinksTemp.add(((String)linksTemp.get(j))); } graphs.put((String)userTemp.get(i),vecLinksTemp); } } public void setGraphs(HashMap<String, Vector<String>> graphs) { this.graphs = graphs; } public HashMap<String, Vector<String>> getGraphs() { return graphs; }
这段 Java 代码定义了一个名为 Graphs 的类,其中包含了一个名为 graphs 的 HashMap 成员变量,用于存储字符串和字符串向量之间的映射关系。
该类有三个方法:
1. 无参构造方法 public Graphs()。
2. 有参构造方法 public Graphs(HashMap<String, Vector<String>> graphs),用于初始化 graphs 成员变量。
3. public void creatGraphs(Vector<String> userTemp, Vector<String> linksTemp),用于创建图形对象,并将其添加到 HashMap 中。该方法通过遍历 userTemp 和 linksTemp 两个向量,根据给定的条件,将 linksTemp 中的元素添加到 vecLinksTemp 中,最后将 vecLinksTemp 添加到 graphs 中。
该类还有两个访问器方法:
1. public void setGraphs(HashMap<String, Vector<String>> graphs),用于设置 graphs 成员变量的值。
2. public HashMap<String, Vector<String>> getGraphs(),用于获取 graphs 成员变量的值。
总之,这段代码实现了一个简单的图形数据结构,并提供了一些基本的操作方法。
把下面这段js代码转换为java代码 function getMatchList(peopleList,round_num) { while ((peopleList.length*round_num)%4!=0) { round_num++; } let matchListPoor = getTempMatchList(peopleList,round_num); let all_round = matchListPoor.length/2; let res = []; let rivalry = []; let round = 0; while (matchListPoor.length>0) { let per = matchListPoor[0]; matchListPoor.splice(0,1); if(rivalry.length==0){ rivalry.push(per); round = 1; }else if(!rivalry[0].includes(per[0])&&!rivalry[0].includes(per[1])){ rivalry.push(per); }else{ matchListPoor.push(per); round = 2; } if(rivalry.length==2){ res.push(rivalry); rivalry = []; } if(matchListPoor.length==1&&round == 2){ matchListPoor = [...matchListPoor,...rivalry]; for (let j = 0; j < res.length; j++) { if(!res[j][0].includes(matchListPoor[0][0])&&!res[j][0].includes(matchListPoor[0][1])){ let temp = res[j][1]; res[j][1] = matchListPoor[0]; matchListPoor[0] = temp; if(!matchListPoor[0].includes(matchListPoor[1][0])&&!matchListPoor[0].includes(matchListPoor[1][1])){ res.push(matchListPoor); break; } } } } if(res.length==all_round){ break; } } return res; }
下面是将给定的 JavaScript 代码翻译成 Java 代码的示例:
```
public static List<List<String[]>> getMatchList(List<String[]> peopleList, int round_num) {
while ((peopleList.size() * round_num) % 4 != 0) {
round_num++;
}
List<String[][]> matchListPoor = getTempMatchList(peopleList, round_num);
int all_round = matchListPoor.size() / 2;
List<List<String[]>> res = new ArrayList<>();
List<String[][]> rivalry = new ArrayList<>();
int round = 0;
while (matchListPoor.size() > 0) {
String[][] per = matchListPoor.get(0);
matchListPoor.remove(0);
if (rivalry.size() == 0) {
rivalry.add(per);
round = 1;
} else if (!contains(rivalry.get(0), per[0]) && !contains(rivalry.get(0), per[1])) {
rivalry.add(per);
} else {
matchListPoor.add(per);
round = 2;
}
if (rivalry.size() == 2) {
res.add(Arrays.asList(rivalry.get(0), rivalry.get(1)));
rivalry.clear();
}
if (matchListPoor.size() == 1 && round == 2) {
matchListPoor.addAll(rivalry);
for (int j = 0; j < res.size(); j++) {
if (!contains(res.get(j).get(0), matchListPoor.get(0)[0])
&& !contains(res.get(j).get(0), matchListPoor.get(0)[1])) {
String[][] temp = res.get(j).get(1);
res.get(j).set(1, matchListPoor.get(0));
matchListPoor.set(0, temp);
if (!contains(matchListPoor.get(0), matchListPoor.get(1)[0])
&& !contains(matchListPoor.get(0), matchListPoor.get(1)[1])) {
res.add(Arrays.asList(matchListPoor.get(0), matchListPoor.get(1)));
break;
}
}
}
}
if (res.size() == all_round) {
break;
}
}
return res;
}
private static boolean contains(String[][] arr, String str) {
return Arrays.stream(arr).flatMap(Arrays::stream).anyMatch(s -> s.equals(str));
}
private static List<String[][]> getTempMatchList(List<String[]> peopleList, int round_num) {
List<String[][]> tempMatchList = new ArrayList<>();
for (int i = 0; i < round_num; i++) {
String[][] matchList = new String[peopleList.size() / 2][2];
for (int j = 0; j < peopleList.size() / 2; j++) {
matchList[j] = new String[]{peopleList.get(j)[0], peopleList.get(peopleList.size() - 1 - j)[0]};
}
peopleList.remove(0);
peopleList.remove(peopleList.size() - 1);
tempMatchList.add(matchList);
}
return tempMatchList;
}
```
需要注意的是,Java 中没有类似 JavaScript 中的 `splice()` 方法,因此需要使用 `remove()` 方法和 `addAll()` 方法代替。另外,在 Java 中,数组不能直接作为列表的元素,因此需要使用二维字符串数组 `String[][]` 代替。