List of usage examples for java.util HashSet containsAll
boolean containsAll(Collection<?> c);
From source file:org.zaproxy.zap.extension.multiFuzz.CharTypes.java
public HashSet<String> traversStep(int cutoff) { int limit = cutoff; HashSet<String> valid = new HashSet<>(); HashMap<String, HashSet<State>> newTravers = new HashMap<>(); for (String hist : travers.keySet()) { for (State s : travers.get(hist)) { for (Character c : s.out.keySet()) { String key = hist + c; HashSet<State> possOld = new HashSet<>(); HashSet<State> poss = s.out.get(c); while (!possOld.containsAll(poss)) { possOld.addAll(poss); for (State p : possOld) { poss.addAll(p.empty); }// ww w . ja v a2 s. c o m } if (newTravers.containsKey(key)) { newTravers.get(key).addAll(poss); } else { newTravers.put(key, poss); } if (poss.contains(states.get(end))) { valid.add(key); if (limit-- <= 0) { this.travers = newTravers; return valid; } } } } } this.travers = newTravers; return valid; }
From source file:module.signature.util.XAdESValidator.java
private static void validateSigner(Document document, Set<User> usersPermitted, Set<User> usersExcluded, boolean allUsersPermittedShouldBeThere) throws SignatureDataException { if (!allUsersPermittedShouldBeThere || ((usersExcluded != null) && !usersExcluded.isEmpty())) { //TODO implement it when needed throw new DomainException("method.not.yet.implemented"); }/*from w w w . j a v a 2 s . co m*/ final String ID_NR_PREFIX = "OID.2.5.4.5=BI"; ArrayList<String> usersPermittedIdNumbers = new ArrayList<String>(); for (User user : usersPermitted) { usersPermittedIdNumbers.add(user.getPerson().getRemotePerson().getDocumentIdNumber()); } //let's extract each signature // XMLDSIG NodeList nlSignature = document.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature"); //DEBUG System.out.println("Got " + nlSignature.getLength() + " signatures"); if (nlSignature.getLength() < 1) { throw new SignatureException("could.not.find.a.signature.in.incoming.data", true, null); } HashSet<String> usersFoundIdNumbers = new HashSet<String>(); for (int i = 0; i < nlSignature.getLength(); i++) { //for each signature, let's extract the ID number of who did it Element signature = (Element) nlSignature.item(i); try { XMLSignature xmlSig = new XMLSignature(signature, null); KeyInfo ki = xmlSig.getKeyInfo(); String certificateIDNr = ki.getX509Certificate().getSubjectX500Principal().getName("RFC1779"); certificateIDNr = certificateIDNr .substring(certificateIDNr.indexOf(ID_NR_PREFIX) + ID_NR_PREFIX.length()); //let's take out the virgul and the last character, which is a control one certificateIDNr = certificateIDNr.substring(0, certificateIDNr.indexOf(',') - 1); usersFoundIdNumbers.add(certificateIDNr); } catch (XMLSignatureException e) { e.printStackTrace(); throw new SignatureDataException("signature.error.XMLSignatureExceptionError", e); } catch (XMLSecurityException e) { throw new SignatureDataException("signature.error.XMLSecurityException", e); } } //now let's validate the extracted info if (allUsersPermittedShouldBeThere && usersFoundIdNumbers.containsAll(usersPermittedIdNumbers)) { return; //TODO TODO URGENT uncomment the next two lines (just made possible to be able to test it!!) } else { throw new SignatureDataException("wrong.document.signer"); } //TODO the rest of the use cases aren't implemented ATM }
From source file:amie.keys.CSAKey.java
public boolean containsSubSet(HashSet<Integer> allPropertiesSet) { boolean contains = false; if (nonKeysInt.contains(allPropertiesSet)) { return true; }//from www . j a v a 2 s . co m for (HashSet<Integer> nonKeyInt : nonKeysInt) { // System.out.println("nonKeyInt:"+nonKeyInt); if (nonKeyInt.containsAll(allPropertiesSet)) { //|| nonKeyInt.equals(allPropertiesSet)) { return true; } } return contains; }
From source file:org.jactr.core.runtime.controller.OldController.java
final public void waitForStart() throws InterruptedException { try {/*w w w . j a v a2s .c o m*/ _lock.lock(); /* * this is a tad complicated since a model might terminate before wait for * Start is even called.. */ HashSet<IModel> runningOrTerminated = new HashSet<IModel>(_runningModels); runningOrTerminated.addAll(_terminatedModels); while (!runningOrTerminated.containsAll(ACTRRuntime.getRuntime().getModels())) { _start.await(); // update the contents runningOrTerminated.addAll(_runningModels); runningOrTerminated.addAll(_terminatedModels); } } finally { _lock.unlock(); } }
From source file:org.fosstrak.ale.server.util.ECReportsHelper.java
/** * compares the content of two ECReports and decides on the content whether they equal or not. the * two reports must follow the same report spec. * @param reportSpec the report spec of the report. * @param newReport the newer report (or report1). * @param oldReport the older report (or report2). * @return true if equal by content, false otherwise. *//*from w w w .j a va 2 s. c o m*/ public boolean areReportsEqual(ECReportSpec reportSpec, ECReport newReport, ECReport oldReport) { boolean equality = false; Map<String, ECReportGroup> newGroupByName = new HashMap<String, ECReportGroup>(); Map<String, ECReportGroup> oldGroupByName = new HashMap<String, ECReportGroup>(); // compare the tags... if (null != oldReport) { List<ECReportGroup> oldGroup = oldReport.getGroup(); List<ECReportGroup> newGroup = newReport.getGroup(); if (oldGroup.size() == newGroup.size()) { // equal amount of groups, so need to compare the groups... for (ECReportGroup g : oldGroup) oldGroupByName.put(g.getGroupName(), g); for (ECReportGroup g : newGroup) newGroupByName.put(g.getGroupName(), g); for (String gName : oldGroupByName.keySet()) { ECReportGroup og = oldGroupByName.get(gName); ECReportGroup ng = newGroupByName.get(gName); // now compare the two groups... if ((null != og.getGroupList()) && (null != ng.getGroupList())) { // need to check boolean useEPC = reportSpec.getOutput().isIncludeEPC(); boolean useTag = reportSpec.getOutput().isIncludeTag(); boolean useHex = reportSpec.getOutput().isIncludeRawHex(); HashSet<String> hs = new HashSet<String>(); HashSet<String> hs2 = new HashSet<String>(); for (ECReportGroupListMember oMember : og.getGroupList().getMember()) { boolean epcAdded = false; // compare according the epc field if (useEPC) epcAdded = addEPC(hs, oMember.getEpc()); if (!epcAdded && useTag) epcAdded = addEPC(hs, oMember.getTag()); if (!epcAdded && useHex) epcAdded = addEPC(hs, oMember.getRawHex()); if (!epcAdded) epcAdded = addEPC(hs, oMember.getRawDecimal()); } for (ECReportGroupListMember oMember : ng.getGroupList().getMember()) { boolean epcAdded = false; // compare according the epc field if (useEPC) epcAdded = addEPC(hs2, oMember.getEpc()); if (!epcAdded && useTag) epcAdded = addEPC(hs2, oMember.getTag()); if (!epcAdded && useHex) epcAdded = addEPC(hs2, oMember.getRawHex()); if (!epcAdded) epcAdded = addEPC(hs2, oMember.getRawDecimal()); } // if intersection is not empty, the sets are not equal if (hs.containsAll(hs2) && hs2.containsAll(hs)) { // equal equality = true; } else { equality = false; break; } } else if ((null == og.getGroupList()) && (null == ng.getGroupList())) { // the groups are equal equality = true; } else { // not equal. equality = false; break; } } } } return equality; }
From source file:xc.mst.services.marcaggregation.MarcAggregationService.java
/** * * need to look to see if the given match set impacts existing sets. i.e if this set is {1,47,50} * and we have existing sets {1,3} and {4,47} then we need a superset: {1,3,4,47,50} and need to * remove the existing sets {1,3}, {4,47} * * disjoint-set data structure?// w w w .j av a2 s.c o m * * @param matchset * @param origMasMatchSetList * @return */ private List<HashSet<Long>> addToMatchSetList(HashSet<Long> matchset, final List<HashSet<Long>> origMasMatchSetList) { TimingLogger.start("addToMatchSetList"); if (matchset == null) { TimingLogger.stop("addToMatchSetList"); return origMasMatchSetList; } if (matchset.size() < 1) { ///TODO shouldn't this be <2 ? TimingLogger.stop("addToMatchSetList"); return origMasMatchSetList; } LOG.debug("** addToMatchSetList, matchset length=" + matchset.size() + " TOTAL matchset size =" + origMasMatchSetList.size()); List<HashSet<Long>> newMasMatchSetList = new ArrayList<HashSet<Long>>(); TimingLogger.start("addToMatchSetList.addAll()"); newMasMatchSetList.addAll(origMasMatchSetList); TimingLogger.stop("addToMatchSetList.addAll()"); TimingLogger.start("addToMatchSetList.set.processing"); boolean added = false; for (HashSet<Long> set : origMasMatchSetList) { for (Long number : matchset) { TimingLogger.start("addToMatchSetList.set.contains"); if (set.contains(number)) { TimingLogger.stop("addToMatchSetList.set.contains"); TimingLogger.start("addToMatchSetList.set.notcontainsall"); if (!set.containsAll(matchset)) { TimingLogger.stop("addToMatchSetList.set.notcontainsall"); TimingLogger.start("newMasMatchSetList.remove()"); newMasMatchSetList.remove(set); TimingLogger.stop("newMasMatchSetList.remove()"); TimingLogger.start("set.addAll()"); set.addAll(matchset); TimingLogger.stop("set.addAll()"); TimingLogger.start("newMasMatchSetList.add()"); newMasMatchSetList.add(set); TimingLogger.stop("newMasMatchSetList.add()"); LOG.debug("addToMatchSetList, post-merge! set.contains(" + number + ") merged newMasMatchSetList set=" + set); } else { TimingLogger.stop("addToMatchSetList.set.notcontainsall"); LOG.debug("addToMatchSetList, will not add in: " + matchset); } added = true; // this flag means that we don't want this set added to the big list below break; // get you out of THIS set, but still must check the others. } else { TimingLogger.stop("addToMatchSetList.set.contains"); } } } TimingLogger.stop("addToMatchSetList.set.processing"); // // the list of sets has to start somewhere, and if you don't find a set including some part // of your set, you must add your set explicitly. // if (!added) { LOG.debug("must add in: " + matchset); newMasMatchSetList.add(matchset); } LOG.debug("** addToMatchSetList, NEW TOTAL matchset size =" + newMasMatchSetList.size()); TimingLogger.stop("addToMatchSetList"); return newMasMatchSetList; }
From source file:org.voltdb.planner.ParsedSelectStmt.java
private boolean orderByColumnsDetermineAllColumns(ArrayList<ParsedColInfo> candidateColumns, ArrayList<AbstractExpression> outNonOrdered) { HashSet<AbstractExpression> orderByExprs = null; ArrayList<AbstractExpression> candidateExprHardCases = null; // First try to get away with a brute force N by M search for exact equalities. for (ParsedColInfo candidateCol : candidateColumns) { if (candidateCol.orderBy) { continue; }//from w ww . ja va 2s.com AbstractExpression candidateExpr = candidateCol.expression; if (orderByExprs == null) { orderByExprs = new HashSet<AbstractExpression>(); for (ParsedColInfo orderByCol : m_orderColumns) { orderByExprs.add(orderByCol.expression); } } if (orderByExprs.contains(candidateExpr)) { continue; } if (candidateExpr instanceof TupleValueExpression) { // Simple column references can only be exactly equal to but not "based on" an ORDER BY. return false; } if (candidateExprHardCases == null) { candidateExprHardCases = new ArrayList<AbstractExpression>(); } candidateExprHardCases.add(candidateExpr); } if (candidateExprHardCases == null) { return true; } // Plan B. profile the ORDER BY list and try to include/exclude the hard cases on that basis. HashSet<AbstractExpression> orderByTVEs = new HashSet<AbstractExpression>(); ArrayList<AbstractExpression> orderByNonTVEs = new ArrayList<AbstractExpression>(); ArrayList<List<AbstractExpression>> orderByNonTVEBaseTVEs = new ArrayList<List<AbstractExpression>>(); HashSet<AbstractExpression> orderByAllBaseTVEs = new HashSet<AbstractExpression>(); for (AbstractExpression orderByExpr : orderByExprs) { if (orderByExpr instanceof TupleValueExpression) { orderByTVEs.add(orderByExpr); orderByAllBaseTVEs.add(orderByExpr); } else { orderByNonTVEs.add(orderByExpr); List<AbstractExpression> baseTVEs = orderByExpr.findBaseTVEs(); orderByNonTVEBaseTVEs.add(baseTVEs); orderByAllBaseTVEs.addAll(baseTVEs); } } boolean result = true; for (AbstractExpression candidateExpr : candidateExprHardCases) { Collection<AbstractExpression> candidateBases = candidateExpr.findBaseTVEs(); if (orderByTVEs.containsAll(candidateBases)) { continue; } if (orderByAllBaseTVEs.containsAll(candidateBases) == false) { if (outNonOrdered == null) { // Short-circuit if the remaining non-qualifying expressions are not of interest. return false; } result = false; outNonOrdered.add(candidateExpr); continue; } // At this point, if the candidateExpr is a match, // then it is based on but not equal to one or more orderByNonTVE(s) and optionally orderByTVE(s). // The simplest example is like "SELECT a+(b-c) ... ORDER BY a, b-c;" // If it is a non-match, it is an original expression based on orderByAllBaseTVEs // The simplest example is like "SELECT a+b ... ORDER BY a, b-c;" // TODO: process REALLY HARD CASES // TODO: issue a warning, short-term? // For now, err on the side of non-determinism. if (outNonOrdered == null) { // Short-circuit if the remaining non-qualifying expressions are not of interest. return false; } outNonOrdered.add(candidateExpr); result = false; } return result; }
From source file:org.unitime.timetable.test.UpdateExamConflicts.java
public void updateConflicts(ExamAssignmentInfo assignment, org.hibernate.Session hibSession) throws Exception { Transaction tx = null;//from www . j a v a 2 s. c om try { if (hibSession.getTransaction() == null || !hibSession.getTransaction().isActive()) tx = hibSession.beginTransaction(); Exam exam = assignment.getExam(hibSession); HashSet<Exam> otherExams = new HashSet(); HashSet<ExamConflict> conflicts = new HashSet(exam.getConflicts()); for (DirectConflict dc : assignment.getDirectConflicts()) { if (dc.getOtherExam() == null) continue; ExamConflict conf = null; for (ExamConflict c : conflicts) { if (c.getConflictType() != ExamConflict.sConflictTypeDirect) continue; if (c.getNrStudents() == 0) continue; Exam other = null; for (Iterator i = c.getExams().iterator(); i.hasNext();) { Exam x = (Exam) i.next(); if (x.getUniqueId().equals(dc.getOtherExam().getExamId())) { other = x; break; } } if (other == null) continue; conf = c; break; } HashSet<Student> students = getStudents(hibSession, dc.getStudents()); if (exam.getUniqueId().compareTo(dc.getOtherExam().getExamId()) < 0) iTotal[sStudents][ExamConflict.sConflictTypeDirect] += students.size(); if (conf == null) { debug(" new direct " + assignment.getExamName() + " " + dc.getOtherExam().getExamName() + " (" + students.size() + " students)"); conf = new ExamConflict(); conf.setConflictType(ExamConflict.sConflictTypeDirect); conf.setStudents(students); conf.setNrStudents(students.size()); exam.getConflicts().add(conf); Exam other = dc.getOtherExam().getExam(hibSession); other.getConflicts().add(conf); otherExams.add(other); conf.setExams(new HashSet()); conf.getExams().add(exam); conf.getExams().add(other); hibSession.save(conf); iCnt[sStudents][conf.getConflictType()][sCreate] += conf.getNrStudents(); } else { conflicts.remove(conf); boolean change = (students.size() != conf.getStudents().size() || !students.containsAll(conf.getStudents())); if (change) { debug(" update direct " + assignment.getExamName() + " " + dc.getOtherExam().getExamName() + " (" + conf.getNrStudents() + "->" + students.size() + " students)"); conf.setStudents(students); conf.setNrStudents(students.size()); hibSession.update(conf); iCnt[sStudents][conf.getConflictType()][sUpdate] += conf.getNrStudents(); } } } for (DirectConflict dc : assignment.getInstructorDirectConflicts()) { if (dc.getOtherExam() == null) continue; ExamConflict conf = null; for (ExamConflict c : conflicts) { if (c.getConflictType() != ExamConflict.sConflictTypeDirect) continue; if (c.getNrInstructors() == 0) continue; Exam other = null; for (Iterator i = c.getExams().iterator(); i.hasNext();) { Exam x = (Exam) i.next(); if (x.getUniqueId().equals(dc.getOtherExam().getExamId())) { other = x; break; } } if (other == null) continue; conf = c; break; } HashSet<DepartmentalInstructor> instructors = getInstructors(hibSession, dc.getStudents()); if (exam.getUniqueId().compareTo(dc.getOtherExam().getExamId()) < 0) iTotal[sInstructors][ExamConflict.sConflictTypeDirect] += instructors.size(); if (conf == null) { debug(" new direct " + assignment.getExamName() + " " + dc.getOtherExam().getExamName() + " (" + instructors.size() + " instructors)"); conf = new ExamConflict(); conf.setConflictType(ExamConflict.sConflictTypeDirect); conf.setInstructors(instructors); conf.setNrInstructors(instructors.size()); exam.getConflicts().add(conf); Exam other = dc.getOtherExam().getExam(hibSession); other.getConflicts().add(conf); otherExams.add(other); conf.setExams(new HashSet()); conf.getExams().add(exam); conf.getExams().add(other); hibSession.save(conf); iCnt[sInstructors][conf.getConflictType()][sCreate] += conf.getNrInstructors(); } else { conflicts.remove(conf); boolean change = (instructors.size() != conf.getInstructors().size() || !instructors.containsAll(conf.getInstructors())); if (change) { debug(" update direct " + assignment.getExamName() + " " + dc.getOtherExam().getExamName() + " (" + conf.getNrInstructors() + "->" + instructors.size() + " instructors)"); conf.setInstructors(instructors); conf.setNrInstructors(instructors.size()); hibSession.update(conf); iCnt[sInstructors][conf.getConflictType()][sUpdate] += conf.getNrInstructors(); } } } for (BackToBackConflict btb : assignment.getBackToBackConflicts()) { int type = (btb.isDistance() ? ExamConflict.sConflictTypeBackToBackDist : ExamConflict.sConflictTypeBackToBack); if (btb.getOtherExam() == null) continue; ExamConflict conf = null; for (ExamConflict c : conflicts) { if (c.getConflictType() != type) continue; if (c.getNrStudents() == 0) continue; Exam other = null; for (Iterator i = c.getExams().iterator(); i.hasNext();) { Exam x = (Exam) i.next(); if (x.getUniqueId().equals(btb.getOtherExam().getExamId())) { other = x; break; } } if (other == null) continue; conf = c; break; } HashSet<Student> students = getStudents(hibSession, btb.getStudents()); if (exam.getUniqueId().compareTo(btb.getOtherExam().getExamId()) < 0) iTotal[sStudents][type] += students.size(); if (conf == null) { debug(" new btb " + assignment.getExamName() + " " + btb.getOtherExam().getExamName() + " (" + students.size() + " students)"); conf = new ExamConflict(); conf.setConflictType(type); conf.setStudents(students); conf.setNrStudents(students.size()); conf.setDistance(btb.getDistance()); exam.getConflicts().add(conf); Exam other = btb.getOtherExam().getExam(hibSession); other.getConflicts().add(conf); otherExams.add(other); conf.setExams(new HashSet()); conf.getExams().add(exam); conf.getExams().add(other); hibSession.save(conf); iCnt[sStudents][conf.getConflictType()][sCreate] += conf.getNrStudents(); } else { conflicts.remove(conf); boolean change = (students.size() != conf.getStudents().size() || !students.containsAll(conf.getStudents())); if (change) { debug(" update btb " + assignment.getExamName() + " " + btb.getOtherExam().getExamName() + " (" + conf.getNrStudents() + "->" + students.size() + " students)"); conf.setStudents(students); conf.setNrStudents(students.size()); conf.setDistance(btb.getDistance()); hibSession.update(conf); iCnt[sStudents][conf.getConflictType()][sUpdate] += conf.getNrStudents(); } else if (conf.getDistance() == null || Math.abs(conf.getDistance() - btb.getDistance()) > 1.0) { debug(" update btb " + assignment.getExamName() + " " + btb.getOtherExam().getExamName() + " (distance " + conf.getDistance() + " -> " + btb.getDistance() + ")"); conf.setDistance(btb.getDistance()); hibSession.update(conf); iCnt[sStudents][conf.getConflictType()][sUpdate] += conf.getNrStudents(); } } } for (BackToBackConflict btb : assignment.getInstructorBackToBackConflicts()) { int type = (btb.isDistance() ? ExamConflict.sConflictTypeBackToBackDist : ExamConflict.sConflictTypeBackToBack); if (btb.getOtherExam() == null) continue; ExamConflict conf = null; for (ExamConflict c : conflicts) { if (c.getConflictType() != type) continue; if (c.getNrInstructors() == 0) continue; Exam other = null; for (Iterator i = c.getExams().iterator(); i.hasNext();) { Exam x = (Exam) i.next(); if (x.getUniqueId().equals(btb.getOtherExam().getExamId())) { other = x; break; } } if (other == null) continue; conf = c; break; } HashSet<DepartmentalInstructor> instructors = getInstructors(hibSession, btb.getStudents()); if (exam.getUniqueId().compareTo(btb.getOtherExam().getExamId()) < 0) iTotal[sInstructors][type] += instructors.size(); if (conf == null) { debug(" new btb " + assignment.getExamName() + " " + btb.getOtherExam().getExamName() + " (" + instructors.size() + " instructors)"); conf = new ExamConflict(); conf.setConflictType(type); conf.setInstructors(instructors); conf.setNrInstructors(instructors.size()); if (btb.isDistance()) conf.setDistance(btb.getDistance()); exam.getConflicts().add(conf); Exam other = btb.getOtherExam().getExam(hibSession); other.getConflicts().add(conf); otherExams.add(other); conf.setExams(new HashSet()); conf.getExams().add(exam); conf.getExams().add(other); hibSession.save(conf); iCnt[sInstructors][conf.getConflictType()][sCreate] += conf.getNrInstructors(); } else { conflicts.remove(conf); boolean change = (instructors.size() != conf.getStudents().size() || !instructors.containsAll(conf.getInstructors())); if (change) { debug(" update btb " + assignment.getExamName() + " " + btb.getOtherExam().getExamName() + " (" + conf.getNrInstructors() + "->" + instructors.size() + " instructors)"); conf.setInstructors(instructors); conf.setNrInstructors(instructors.size()); conf.setDistance(btb.getDistance()); hibSession.update(conf); iCnt[sInstructors][conf.getConflictType()][sUpdate] += conf.getNrInstructors(); } else if (conf.getDistance() == null || Math.abs(conf.getDistance() - btb.getDistance()) > 1.0) { debug(" update btb " + assignment.getExamName() + " " + btb.getOtherExam().getExamName() + " (distance " + conf.getDistance() + " -> " + btb.getDistance() + ")"); conf.setDistance(btb.getDistance()); hibSession.update(conf); iCnt[sInstructors][conf.getConflictType()][sUpdate] += conf.getNrInstructors(); } } } for (MoreThanTwoADayConflict m2d : assignment.getMoreThanTwoADaysConflicts()) { if (m2d.getOtherExams() == null || m2d.getOtherExams().isEmpty()) continue; ExamConflict conf = null; conf: for (ExamConflict c : conflicts) { if (c.getConflictType() != ExamConflict.sConflictTypeMoreThanTwoADay) continue; if (c.getNrStudents() == 0) continue; if (c.getExams().size() != 1 + m2d.getOtherExams().size()) continue; for (Iterator i = c.getExams().iterator(); i.hasNext();) { Exam other = (Exam) i.next(); if (other.getUniqueId().equals(exam.getUniqueId())) continue; boolean contain = false; for (ExamAssignment x : m2d.getOtherExams()) { if (x.getExamId().equals(other.getUniqueId())) { contain = true; break; } } if (!contain) continue conf; } conf = c; break; } HashSet<Student> students = getStudents(hibSession, m2d.getStudents()); boolean smallest = true; for (ExamAssignment x : m2d.getOtherExams()) if (exam.getUniqueId().compareTo(x.getExamId()) > 0) { smallest = false; break; } if (smallest) iTotal[sStudents][ExamConflict.sConflictTypeMoreThanTwoADay] += students.size(); String name = assignment.getExamName(); for (ExamAssignment x : m2d.getOtherExams()) { name += " " + x.getExamName(); } if (conf == null) { debug(" new m2d " + name + " (" + students.size() + " students)"); conf = new ExamConflict(); conf.setConflictType(ExamConflict.sConflictTypeMoreThanTwoADay); conf.setStudents(students); conf.setNrStudents(students.size()); exam.getConflicts().add(conf); conf.setExams(new HashSet()); conf.getExams().add(exam); for (ExamAssignment x : m2d.getOtherExams()) { Exam other = x.getExam(hibSession); other.getConflicts().add(conf); otherExams.add(other); conf.getExams().add(other); } hibSession.save(conf); iCnt[sStudents][conf.getConflictType()][sCreate] += conf.getNrStudents(); } else { conflicts.remove(conf); boolean change = (students.size() != conf.getStudents().size() || !students.containsAll(conf.getStudents())); if (change) { debug(" update m2d " + name + " (" + conf.getNrStudents() + "->" + students.size() + " students)"); conf.setStudents(students); conf.setNrStudents(students.size()); hibSession.update(conf); iCnt[sStudents][conf.getConflictType()][sUpdate] += conf.getNrStudents(); } } } for (MoreThanTwoADayConflict m2d : assignment.getInstructorMoreThanTwoADaysConflicts()) { if (m2d.getOtherExams() == null || m2d.getOtherExams().isEmpty()) continue; ExamConflict conf = null; conf: for (ExamConflict c : conflicts) { if (c.getConflictType() != ExamConflict.sConflictTypeMoreThanTwoADay) continue; if (c.getNrInstructors() == 0) continue; if (c.getExams().size() != 1 + m2d.getOtherExams().size()) continue; for (Iterator i = c.getExams().iterator(); i.hasNext();) { Exam other = (Exam) i.next(); if (other.getUniqueId().equals(exam.getUniqueId())) continue; boolean contain = false; for (ExamAssignment x : m2d.getOtherExams()) { if (x.getExamId().equals(other.getUniqueId())) { contain = true; break; } } if (!contain) continue conf; } conf = c; break; } HashSet<DepartmentalInstructor> instructors = getInstructors(hibSession, m2d.getStudents()); boolean smallest = true; for (ExamAssignment x : m2d.getOtherExams()) if (exam.getUniqueId().compareTo(x.getExamId()) > 0) { smallest = false; break; } if (smallest) iTotal[sInstructors][ExamConflict.sConflictTypeMoreThanTwoADay] += instructors.size(); String name = assignment.getExamName(); for (ExamAssignment x : m2d.getOtherExams()) { name += " " + x.getExamName(); } if (conf == null) { debug(" new btb " + name + " (" + instructors.size() + " instructors)"); conf = new ExamConflict(); conf.setConflictType(ExamConflict.sConflictTypeMoreThanTwoADay); conf.setInstructors(instructors); conf.setNrInstructors(instructors.size()); exam.getConflicts().add(conf); conf.setExams(new HashSet()); conf.getExams().add(exam); for (ExamAssignment x : m2d.getOtherExams()) { Exam other = x.getExam(hibSession); other.getConflicts().add(conf); otherExams.add(other); conf.getExams().add(other); } hibSession.save(conf); iCnt[sInstructors][conf.getConflictType()][sCreate] += conf.getNrInstructors(); } else { conflicts.remove(conf); boolean change = (instructors.size() != conf.getStudents().size() || !instructors.containsAll(conf.getInstructors())); if (change) { debug(" update btb " + name + " (" + conf.getNrInstructors() + "->" + instructors.size() + " instructors)"); conf.setInstructors(instructors); conf.setNrInstructors(instructors.size()); hibSession.update(conf); iCnt[sInstructors][conf.getConflictType()][sUpdate] += conf.getNrInstructors(); } } } for (ExamConflict conf : conflicts) { String name = ""; if (conf.getConflictType() == ExamConflict.sConflictTypeDirect) name = "direct"; else if (conf.getConflictType() == ExamConflict.sConflictTypeMoreThanTwoADay) name = "m2d"; else if (conf.getConflictType() == ExamConflict.sConflictTypeBackToBack) name = "btb"; else if (conf.getConflictType() == ExamConflict.sConflictTypeBackToBackDist) name = "btb"; if (conf.getNrInstructors() != null) iCnt[sInstructors][conf.getConflictType()][sDelete] += conf.getNrInstructors(); if (conf.getNrStudents() != null) iCnt[sStudents][conf.getConflictType()][sDelete] += conf.getNrStudents(); for (Iterator i = conf.getExams().iterator(); i.hasNext();) { Exam other = (Exam) i.next(); name += " " + other.getLabel(); other.getConflicts().remove(conf); if (!other.equals(exam)) otherExams.add(other); } debug(" delete " + name + " (" + (conf.getNrStudents() != null && conf.getNrStudents() > 0 ? conf.getNrStudents() + " students" : "") + (conf.getNrInstructors() != null && conf.getNrInstructors() > 0 ? conf.getNrInstructors() + " instructors" : "") + ")"); hibSession.delete(conf); } hibSession.update(exam); for (Exam other : otherExams) hibSession.update(other); //hibSession.flush(); if (tx != null) tx.commit(); } catch (Exception e) { if (tx != null) tx.rollback(); throw e; } }