List of usage examples for java.util Hashtable entrySet
Set entrySet
To view the source code for java.util Hashtable entrySet.
Click Source Link
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Ensure that next up/down/left/right View is visible for all sub-views of the * passed view./*from w w w . j av a 2 s. c om*/ * * @param root */ public static void fixFocusSettings(View root) { final INextView getDown = new INextView() { @Override public int getNext(View v) { return v.getNextFocusDownId(); } @Override public void setNext(View v, int id) { v.setNextFocusDownId(id); } }; final INextView getUp = new INextView() { @Override public int getNext(View v) { return v.getNextFocusUpId(); } @Override public void setNext(View v, int id) { v.setNextFocusUpId(id); } }; final INextView getLeft = new INextView() { @Override public int getNext(View v) { return v.getNextFocusLeftId(); } @Override public void setNext(View v, int id) { v.setNextFocusLeftId(id); } }; final INextView getRight = new INextView() { @Override public int getNext(View v) { return v.getNextFocusRightId(); } @Override public void setNext(View v, int id) { v.setNextFocusRightId(id); } }; Hashtable<Integer, View> vh = getViews(root); for (Entry<Integer, View> ve : vh.entrySet()) { final View v = ve.getValue(); if (v.getVisibility() == View.VISIBLE) { fixNextView(vh, v, getDown); fixNextView(vh, v, getUp); fixNextView(vh, v, getLeft); fixNextView(vh, v, getRight); } } }
From source file:org.alfresco.dataprep.UserService.java
/** * Add dashlet to user dashboard/*w w w.j av a 2s.com*/ * * @param userName String identifier * @param password String password * @param dashlet Dashlet dashlet * @param layout dashlet layout * @param column int column index * @param position position in column * @return true if the dashlet is added */ @SuppressWarnings("unchecked") public boolean addDashlet(final String userName, final String password, final UserDashlet dashlet, final DashletLayout layout, final int column, final int position) { login(userName, password); if (column > 4 || column < 1) { throw new RuntimeException("Maximum number of columns must be at between 1 and 4"); } if (position > 5 || position < 1) { throw new RuntimeException("Maximum number of position must be between 1 and 5"); } AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); String url = client.getShareUrl() + DashboardCustomization.ADD_DASHLET_URL; JSONObject body = new JSONObject(); JSONArray array = new JSONArray(); body.put("dashboardPage", "user/" + userName + "/dashboard"); body.put("templateId", layout.id); // keep default dashlets Hashtable<String, String> defaultDashlets = new Hashtable<String, String>(); defaultDashlets.put(UserDashlet.MY_SITES.id, "component-1-1"); defaultDashlets.put(UserDashlet.MY_TASKS.id, "component-1-2"); defaultDashlets.put(UserDashlet.MY_ACTIVITIES.id, "component-2-1"); defaultDashlets.put(UserDashlet.MY_DOCUMENTS.id, "component-2-2"); Iterator<Map.Entry<String, String>> entries = defaultDashlets.entrySet().iterator(); while (entries.hasNext()) { Map.Entry<String, String> entry = entries.next(); JSONObject jDashlet = new JSONObject(); jDashlet.put("url", entry.getKey()); jDashlet.put("regionId", entry.getValue()); jDashlet.put("originalRegionId", entry.getValue()); array.add(jDashlet); } JSONObject newDashlet = new JSONObject(); newDashlet.put("url", dashlet.id); String region = "component-" + column + "-" + position; newDashlet.put("regionId", region); array.add(newDashlet); body.put("dashlets", array); HttpPost post = new HttpPost(url); post.setEntity(client.setMessageBody(body)); try { HttpResponse response = client.execute(userName, password, post); if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { logger.info("Dashlet " + dashlet.name + " was added on user: " + userName + " dashboard"); return true; } else { logger.error("Unable to add dashlet to user dashboard " + userName); } } finally { post.releaseConnection(); client.close(); } return false; }
From source file:org.mahasen.client.Search.java
/** * @param searchRequests/*from ww w . ja va 2 s .co m*/ * @param isAndSearch * @return * @throws IOException * @throws URISyntaxException * @throws AuthenticationExceptionException * * @throws MahasenClientException */ private HttpResponse sendRequest(Hashtable<String, Vector<String>> searchRequests, boolean isAndSearch) throws IOException, URISyntaxException, AuthenticationExceptionException, MahasenClientException { httpclient = new DefaultHttpClient(); HttpResponse response = null; String userName = clientLoginData.getUserName(); String passWord = clientLoginData.getPassWord(); String hostAndPort = clientLoginData.getHostNameAndPort(); String userId = clientLoginData.getUserId(userName, passWord); Boolean isLogged = clientLoginData.isLoggedIn(); System.out.println(" Is Logged : " + isLogged); System.out.println(" Is Logged : " + isLogged); if (isLogged == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>(); for (Map.Entry<String, Vector<String>> entry : searchRequests.entrySet()) { for (String value : entry.getValue()) { qparams.add(new BasicNameValuePair(entry.getKey(), value)); } } /*qparams.add(new BasicNameValuePair("org.mahasen","value1")); qparams.add(new BasicNameValuePair("org.mahasen","value2")); qparams.add(new BasicNameValuePair("org.mahasen","value3"));*/ URI uri; if (isAndSearch == true) { uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/multiple_and_search_request_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); } else { uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/multiple_or_search_request_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); } HttpPost httppost = new HttpPost(uri); System.out.println("executing request " + httppost.getRequestLine()); response = httpclient.execute(httppost); } else { System.out.println("User has to be logged in to perform this function"); } return response; }
From source file:org.opendaylight.defense4all.core.impl.DFMgmtPointImpl.java
protected void resetPns(ResetLevel resetLevel) throws ExceptionControlApp { Hashtable<String, Hashtable<String, Object>> pnTable; try {//ww w .j a v a 2 s.c o m pnTable = dfAppRootFullImpl.pNsRepo.getTable(); } catch (Throwable e) { log.error("Failed to get pNsRepo table", e); fMain.getHealthTracker().reportHealthIssue(HealthTracker.MODERATE_HEALTH_ISSUE); throw new ExceptionControlApp("Failed to get pNsRepo table", e); } Set<Entry<String, Hashtable<String, Object>>> pnTableEntrySet = pnTable.entrySet(); if (pnTableEntrySet == null) return; Iterator<Map.Entry<String, Hashtable<String, Object>>> iter = pnTableEntrySet.iterator(); Map.Entry<String, Hashtable<String, Object>> entry; String pnKey; PN pn; while (iter.hasNext()) { try { entry = iter.next(); pnKey = entry.getKey(); } catch (Exception e1) { log.error("Invalid entry in pNsRepo table", e1); fMain.getHealthTracker().reportHealthIssue(HealthTracker.MINOR_HEALTH_ISSUE); continue; } try { pn = new PN(entry.getValue()); } catch (ExceptionControlApp e) { continue; /* Ignore */} pn.averageStr = ""; pn.latestRateStr = ""; pn.latestRateTime = 0; pn.attackSuspicions = ""; pn.statsCollectionStatus = StatsCollectionStatus.INVALID; if (resetLevel == ResetLevel.dynamic) { pn.baselineStr = ""; pn.baselinesTime = 0; } try { dfAppRootFullImpl.pNsRepo.setRow(pnKey, pn.toRow()); } catch (Throwable e) { log.error("Failed to set pnRow in pNsRepo table " + pnKey, e); fMain.getHealthTracker().reportHealthIssue(HealthTracker.MINOR_HEALTH_ISSUE); continue; } } }
From source file:org.apache.pig.impl.logicalLayer.LOFRJoin.java
@Override /**// w ww . j a va 2s . c om * Uses the schema from its input operators and dedups * those fields that have the same alias and sets the * schema for the join */ public Schema getSchema() throws FrontendException { List<LogicalOperator> inputs = mPlan.getPredecessors(this); mType = DataType.BAG;//mType is from the super class Hashtable<String, Integer> nonDuplicates = new Hashtable<String, Integer>(); if (!mIsSchemaComputed) { List<Schema.FieldSchema> fss = new ArrayList<Schema.FieldSchema>(); int i = -1; for (LogicalOperator op : inputs) { try { Schema cSchema = op.getSchema(); if (cSchema != null) { for (FieldSchema schema : cSchema.getFields()) { ++i; if (nonDuplicates.containsKey(schema.alias)) { if (nonDuplicates.get(schema.alias) != -1) { nonDuplicates.remove(schema.alias); nonDuplicates.put(schema.alias, -1); } } else nonDuplicates.put(schema.alias, i); FieldSchema newFS = new FieldSchema(op.getAlias() + "::" + schema.alias, schema.schema, schema.type); newFS.setParent(schema.canonicalName, op); fss.add(newFS); } } else fss.add(new FieldSchema(null, DataType.BYTEARRAY)); } catch (FrontendException ioe) { mIsSchemaComputed = false; mSchema = null; throw ioe; } } mIsSchemaComputed = true; for (Entry<String, Integer> ent : nonDuplicates.entrySet()) { int ind = ent.getValue(); if (ind == -1) continue; FieldSchema prevSch = fss.get(ind); fss.set(ind, new FieldSchema(ent.getKey(), prevSch.schema, prevSch.type)); } mSchema = new Schema(fss); } return mSchema; }
From source file:metabest.transformations.MetaModel2Use.java
private String simultaneousCompositionConstraint(List<Reference> references) { String constraints = ""; // obtain the containment references that can contain each class Hashtable<String, List<Reference>> containers = new Hashtable<String, List<Reference>>(); for (Reference ref : references) { if (ref.isAnnotated(Composition.NAME)) { String classname = ref.getReference().getName(); if (!containers.containsKey(classname)) containers.put(classname, new ArrayList<Reference>()); containers.get(classname).add(ref); }// ww w .ja va 2s . co m if (ref.getOpposite() != null && ref.getOpposite().isAnnotated(Composition.NAME)) { String classname = ref.getOpposite().getReference().getName(); if (!containers.containsKey(classname)) containers.put(classname, new ArrayList<Reference>()); containers.get(classname).add(ref.getOpposite()); } } // if a class can potentially be in more than two containers, add a constraint for (Entry<String, List<Reference>> entry : containers.entrySet()) { if (entry.getValue().size() > 1) { constraints += "\n\ncontext " + entry.getKey() + "\n\tinv single_container: "; constraints += "\n"; for (Reference ref : entry.getValue()) constraints += "\t" + ((MetaClass) ref.eContainer()).getName() + ".allInstances()->collect(o | o." + ref.getName() + ")->count(self) +\n"; constraints = constraints.substring(0, constraints.lastIndexOf("+")) + "<= 1"; } } if (!constraints.isEmpty()) constraints += "\n"; return constraints; }
From source file:org.wso2.carbon.service.mgt.ServiceAdmin.java
public FaultyServicesWrapper getFaultyServiceArchives(int pageNumber) throws AxisFault { AxisConfiguration ac = getAxisConfig(); String repository = ac.getRepository().getPath(); Hashtable<String, String> faultyServices = ac.getFaultyServices(); List<FaultyService> fsList = new ArrayList<FaultyService>(); for (Map.Entry<String, String> entry : faultyServices.entrySet()) { String artifactPath = entry.getKey(); String serviceName = artifactPath; String fault = entry.getValue(); FaultyService fs = new FaultyService(); if (File.separatorChar == '\\') { serviceName = serviceName.replace('\\', '/'); repository = repository.replace('\\', '/'); if (repository.startsWith("/")) { repository = repository.substring(1); }//from www. j ava 2s .co m } if (serviceName.endsWith("/")) { serviceName = serviceName.substring(0, serviceName.length() - 1); } if (repository.endsWith("/")) { repository = repository.substring(0, repository.length() - 1); } if (serviceName.startsWith(repository)) { serviceName = serviceName.substring(repository.length() + 1); serviceName = serviceName.substring(serviceName.indexOf('/') + 1); } int slashIndex = serviceName.lastIndexOf('/'); int dotIndex = serviceName.lastIndexOf('.'); if (dotIndex != -1 && (dotIndex > slashIndex)) { serviceName = serviceName.substring(0, dotIndex); } //Retrieving faulty services registered via CarbonConfigurationContext AxisService axisService = CarbonUtils.getFaultyService(artifactPath, this.getConfigContext()); fs.setServiceName(serviceName); fs.setFault(fault); if (File.separatorChar == '\\') { artifactPath = artifactPath.replace('\\', '/'); } if (axisService != null) { fs.setArtifact(artifactPath.replace(repository, "")); fs.setServiceType(getServiceType(axisService)); fsList.add(fs); continue; } // sometimes we get the real serviceName. Ex: proxy services. In that case, there // might be an AxisService object.. axisService = ac.getService(serviceName); if (artifactPath.startsWith(repository)) { artifactPath = artifactPath.replace(repository, ""); fs.setArtifact(artifactPath); } fs.setServiceName(serviceName); fs.setFault(fault); if (axisService != null) { fs.setServiceType(getServiceType(axisService)); } fsList.add(fs); } FaultyServicesWrapper wrapper = null; if (fsList.size() > 0) { Collections.sort(fsList, new Comparator<FaultyService>() { public int compare(FaultyService arg0, FaultyService arg1) { return arg0.getServiceName().compareToIgnoreCase(arg1.getServiceName()); } }); // Pagination wrapper = new FaultyServicesWrapper(); wrapper.setNumberOfFaultyServiceGroups(getNumberOfFaultyServices()); DataPaginator.doPaging(pageNumber, fsList, wrapper); } return wrapper; }
From source file:org.apache.pig.impl.logicalLayer.LOJoin.java
@Override public Schema getSchema() throws FrontendException { List<LogicalOperator> inputs = mPlan.getPredecessors(this); mType = DataType.BAG;//mType is from the super class Hashtable<String, Integer> nonDuplicates = new Hashtable<String, Integer>(); if (!mIsSchemaComputed) { List<Schema.FieldSchema> fss = new ArrayList<Schema.FieldSchema>(); mSchemaInputMapping = new ArrayList<LogicalOperator>(); int i = -1; boolean seeUnknown = false; for (LogicalOperator op : inputs) { try { Schema cSchema = op.getSchema(); if (cSchema != null) { for (FieldSchema schema : cSchema.getFields()) { ++i;/*from ww w .j av a 2s. c o m*/ FieldSchema newFS = null; if (schema.alias != null) { if (nonDuplicates.containsKey(schema.alias)) { if (nonDuplicates.get(schema.alias) != -1) { nonDuplicates.remove(schema.alias); nonDuplicates.put(schema.alias, -1); } } else { nonDuplicates.put(schema.alias, i); } newFS = new FieldSchema(op.getAlias() + "::" + schema.alias, schema.schema, schema.type); } else { newFS = new Schema.FieldSchema(null, schema.type); } newFS.setParent(schema.canonicalName, op); fss.add(newFS); mSchemaInputMapping.add(op); } } else { seeUnknown = true; } } catch (FrontendException ioe) { mIsSchemaComputed = false; mSchema = null; throw ioe; } } mIsSchemaComputed = true; mSchema = null; if (!seeUnknown) { mSchema = new Schema(fss); for (Entry<String, Integer> ent : nonDuplicates.entrySet()) { int ind = ent.getValue(); if (ind == -1) continue; FieldSchema prevSch = fss.get(ind); // this is a non duplicate and hence can be referred to // with just the field schema alias or outeralias::field schema alias // In mSchema we have outeralias::fieldschemaalias. To allow // using just the field schema alias, add it to mSchemas // as an alias for this field. mSchema.addAlias(ent.getKey(), prevSch); } } } return mSchema; }
From source file:org.unitime.timetable.solver.TimetableSolver.java
public Vector getTimetableGridTables(TimetableGridContext context) { Vector models = new Vector(); Query q = (context.getFilter() == null ? null : new Query(context.getFilter())); Lock lock = currentSolution().getLock().readLock(); lock.lock();/*from w w w .j a va2 s .com*/ try { TimetableModel model = (TimetableModel) currentSolution().getModel(); switch (context.getResourceType()) { case TimetableGridModel.sResourceTypeRoom: for (RoomConstraint rc : model.getRoomConstraints()) { if (!match(q, rc)) continue; models.add(new SolverGridModel(this, rc, context)); } break; case TimetableGridModel.sResourceTypeInstructor: for (InstructorConstraint ic : model.getInstructorConstraints()) { if (!match(q, ic.getName())) continue; models.add(new SolverGridModel(this, ic, context)); } break; case TimetableGridModel.sResourceTypeDepartment: for (DepartmentSpreadConstraint dc : model.getDepartmentSpreadConstraints()) { if (!match(q, dc.getName())) continue; models.add(new SolverGridModel(this, dc, context)); } if (model.getDepartmentSpreadConstraints().isEmpty()) { org.cpsolver.ifs.assignment.Assignment<Lecture, Placement> assignment = currentSolution() .getAssignment(); Map<Department, Set<Long>> dept2class = new HashMap<Department, Set<Long>>(); for (Object[] pair : (List<Object[]>) DepartmentDAO.getInstance().getSession().createQuery( "select c.controllingDept, c.uniqueId from Class_ c where c.managingDept.solverGroup.uniqueId in :solverGroupIds") .setParameterList("solverGroupIds", getOwnerId(), new LongType()).list()) { Department dept = (Department) pair[0]; Long classId = (Long) pair[1]; Set<Long> classIds = dept2class.get(dept); if (classIds == null) { classIds = new HashSet<Long>(); dept2class.put(dept, classIds); } classIds.add(classId); } for (Department d : new TreeSet<Department>(dept2class.keySet())) { if (!match(q, d.getShortLabel())) continue; Set<Long> classIds = dept2class.get(d); int size = 0; List<Placement> placements = new ArrayList<Placement>(); for (Lecture lecture : currentSolution().getModel().variables()) { if (classIds.contains(lecture.getClassId())) { size++; Placement placement = assignment.getValue(lecture); if (placement != null) placements.add(placement); } } if (size > 0) models.add(new SolverGridModel(this, TimetableGridModel.sResourceTypeDepartment, d.getUniqueId(), d.getShortLabel(), size, placements, context)); } } break; case TimetableGridModel.sResourceTypeCurriculum: Hashtable<String, List<Student>> curricula = new Hashtable<String, List<Student>>(); boolean hasCurricula = false; HashSet<String> ignore = new HashSet<String>(), tested = new HashSet<String>(); for (Student student : model.getAllStudents()) { if (student.getCurriculum() != null && student.getAcademicClassification() != null) { if (!hasCurricula) { curricula.clear(); hasCurricula = true; } String c = student.getCurriculum() + " " + student.getAcademicClassification(); if (tested.add(c) && !match(q, c)) ignore.add(c); if (ignore.contains(c)) continue; List<Student> students = curricula.get(c); if (students == null) { students = new ArrayList<Student>(); curricula.put(c, students); } students.add(student); } else if (!hasCurricula && student.getAcademicArea() != null && student.getAcademicClassification() != null) { String c = student.getAcademicArea() + (student.getMajor() == null ? "" : " " + student.getMajor()) + " " + student.getAcademicClassification(); if (tested.add(c) && !match(q, c)) ignore.add(c); if (ignore.contains(c)) continue; List<Student> students = curricula.get(c); if (students == null) { students = new ArrayList<Student>(); curricula.put(c, students); } students.add(student); } } for (Map.Entry<String, List<Student>> curriculum : curricula.entrySet()) { models.add(new SolverGridModel(this, curriculum.getKey(), curriculum.getValue(), context)); } break; case TimetableGridModel.sResourceTypeSubjectArea: org.cpsolver.ifs.assignment.Assignment<Lecture, Placement> assignment = currentSolution() .getAssignment(); Map<SubjectArea, Set<Long>> sa2class = new HashMap<SubjectArea, Set<Long>>(); for (Object[] pair : (List<Object[]>) DepartmentDAO.getInstance().getSession().createQuery( "select co.subjectArea, c.uniqueId from Class_ c inner join c.schedulingSubpart.instrOfferingConfig.instructionalOffering.courseOfferings co where co.isControl = true and c.managingDept.solverGroup.uniqueId in :solverGroupIds") .setParameterList("solverGroupIds", getOwnerId(), new LongType()).list()) { SubjectArea sa = (SubjectArea) pair[0]; Long classId = (Long) pair[1]; Set<Long> classIds = sa2class.get(sa); if (classIds == null) { classIds = new HashSet<Long>(); sa2class.put(sa, classIds); } classIds.add(classId); } for (SubjectArea sa : new TreeSet<SubjectArea>(sa2class.keySet())) { if (!match(q, sa.getSubjectAreaAbbreviation())) continue; Set<Long> classIds = sa2class.get(sa); int size = 0; List<Placement> placements = new ArrayList<Placement>(); for (Lecture lecture : currentSolution().getModel().variables()) { if (classIds.contains(lecture.getClassId())) { size++; Placement placement = assignment.getValue(lecture); if (placement != null) placements.add(placement); } } if (size > 0) models.add(new SolverGridModel(this, TimetableGridModel.sResourceTypeSubjectArea, sa.getUniqueId(), sa.getSubjectAreaAbbreviation(), size, placements, context)); } break; } } finally { lock.unlock(); } return models; }
From source file:org.unitime.timetable.solver.exam.ExamSolver.java
public ExamProposedChange update(ExamProposedChange change) { Lock lock = currentSolution().getLock().writeLock(); lock.lock();//from w w w . ja v a 2s . com try { Hashtable<Exam, ExamPlacement> undoAssign = new Hashtable(); HashSet<Exam> undoUnassing = new HashSet(); Vector<Exam> unassign = new Vector(); Vector<ExamPlacement> assign = new Vector(); HashSet<ExamPlacement> conflicts = new HashSet(); /* for (ExamAssignment assignment: change.getConflicts()) { ExamPlacement placement = getPlacement(assignment); if (placement==null || !placement.equals(placement.variable().getAssignment())) return null; undoAssign.put((Exam)placement.variable(),placement); unassign.add((Exam)placement.variable()); } */ for (ExamAssignment assignment : change.getAssignments()) { ExamPlacement placement = getPlacement(assignment); if (placement == null) return null; if (currentSolution().getAssignment().getValue(placement.variable()) != null) undoAssign.put((Exam) placement.variable(), currentSolution().getAssignment().getValue(placement.variable())); else undoUnassing.add((Exam) placement.variable()); assign.add(placement); unassign.add((Exam) placement.variable()); } for (Exam exam : unassign) currentSolution().getAssignment().unassign(0, exam); for (ExamPlacement placement : assign) { for (Iterator i = placement.variable().getModel() .conflictValues(currentSolution().getAssignment(), placement).iterator(); i.hasNext();) { ExamPlacement conflict = (ExamPlacement) i.next(); Exam conflictingExam = (Exam) conflict.variable(); if (!undoAssign.containsKey(conflictingExam) && !undoUnassing.contains(conflictingExam)) undoAssign.put(conflictingExam, conflict); conflicts.add(conflict); currentSolution().getAssignment().unassign(0, conflict.variable()); } currentSolution().getAssignment().assign(0, placement); } change.getAssignments().clear(); change.getConflicts().clear(); for (ExamPlacement assignment : assign) if (!conflicts.contains(assignment)) change.getAssignments() .add(new ExamAssignmentInfo(assignment, currentSolution().getAssignment())); for (Exam exam : undoUnassing) if (currentSolution().getAssignment().getValue(exam) != null) currentSolution().getAssignment().unassign(0, exam); for (Map.Entry<Exam, ExamPlacement> entry : undoAssign.entrySet()) currentSolution().getAssignment().unassign(0, entry.getKey()); for (Map.Entry<Exam, ExamPlacement> entry : undoAssign.entrySet()) currentSolution().getAssignment().assign(0, entry.getValue()); for (ExamPlacement conflict : conflicts) { ExamPlacement original = undoAssign.get((Exam) conflict.variable()); change.getConflicts().add(new ExamAssignment(original == null ? conflict : original, currentSolution().getAssignment())); } return change; } finally { lock.unlock(); } }