// FIXME this should be stored in Couch // along with first access to the task public static Version resolveVersion( final Task task, final int anchor, final int step, final Collection<String> studentIds, final String studentId ) { final List<Version> versionsEff = filterPrivateVersions(task); final ArrayList<String> studIds = new ArrayList<String>(studentIds); Collections.sort(studIds); final int studIdx = studIds.indexOf(studentId); final int vSize = versionsEff.size(); final int verIdx = (anchor + (vSize + step) * studIdx) % vSize; return versionsEff.get(verIdx); }
public static List<Version> filterPrivateVersions(Task task) { if (task.getVersions().isEmpty()) { throw new IllegalStateException( "task has no versions: " + task.getId() ); } final List<Version> versions = new ArrayList<Version>( task.getVersions().values() ); final List<Version> versionsPriv = new ArrayList<Version>( versions ); for ( Iterator<Version> verIt = versionsPriv.iterator(); verIt.hasNext(); ) { if (verIt.next().isShared()) { verIt.remove(); } } return versionsPriv.isEmpty() ? versions : versionsPriv; }