[英]Optimize the code to get blackboard user or course by its unique run id
I am fetching a course object by its course run id. 我正在通过其课程运行ID获取课程对象。 Below is my code that works perfectly ok. 下面是我的代码,可以正常运行。
public static CourseVO getBlackboardCourseObjectByCourseRunID(String RunID){
CourseVO[] courseVOList = null;
try {
courseVOList = BlackboardCoursesDAO.getAllBlackBoardCourse();
} catch (RemoteException e) {
// TODO Auto-generated catch block
throw new RuntimeException("Not able to fetch blackboard courses");
}
CourseVO courseVO = new CourseVO();
int length=courseVOList.length;
System.out.println("length : "+length);
int i=0;
courseVO = courseVOList[i];
while(!courseVO.getId().equals(RunID) && i<length){
courseVO = courseVOList[i];
//System.out.println("in while loop ");
i++;
}
return courseVO;
}
But it troubles when I try to fetch this object in a loop. 但是,当我尝试以循环方式获取此对象时会遇到麻烦。 If anyone can provide some better code, it will be great help. 如果有人可以提供更好的代码,那将是很大的帮助。
Thanks. 谢谢。
After line 8, you can try to change lines with this> 在第8行之后,您可以尝试使用此>更改行
Stream<CourseVO> courseList = Arrays.stream(courseVOList);
CourseVO foundCourse = courseList.filter(s -> s.getId().equals(RunID) )
.findFirst().get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.