0

I am fetching a course object by its course run 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.

Neha
  • 143
  • 4
  • 19
  • instead of getting all BlackBoard course, why not get unique BlackBoard course with RunId. Something like this >> courseVO = blackboardCoursesDAO.getBlackBoardCourseById(runId); – erolkaya84 May 25 '16 at 12:48
  • There is no such blackboard API to get course by its run id. It is possible for courseId which is another field in Course object. So, I have made my custom function. – Neha May 25 '16 at 12:54

1 Answers1

0

After line 8, you can try to change lines with this>

Stream<CourseVO> courseList = Arrays.stream(courseVOList);

CourseVO foundCourse = courseList.filter(s -> s.getId().equals(RunID) )
  .findFirst().get();
erolkaya84
  • 1,769
  • 21
  • 28
  • It wont be much helpful as it will go inside the loop and then compare each with its run id and then return object. I was wondering if there is any filter in the API to fetch blackboard course data as it is for courseId field that I am not familiar with. – Neha May 25 '16 at 13:22
  • what you need is stream.filter(). I will update my answer. – erolkaya84 May 25 '16 at 13:45