List of usage examples for java.util Collections EMPTY_SET
Set EMPTY_SET
To view the source code for java.util Collections EMPTY_SET.
Click Source Link
From source file:dk.dma.ais.abnormal.analyzer.analysis.CloseEncounterAnalysis.java
/** * In the set of candidateTracks: find the candidateTracks which are near to the nearToTrack - with 'near' * defined as/* ww w . j a va2s. c om*/ * * - last reported position timestamp within +/- 1 minute of nearToTrack's * - last reported position within 1 nm of nearToTrack * * @param candidateTracks the set of candidate candidateTracks to search among. * @param nearToTrack the nearToTrack to find other near-by candidateTracks for. * @return the set of nearby candidateTracks */ Set<Track> findNearByTracks(Collection<Track> candidateTracks, Track nearToTrack, int maxTimestampDeviationMillis, int maxDistanceDeviationMeters) { Set<Track> nearbyTracks = Collections.EMPTY_SET; TrackingReport positionReport = nearToTrack.getNewestTrackingReport(); if (positionReport != null) { final long timestamp = positionReport.getTimestamp(); nearbyTracks = candidateTracks.stream() .filter(candidateTrack -> candidateTrack.getMmsi() != nearToTrack.getMmsi() && candidateTrack.getTimeOfLastPositionReport() > 0L && candidateTrack.getTimeOfLastPositionReport() > timestamp - maxTimestampDeviationMillis && candidateTrack.getTimeOfLastPositionReport() < timestamp + maxTimestampDeviationMillis && candidateTrack.getPosition().distanceTo(nearToTrack.getPosition(), CoordinateSystem.CARTESIAN) < maxDistanceDeviationMeters) .collect(toSet()); } return nearbyTracks; }
From source file:org.wrml.server.WrmlServletTest.java
/** * This tests that the system returns an error when no 1) Accept Header is listed, and 2) No default is provided by * the engine/* w w w .j a va 2s. com*/ */ @Test public void requestNoAcceptHeaderNoDefault() throws ServletException, IOException { _Servlet.setEngine(_Engine); initMockApiNavigator(Method.Get, CAPRICA_SIX_ENDPOINT, CAPRICA_SCHEMA_URI); final Context context = _Engine.getContext(); final ApiNavigator apiNavigator = context.getApiLoader().getParentApiNavigator(CAPRICA_SIX_ENDPOINT); final Resource endpointResource = apiNavigator.getResource(CAPRICA_SIX_ENDPOINT); when(endpointResource.getResponseSchemaUris(Method.Get)).thenReturn(Collections.EMPTY_SET); MockHttpServletRequest request = new MockHttpServletRequest(); initMockHttpRequest(request, CAPRICA_SIX_ENDPOINT); request.setMethod(Method.Get.getProtocolGivenName()); // request.addHeader("Accept", null); HttpServletResponse response = mock(HttpServletResponse.class); ServletOutputStream out = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(out); _Servlet.service(request, response); verify(response, times(1)).setContentType(ContentType.TEXT_PLAIN.toString()); verify(response, times(1)).setStatus(HttpServletResponse.SC_BAD_REQUEST); //verify(response, times(0)).setContentLength(anyInt()); verify(response, times(1)).flushBuffer(); }
From source file:net.lightbody.bmp.proxy.jetty.util.URI.java
/** Get the uri query _parameters names. * @return Unmodifiable set of URI query _parameters names *//*from w w w. j a v a 2s . c om*/ public Set getParameterNames() { if (_parameters == null) return Collections.EMPTY_SET; return _parameters.keySet(); }
From source file:de.hybris.platform.classification.impl.DefaultClassificationClassesResolverStrategy.java
private <T extends ItemModel> Set<ClassificationClassModel> resolveClasses(final T item, final SuperCategoriesResolver<T> scr, final Collection<ClassificationSystemVersionModel> systemVersions) { validateParameterNotNull(item, "item must not be null!"); validateParameterNotNull(scr, "scr must not be null!"); validateParameterNotNull(systemVersions, "systemVersions must not be null!"); if (item instanceof ClassificationClassModel) { return Collections.singleton((ClassificationClassModel) item); } else {/*from w w w .j av a 2 s . c o m*/ final boolean includeOnlyClosestClasses = isIncludingOnlyClosestClasses(); Set<CategoryModel> touchedCategorieModels = null; Set<ClassificationClassModel> returnCCModels = null; final Map<ClassificationSystemVersionModel, Set<ClassificationClassModel>> permittedVersions = new HashMap<ClassificationSystemVersionModel, Set<ClassificationClassModel>>(); for (final ClassificationSystemVersionModel clSysVer : systemVersions) { permittedVersions.put(clSysVer, null); } Set<CategoryModel> currentCategoriesLevel = scr.getSuperCategories(item); while (currentCategoriesLevel != null && !currentCategoriesLevel.isEmpty() && !permittedVersions.isEmpty()) { Set<CategoryModel> nextCategoriesLevel = null; for (final CategoryModel category : currentCategoriesLevel) { // avoid endless turns due to cycles using a control set if (touchedCategorieModels == null) { touchedCategorieModels = new HashSet<CategoryModel>(); touchedCategorieModels.add(category); } else if (!touchedCategorieModels.add(category)) { continue; // skip this category since we've ran across it before } // filter by system if required if (category instanceof ClassificationClassModel) { final ClassificationClassModel cCcategory = (ClassificationClassModel) category; final ClassificationSystemVersionModel clVer = cCcategory.getCatalogVersion(); if (permittedVersions.containsKey(clVer)) { // only closest: needs some extra work to collect classes for that version on *this* level only ( see below ) if (includeOnlyClosestClasses) { Set<ClassificationClassModel> matchSet = permittedVersions.get(clVer); if (matchSet == null) { permittedVersions.put(clVer, matchSet = new LinkedHashSet<ClassificationClassModel>()); } matchSet.add(cCcategory); } // all: we can add them to the result right away else { if (returnCCModels == null) { returnCCModels = new LinkedHashSet<ClassificationClassModel>(); } returnCCModels.add(cCcategory); } } continue; // never add a classification class super category to next level } // no need to go further if at least one class has been found on this level else { if (nextCategoriesLevel == null) { nextCategoriesLevel = new LinkedHashSet<CategoryModel>(); } nextCategoriesLevel.addAll(category.getSupercategories()); } } if (includeOnlyClosestClasses) { /* * now prune all matching versions to avoid finding classes for them within next level */ for (final Iterator<Map.Entry<ClassificationSystemVersionModel, Set<ClassificationClassModel>>> it = permittedVersions .entrySet().iterator(); it.hasNext();) { if (returnCCModels == null) { returnCCModels = new LinkedHashSet<ClassificationClassModel>(); } final Map.Entry<ClassificationSystemVersionModel, Set<ClassificationClassModel>> mapentry = it .next(); if (mapentry.getValue() != null && !mapentry.getValue().isEmpty()) { returnCCModels.addAll(mapentry.getValue()); it.remove(); // stop looking for classes for this version ( since we just want 'closest' classes ) } } } currentCategoriesLevel = nextCategoriesLevel; } return returnCCModels == null ? Collections.EMPTY_SET : returnCCModels; } }
From source file:org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from w ww.j a va2 s. c o m protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { UrlMappingsHolder holder = WebUtils.lookupUrlMappings(getServletContext()); String uri = urlHelper.getPathWithinApplication(request); if (!"/".equals(uri) && noControllers() && noRegexMappings(holder)) { // not index request, no controllers, and no URL mappings for views, so it's not a Grails request processFilterChain(request, response, filterChain); return; } if (isUriExcluded(holder, uri)) { processFilterChain(request, response, filterChain); return; } if (LOG.isDebugEnabled()) { LOG.debug("Executing URL mapping filter..."); LOG.debug(holder); } GrailsWebRequest webRequest = (GrailsWebRequest) request .getAttribute(GrailsApplicationAttributes.WEB_REQUEST); HttpServletRequest currentRequest = webRequest.getCurrentRequest(); String version = findRequestedVersion(webRequest); UrlMappingInfo[] urlInfos = holder.matchAll(uri, currentRequest.getMethod(), version != null ? version : UrlMapping.ANY_VERSION); WrappedResponseHolder.setWrappedResponse(response); boolean dispatched = false; try { for (UrlMappingInfo info : urlInfos) { if (info != null) { Object redirectInfo = info.getRedirectInfo(); if (redirectInfo != null) { final Map redirectArgs; if (redirectInfo instanceof Map) { redirectArgs = (Map) redirectInfo; } else { redirectArgs = CollectionUtils.newMap("uri", redirectInfo); } GrailsParameterMap params = webRequest.getParams(); redirectArgs.put("params", params); redirectDynamicMethod.invoke(this, "redirect", new Object[] { redirectArgs }); dispatched = true; break; } // GRAILS-3369: The configure() will modify the // parameter map attached to the web request. So, // we need to clear it each time and restore the // original request parameters. webRequest.resetParams(); final String viewName; try { info.configure(webRequest); viewName = info.getViewName(); if (viewName == null && info.getURI() == null) { ControllerArtefactHandler.ControllerCacheKey featureId = getFeatureId(info); GrailsClass controller = application .getArtefactForFeature(ControllerArtefactHandler.TYPE, featureId); if (controller == null) { continue; } webRequest.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE, controller.getLogicalPropertyName(), WebRequest.SCOPE_REQUEST); webRequest.setAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS, controller, WebRequest.SCOPE_REQUEST); webRequest.setAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS_AVAILABLE, Boolean.TRUE, WebRequest.SCOPE_REQUEST); } } catch (Exception e) { if (e instanceof MultipartException) { reapplySitemesh(request); throw ((MultipartException) e); } LOG.error("Error when matching URL mapping [" + info + "]:" + e.getMessage(), e); continue; } dispatched = true; if (!WAR_DEPLOYED) { checkDevelopmentReloadingState(request); } request = checkMultipart(request); if (viewName == null || viewName.endsWith(GSP_SUFFIX) || viewName.endsWith(JSP_SUFFIX)) { if (info.isParsingRequest()) { webRequest.informParameterCreationListeners(); } String forwardUrl = WebUtils.forwardRequestForUrlMappingInfo(request, response, info); if (LOG.isDebugEnabled()) { LOG.debug("Matched URI [" + uri + "] to URL mapping [" + info + "], forwarding to [" + forwardUrl + "] with response [" + response.getClass() + "]"); } } else { if (!renderViewForUrlMappingInfo(request, response, info, viewName)) { dispatched = false; } } break; } } } finally { WrappedResponseHolder.setWrappedResponse(null); } if (!dispatched) { Set<HttpMethod> allowedHttpMethods = allowHeaderForWrongHttpMethod ? allowedMethods(holder, uri) : Collections.EMPTY_SET; if (allowedHttpMethods.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("No match found, processing remaining filter chain."); } processFilterChain(request, response, filterChain); } else { response.addHeader(HttpHeaders.ALLOW, DefaultGroovyMethods.join(allowedHttpMethods, ",")); response.sendError(HttpStatus.METHOD_NOT_ALLOWED.value()); } } }
From source file:org.apereo.services.persondir.support.ldap.LdapPersonAttributeDaoTest.java
public void testProperties() throws Exception { final LdapPersonAttributeDao impl = new LdapPersonAttributeDao(); assertEquals("", impl.getBaseDN()); impl.setBaseDN("BaseDN"); assertEquals("BaseDN", impl.getBaseDN()); impl.setBaseDN(null);/*w ww .j ava2 s. c om*/ assertEquals("", impl.getBaseDN()); assertNull(impl.getResultAttributeMapping()); final Map<String, Object> attrMap = new HashMap<>(); attrMap.put("mail", "email"); impl.setResultAttributeMapping(attrMap); final Map<String, Set<String>> expectedAttrMap = new HashMap<>(); expectedAttrMap.put("mail", Collections.singleton("email")); assertEquals(expectedAttrMap, impl.getResultAttributeMapping()); assertNull(impl.getContextSource()); impl.setContextSource(this.getContextSource()); assertEquals(this.getContextSource(), impl.getContextSource()); impl.setResultAttributeMapping(null); assertEquals(Collections.EMPTY_SET, impl.getPossibleUserAttributeNames()); impl.setResultAttributeMapping(attrMap); assertEquals(Collections.singleton("email"), impl.getPossibleUserAttributeNames()); }
From source file:org.jasig.services.persondir.support.ldap.LdapPersonAttributeDaoTest.java
public void testProperties() throws Exception { LdapPersonAttributeDao impl = new LdapPersonAttributeDao(); assertEquals("", impl.getBaseDN()); impl.setBaseDN("BaseDN"); assertEquals("BaseDN", impl.getBaseDN()); impl.setBaseDN(null);/*from w w w . j a va2 s . c o m*/ assertEquals("", impl.getBaseDN()); assertNull(impl.getResultAttributeMapping()); Map<String, Object> attrMap = new HashMap<String, Object>(); attrMap.put("mail", "email"); impl.setResultAttributeMapping(attrMap); Map<String, Set<String>> expectedAttrMap = new HashMap<String, Set<String>>(); expectedAttrMap.put("mail", Collections.singleton("email")); assertEquals(expectedAttrMap, impl.getResultAttributeMapping()); assertNull(impl.getContextSource()); impl.setContextSource(this.getContextSource()); assertEquals(this.getContextSource(), impl.getContextSource()); impl.setResultAttributeMapping(null); assertEquals(Collections.EMPTY_SET, impl.getPossibleUserAttributeNames()); impl.setResultAttributeMapping(attrMap); assertEquals(Collections.singleton("email"), impl.getPossibleUserAttributeNames()); }
From source file:org.archive.modules.extractor.ExtractorYoutubeFormatStreamTest.java
public void testDontExtract() throws URIException, UnsupportedEncodingException, IOException, InterruptedException { // not a youtube watch url so shouldProcess() will return false CrawlURI testUri = createTestUri("http://archive.org/watch?w=blah", getTestResourceFileName()); extractor.process(testUri);/*www . j a va 2s. c om*/ assertEquals(Collections.EMPTY_SET, testUri.getOutLinks()); }
From source file:org.archive.modules.extractor.ExtractorHTMLTest.java
/** * test to see if embedded <SCRIPT/> which writes script TYPE * creates any outlinks, e.g. "type='text/javascript'". * //from www . j av a2 s . c o m * [HER-1526] SCRIPT writing script TYPE common trigger of bogus links * (eg. 'text/javascript') * * @throws URIException */ public void testScriptTagWritingScriptType() throws URIException { CrawlURI curi = new CrawlURI(UURIFactory.getInstance("http://www.example.com/en/fiche/dossier/322/")); CharSequence cs = "<script type=\"text/javascript\">" + "var gaJsHost = ((\"https:\" == document.location.protocol) " + "? \"https://ssl.\" : \"http://www.\");" + " document.write(unescape(\"%3Cscript src='\" + gaJsHost + " + "\"google-analytics.com/ga.js' " + "type='text/javascript'%3E%3C/script%3E\"));" + "</script>"; getExtractor().extract(curi, cs); assertEquals(Collections.EMPTY_SET, curi.getOutLinks()); }
From source file:org.LexGrid.LexBIG.example.BuildTreeForCode.java
/** * The given path represents a multi-tier association with associated * concepts and targets. This method expands the association content and * adds results to the given tree item, recursing as necessary to process * each level in the path./*w w w .j av a2s . c om*/ * <p> * Nodes in the association act as the backbone for the display. For each * backbone node, additional children are resolved one level deep along with * an indication of further expandability. */ protected void addPathFromRoot(TreeItem ti, LexBIGService lbsvc, LexBIGServiceConvenienceMethods lbscm, String scheme, CodingSchemeVersionOrTag csvt, Association path, String[] associationsToNavigate, boolean associationsNavigatedFwd, Map<String, EntityDescription> codesToDescriptions) throws LBException { // First, add the branch point from the path ... ConceptReference branchRoot = path.getAssociationReference(); String branchCode = branchRoot.getCode(); String branchCodeDescription = codesToDescriptions.containsKey(branchCode) ? codesToDescriptions.get(branchCode).getContent() : getCodeDescription(lbsvc, scheme, csvt, branchCode); TreeItem branchPoint = new TreeItem(branchCode, branchCodeDescription); String branchNavText = getDirectionalLabel(lbscm, scheme, csvt, path, associationsNavigatedFwd); // Now process elements in the branch ... AssociatedConceptList concepts = path.getAssociatedConcepts(); for (int i = 0; i < concepts.getAssociatedConceptCount(); i++) { // Determine the next concept in the branch and // add a corresponding item to the tree. AssociatedConcept concept = concepts.getAssociatedConcept(i); String code = concept.getCode(); TreeItem branchItem = new TreeItem(code, getCodeDescription(concept)); branchPoint.addChild(branchNavText, branchItem); // Recurse to process the remainder of the backbone ... AssociationList nextLevel = concept.getSourceOf(); if (nextLevel != null) { if (nextLevel.getAssociationCount() != 0) { // Add immediate children of the focus code with an // indication of sub-nodes (+). Codes already // processed as part of the path are ignored since // they are handled through recursion. addChildren(branchItem, lbsvc, lbscm, scheme, csvt, code, codesToDescriptions.keySet(), associationsToNavigate, associationsNavigatedFwd); // More levels left to process ... for (int j = 0; j < nextLevel.getAssociationCount(); j++) addPathFromRoot(branchPoint, lbsvc, lbscm, scheme, csvt, nextLevel.getAssociation(j), associationsToNavigate, associationsNavigatedFwd, codesToDescriptions); } else { // End of the line ... // Always add immediate children of the focus code, // in this case with no exclusions since we are moving // beyond the path to root and allowed to duplicate // nodes that may have occurred in the path to root. addChildren(branchItem, lbsvc, lbscm, scheme, csvt, code, Collections.EMPTY_SET, associationsToNavigate, associationsNavigatedFwd); } } else { // Add immediate children of the focus code with an // indication of sub-nodes (+). Codes already // processed as part of the path are ignored since // they are handled through recursion. addChildren(branchItem, lbsvc, lbscm, scheme, csvt, code, codesToDescriptions.keySet(), associationsToNavigate, associationsNavigatedFwd); } } // Add immediate children of the node being processed, // and indication of sub-nodes. addChildren(branchPoint, lbsvc, lbscm, scheme, csvt, branchCode, codesToDescriptions.keySet(), associationsToNavigate, associationsNavigatedFwd); // Add the populated tree item to those tracked from root. ti.addChild(branchNavText, branchPoint); }