List of usage examples for java.util Set clear
void clear();
From source file:eu.europeana.enrichment.tagger.postprocessors.PeopleTermFilter.java
@Override public TermList disambiguate(TermList terms, DisambiguationContext disambiguationContext) throws Exception { // disambiguation not needed if (terms.size() < 2) return terms; TermList results = new TermList(); if (!(disambiguationContext instanceof UlanDisambiguationContext)) throw new Exception( "Expected ULAN-specific disambiguation context. Apperantly, Ulan.disambiguate was called outside Ulan lookupPerson."); UlanDisambiguationContext udc = (UlanDisambiguationContext) disambiguationContext; for (Term term : terms) { // ulan years Set<Integer> ulanBirthYears = years("birth", term); Set<Integer> ulanDeathYears = years("death", term); // 100 years was added to ULAN when no death date was there if (!ulanBirthYears.isEmpty() && !ulanDeathYears.isEmpty() && ulanBirthYears.iterator().next() + 100 == ulanDeathYears.iterator().next()) { ulanDeathYears.clear(); }/* w ww. java 2 s . com*/ // request years int reqBirthYear = 0; int reqDeathYear = 0; if (udc.birthDate != null) { if (udc.birthDate.matches("^\\d\\d\\d\\d(\\-(.+))?")) reqBirthYear = Integer.parseInt(udc.birthDate.substring(0, 4)); if (reqBirthYear >= now.get(Calendar.YEAR)) { reqBirthYear = 0; } } if (udc.deathDate != null) { if (udc.deathDate.matches("^\\d\\d\\d\\d(\\-(.+))?")) reqDeathYear = Integer.parseInt(udc.deathDate.substring(0, 4)); if (reqDeathYear >= now.get(Calendar.YEAR)) { reqDeathYear = 0; } } // comparing the ulan dates with the requested dates if (udc.isLiveDate) { if (checkDates(ulanBirthYears, ulanDeathYears, reqBirthYear, reqDeathYear, 3, true)) // reqBirthYear should be a year of ULAN life // if (reqBirthYear >= Collections.min(ulanBirthYears) // && (ulanDeathYears.isEmpty() || reqBirthYear <= // Collections.max(ulanDeathYears))) { results.add(term); term.setDisambiguatingComment( String.format("requested year of life %d matched ULAN lifetime (%s-%s)", reqBirthYear, toString(ulanBirthYears), toString(ulanDeathYears))); } } else { // requested years should match ULAN years if (reqBirthYear == 0 && reqDeathYear == 0) { // no years results.add(term); term.setDisambiguatingComment("Matching name only, no life dates provided"); } else { // check years if (checkDates(ulanBirthYears, ulanDeathYears, reqBirthYear, reqDeathYear, 3, false)) { results.add(term); term.setDisambiguatingComment(String.format( "requested lifetime (%d-%d) matched ULAN lifetime (%s-%s)", reqBirthYear, reqDeathYear, toString(ulanBirthYears), toString(ulanDeathYears))); } } // Unambiguous choice that fails date check if (terms.size() == 1 && results.isEmpty()) { // do a very relaxed check // if (checkDates(ulanBirthYears, ulanDeathYears, // reqBirthYear, reqDeathYear, 25, false)) { results.add(term); term.setConfidenceComment(String.format( "requested lifetime (%d-%d) DID NOT really match ULAN lifetime (%s-%s)", reqBirthYear, reqDeathYear, toString(ulanBirthYears), toString(ulanDeathYears))); term.setDisambiguatingComment("Maching name, and relaxed match on life dates"); } } } } return (results.size() == 1) ? results : new TermList(); }
From source file:org.adaway.util.ScanAdwareLoader.java
/** * Finds all installed packages that look like they include a known ad framework *//*from w ww .j av a 2 s .c o m*/ private List<PackageInfo> getAdPackages() { Set<PackageInfo> adPackages = new HashSet<PackageInfo>(); PackageManager pm = context.getPackageManager(); // It'd be simpler to just use pm.getInstalledPackages here, but apparently it's broken List<ApplicationInfo> appInfos = pm.getInstalledApplications(0); for (ApplicationInfo appInfo : appInfos) { if (canceled) { adPackages.clear(); break; } try { PackageInfo pkgInfo = pm.getPackageInfo(appInfo.packageName, PackageManager.GET_ACTIVITIES | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES); Log.v(Constants.TAG, "Scanning package " + pkgInfo.packageName); if (pkgInfo.activities != null) { for (ActivityInfo activity : pkgInfo.activities) { Log.v(Constants.TAG, "[ACTIVITY] " + activity.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (activity.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as activity " + activity.name); adPackages.add(pkgInfo); } } } } if (pkgInfo.receivers != null) { for (ActivityInfo receiver : pkgInfo.receivers) { Log.v(Constants.TAG, "[RECEIVER] " + receiver.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (receiver.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as receiver " + receiver.name); adPackages.add(pkgInfo); break; } } } } if (pkgInfo.services != null) { for (ServiceInfo service : pkgInfo.services) { Log.v(Constants.TAG, "[SERVICE] " + service.name); for (String adPackagePrefix : AD_PACKAGE_PREFIXES) { if (service.name.startsWith(adPackagePrefix)) { Log.i(Constants.TAG, "Detected ad framework prefix " + adPackagePrefix + " in package " + pkgInfo.packageName + " as service " + service.name); adPackages.add(pkgInfo); break; } } } } } catch (Exception e) { Log.e(Constants.TAG, "Scan Adware Exception", e); } } return new ArrayList<PackageInfo>(adPackages); }
From source file:com.krawler.esp.handlers.ProfileHandler.java
public static void updateCompany(Session session, HttpServletRequest request, HashMap hm) throws ServiceException { try {//from w w w. j av a 2 s. com CompanyPreferences cp = (CompanyPreferences) session.load(CompanyPreferences.class, AuthHandler.getCompanyid(request)); Company company = cp.getCompany(); company.setCompanyName((String) hm.get("companyname")); company.setAddress((String) hm.get("address")); company.setCity((String) hm.get("city")); company.setState((String) hm.get("state")); company.setZipCode((String) hm.get("zip")); company.setPhoneNumber((String) hm.get("phone")); company.setFaxNumber((String) hm.get("fax")); company.setWebsite((String) hm.get("website")); company.setEmailID((String) hm.get("mail")); company.setSubDomain((String) hm.get("domainname")); cp.setEmpidformat((String) hm.get("employeeidformat")); company.setCountry((Country) session.load(Country.class, (String) hm.get("country"))); company.setCurrency((KWLCurrency) session.load(KWLCurrency.class, (String) hm.get("currency"))); KWLTimeZone timeZone = (KWLTimeZone) session.load(KWLTimeZone.class, (String) hm.get("timezone")); company.setTimeZone(timeZone); company.setModifiedOn(new Date()); JSONArray jArr = new JSONArray((String) hm.get("holidays")); Set<CompanyHoliday> holidays = company.getHolidays(); holidays.clear(); DateFormat formatter = AuthHandler.getDateFormatter(request); for (int i = 0; i < jArr.length(); i++) { CompanyHoliday day = new CompanyHoliday(); JSONObject obj = jArr.getJSONObject(i); day.setDescription(obj.getString("description")); day.setHolidayDate(formatter.parse(obj.getString("day"))); day.setCompany(company); holidays.add(day); } String imageName = ((FileItem) (hm.get("logo"))).getName(); if (StringUtil.isNullOrEmpty(imageName) == false) { String fileName = AuthHandler.getCompanyid(request) + FileUploadHandler.getCompanyImageExt(); company.setCompanyLogo(ProfileImageServlet.ImgBasePath + fileName); new FileUploadHandler().uploadImage((FileItem) hm.get("logo"), fileName, StorageHandler.GetProfileImgStorePath(), 130, 25, true, false); } session.update(company); SessionHandler.updatePreferences(request, (String) hm.get("currency"), null, (String) hm.get("timezone"), timeZone.getDifference()); // insertAuditLog(session, AuditAction.COMPANY_UPDATION, "User " + AuthHandler.getUserName(request) + " changed company details", request); } catch (Exception e) { throw ServiceException.FAILURE("ProfileHandler.updateCompany", e); } }
From source file:edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.java
protected void computeWeightedPathsFromSource(V root, int depth) { int pathIdx = 1; for (E e : getGraph().getOutEdges(root)) { this.pathIndices.put(e, pathIdx); this.roots.put(e, root); newVertexEncountered(pathIdx, getGraph().getEndpoints(e).getSecond(), root); pathIdx++;/*from w ww. j a v a2 s. c o m*/ } List<E> edges = new ArrayList<E>(); V virtualNode = vertexFactory.create(); getGraph().addVertex(virtualNode); E virtualSinkEdge = edgeFactory.create(); getGraph().addEdge(virtualSinkEdge, virtualNode, root); edges.add(virtualSinkEdge); int currentDepth = 0; while (currentDepth <= depth) { double currentWeight = Math.pow(mAlpha, -1.0 * currentDepth); for (E currentEdge : edges) { incrementRankScore(getGraph().getEndpoints(currentEdge).getSecond(), // currentWeight); } if ((currentDepth == depth) || (edges.size() == 0)) break; List<E> newEdges = new ArrayList<E>(); for (E currentSourceEdge : edges) { //Iterator sourceEdgeIt = edges.iterator(); sourceEdgeIt.hasNext();) { Number sourcePathIndex = this.pathIndices.get(currentSourceEdge); // from the currentSourceEdge, get its opposite end // then iterate over the out edges of that opposite end V newDestVertex = getGraph().getEndpoints(currentSourceEdge).getSecond(); Collection<E> outs = getGraph().getOutEdges(newDestVertex); for (E currentDestEdge : outs) { V destEdgeRoot = this.roots.get(currentDestEdge); V destEdgeDest = getGraph().getEndpoints(currentDestEdge).getSecond(); if (currentSourceEdge == virtualSinkEdge) { newEdges.add(currentDestEdge); continue; } if (destEdgeRoot == root) { continue; } if (destEdgeDest == getGraph().getEndpoints(currentSourceEdge).getFirst()) {//currentSourceEdge.getSource()) { continue; } Set<Number> pathsSeen = this.pathsSeenMap.get(destEdgeDest); if (pathsSeen == null) { newVertexEncountered(sourcePathIndex.intValue(), destEdgeDest, root); } else if (roots.get(destEdgeDest) != root) { roots.put(destEdgeDest, root); pathsSeen.clear(); pathsSeen.add(sourcePathIndex); } else if (!pathsSeen.contains(sourcePathIndex)) { pathsSeen.add(sourcePathIndex); } else { continue; } this.pathIndices.put(currentDestEdge, sourcePathIndex); this.roots.put(currentDestEdge, root); newEdges.add(currentDestEdge); } } edges = newEdges; currentDepth++; } getGraph().removeVertex(virtualNode); }
From source file:com.sap.prd.mobile.ios.mios.XCodePackageXcodeprojMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { String xprojZipFileName = project.getArtifactId() + "-" + XCODEPROJ_WITH_DEPS_CLASSIFIER + ".zip"; final String projectBuildDirectory = project.getBuild().getDirectory(); try {/*from ww w. j a v a2 s .c om*/ final File targetFolder = new File(projectBuildDirectory); FileUtils.mkdirs(targetFolder); String relativeTargetDirName = FileUtils.getRelativePath(projectBuildDirectory, project.getBasedir().getAbsolutePath(), "/"); String relativeSrcDirName = FileUtils.getRelativePath( FolderLayout.getSourceFolder(project).getAbsolutePath(), project.getBasedir().getAbsolutePath(), "/"); Set<String> includes = new HashSet<String>(); includes.add(relativeSrcDirName); // src/xcode folder includes.add(relativeTargetDirName + "/xcode-deps/frameworks"); zip(Arrays.asList("zip", "-r", "-y", "-q", relativeTargetDirName + "/" + xprojZipFileName), includes, excludes); includes.clear(); includes.add("pom.xml"); includes.add("sync.info"); includes.add(relativeTargetDirName + "/bundles"); includes.add(relativeTargetDirName + "/headers"); includes.add(relativeTargetDirName + "/libs"); includes.add(relativeTargetDirName + "/xcode-deps"); Collection<String> myExcludes = excludes == null ? new ArrayList<String>() : new ArrayList<String>(excludes); myExcludes.add(relativeTargetDirName + "/xcode-deps/frameworks/*"); if (additionalArchivePaths != null) { includes.addAll(additionalArchivePaths); } zip(Arrays.asList("zip", "-r", "-g", "-q", relativeTargetDirName + "/" + xprojZipFileName), includes, myExcludes); getLog().info( "Packaged the Xcode project with all its dependencies into the zip file " + xprojZipFileName); } catch (IOException e) { throw new MojoExecutionException( "Could not package the Xcode project with all its dependencies into a zip file.", e); } projectHelper.attachArtifact(project, "zip", XCODEPROJ_WITH_DEPS_CLASSIFIER, new File(projectBuildDirectory, xprojZipFileName)); }
From source file:co.turnus.analysis.bottlenecks.AlgorithmicBottlenecks.java
protected HotspotsData find(Table<String, String, Double> ratiosTable) { // check if the trace should be initialised initTrace();/*from w ww .ja va 2s. co m*/ Trace trace = project.getTrace(); Network network = project.getNetwork(); HotSpotsDataCollector collector = new HotSpotsDataCollector(network); iterationId++; Step tStep = null; double cpValue = Double.MIN_VALUE; for (long stepId = 0; stepId < trace.getLength(); stepId++) { Step step = trace.getStep(stepId); double es = 0.0; for (Dependency in : step.getIncomings()) { double tmp = in.getSource().getAttribute(EARLY_FINISH + iterationId); es = FastMath.max(tmp, es); } // evaluate early start and finish time double[] cl = getWeight(step, ratiosTable); double ef = es + cl[MEAN]; step.setAttribute(EARLY_START + iterationId, es); step.setAttribute(EARLY_FINISH + iterationId, ef); if (ef > cpValue) { cpValue = ef; tStep = step; } } for (long stepId = trace.getLength() - 1; stepId >= 0; stepId--) { Step step = trace.getStep(stepId); double lf = cpValue; for (Dependency out : step.getOutgoings()) { double tmp = out.getTarget().getAttribute(LATEST_START + iterationId); lf = FastMath.min(tmp, lf); } double[] cl = getWeight(step, ratiosTable); double ls = lf - cl[MEAN]; step.setAttribute(LATEST_FINISH + iterationId, lf); step.setAttribute(LATEST_START + iterationId, ls); double ef = step.getAttribute(EARLY_FINISH + iterationId); double slack = lf - ef; step.setAttribute(SLACK + iterationId, slack); // log computational load with the slack collector.addExecution(step, cl, slack); } // Walk back the critical path following the early finish gradient Step next = tStep; Set<Step> predecessors = new HashSet<>(); while (next != null) { collector.addCriticalExecution(next, getWeight(next, ratiosTable)); predecessors.clear(); for (Dependency in : next.getIncomings()) { predecessors.add(in.getSource()); } next = null; double efMax = Double.MIN_VALUE; for (Step s : predecessors) { // it's the same as the partial critical path double ef = s.getAttribute(EARLY_FINISH + iterationId); if (ef > efMax) { efMax = ef; next = s; } } } return collector.getResults(); }
From source file:com.evolveum.icf.dummy.resource.DummyObject.java
public void replaceAttributeValues(String name, Collection<Object> values) throws SchemaViolationException, ConnectException, FileNotFoundException { checkModifyBreak();//from w w w. j a v a2s . c o m Set<Object> currentValues = attributes.get(name); if (currentValues == null) { currentValues = new HashSet<Object>(); attributes.put(name, currentValues); } else { currentValues.clear(); } currentValues.addAll(values); checkSchema(name, values, "replace"); recordModify(); }
From source file:org.apache.hadoop.raid.StripeReader.java
/** * Builds (codec.stripeLength + codec.parityLength) inputs given some erased locations. * Outputs:/* w w w . j a v a2 s . c om*/ * - the array of input streams @param inputs * - the list of erased locations @param erasedLocations. * - the list of locations that are not read @param locationsToNotRead. */ public InputStream[] buildInputs(FileSystem srcFs, Path srcFile, FileStatus srcStat, FileSystem parityFs, Path parityFile, FileStatus parityStat, int stripeIdx, long offsetInBlock, List<Integer> erasedLocations, Set<Integer> locationsToNotRead, ErasureCode code) throws IOException { InputStream[] inputs = new InputStream[codec.stripeLength + codec.parityLength]; boolean redo = false; do { locationsToNotRead.clear(); List<Integer> locationsToRead = code.locationsToReadForDecode(erasedLocations); for (int i = 0; i < inputs.length; i++) { boolean isErased = (erasedLocations.indexOf(i) != -1); boolean shouldRead = (locationsToRead.indexOf(i) != -1); try { InputStream stm = null; if (isErased || !shouldRead) { if (isErased) { LOG.info("Location " + i + " is erased, using zeros"); } else { LOG.info("Location " + i + " need not be read, using zeros"); } locationsToNotRead.add(i); stm = new RaidUtils.ZeroInputStream(srcStat.getBlockSize() * ((i < codec.parityLength) ? stripeIdx * codec.parityLength + i : stripeIdx * codec.stripeLength + i - codec.parityLength)); } else { stm = buildOneInput(i, offsetInBlock, srcFs, srcFile, srcStat, parityFs, parityFile, parityStat); } inputs[i] = stm; } catch (IOException e) { if (e instanceof BlockMissingException || e instanceof ChecksumException) { erasedLocations.add(i); redo = true; RaidUtils.closeStreams(inputs); break; } else { throw e; } } } } while (redo); assert (locationsToNotRead.size() == codec.parityLength); return inputs; }
From source file:net.solarnetwork.central.dras.biz.dao.test.ibatis.DaoEventBizTest.java
@Test public void assignMembers() { setupTestLocation();/* w ww. ja v a 2s.c o m*/ setupTestProgram(TEST_PROGRAM_ID, TEST_PROGRAM_NAME); setupTestParticipant(); setupTestParticipantGroup(); setupTestEvent(TEST_EVENT_ID, TEST_PROGRAM_ID); // add participant to program Set<Long> memberIds = new HashSet<Long>(1); memberIds.add(TEST_PARTICIPANT_ID); programDao.assignParticipantMembers(TEST_PROGRAM_ID, memberIds, TEST_EFFECTIVE_ID); MembershipCommand participants = new MembershipCommand(); participants.getGroup().addAll(memberIds); // add participant to participant group participantGroupDao.assignParticipantMembers(TEST_PARTICIPANT_GROUP_ID, memberIds, TEST_EFFECTIVE_ID); memberIds.clear(); memberIds.add(TEST_PARTICIPANT_GROUP_ID); MembershipCommand groups = new MembershipCommand(); groups.getGroup().addAll(memberIds); // assign participant and group EffectiveCollection<Event, Member> result = eventBiz.assignMembers(TEST_EVENT_ID, participants, groups); assertNotNull(result); assertNotNull(result.getEffective()); assertNotNull(result.getObject()); assertEquals(TEST_EVENT_ID, result.getObject().getId()); assertNotNull(result.getCollection()); assertEquals(2, result.getCollection().size()); // we have Participant and ParticipantGroup objects Map<String, Collection<Long>> mapping = result.getMemberMap(); assertEquals(2, mapping.size()); Collection<Long> foundParticipants = mapping.get(Participant.class.getSimpleName()); assertNotNull(foundParticipants); assertEquals(1, foundParticipants.size()); Collection<Long> foundParticipantGroups = mapping.get(ParticipantGroup.class.getSimpleName()); assertNotNull(foundParticipantGroups); assertEquals(1, foundParticipantGroups.size()); assertTrue(foundParticipants.contains(TEST_PARTICIPANT_ID)); assertTrue(foundParticipantGroups.contains(TEST_PARTICIPANT_GROUP_ID)); }
From source file:com.evolveum.icf.dummy.resource.DummyObject.java
public void replaceAttributeValues(String name, Object... values) throws SchemaViolationException, ConnectException, FileNotFoundException { checkModifyBreak();/*from w ww. j ava2 s .c o m*/ Set<Object> currentValues = attributes.get(name); if (currentValues == null) { currentValues = new HashSet<Object>(); attributes.put(name, currentValues); } else { currentValues.clear(); } List<Object> valuesList = Arrays.asList(values); currentValues.addAll(valuesList); checkSchema(name, valuesList, "replace"); if (valuesList.isEmpty()) { attributes.remove(name); } recordModify(); }