List of usage examples for java.util EnumSet noneOf
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType)
From source file:com.couchbase.touchdb.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testPutAttachment() { TDBlobStore attachments = database.getAttachments(); // Put a revision that includes an _attachments dict: byte[] attach1 = "This is the body of attach1".getBytes(); String base64 = Base64.encodeBytes(attach1); Map<String, Object> attachment = new HashMap<String, Object>(); attachment.put("content_type", "text/plain"); attachment.put("data", base64); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", attachment); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("foo", 1); properties.put("bar", false); properties.put("_attachments", attachmentDict); TDStatus status = new TDStatus(); TDRevision rev1 = database.putRevision(new TDRevision(properties), null, false, status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); // Examine the attachment store: Assert.assertEquals(1, attachments.count()); // Get the revision: TDRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> expectAttachmentDict = new HashMap<String, Object>(); expectAttachmentDict.put("attach", innerDict); Assert.assertEquals(expectAttachmentDict, gotAttachmentDict); // Update the attachment directly: byte[] attachv2 = "Replaced body of attach".getBytes(); database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(), null, status);// w ww .j a v a 2s.c o m Assert.assertEquals(TDStatus.CONFLICT, status.getCode()); database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(), "1-bogus", status); Assert.assertEquals(TDStatus.CONFLICT, status.getCode()); TDRevision rev2 = database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(), rev1.getRevId(), status); Assert.assertEquals(TDStatus.CREATED, status.getCode()); Assert.assertEquals(rev1.getDocId(), rev2.getDocId()); Assert.assertEquals(2, rev2.getGeneration()); // Get the updated revision: TDRevision gotRev2 = database.getDocumentWithIDAndRev(rev2.getDocId(), rev2.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); attachmentDict = (Map<String, Object>) gotRev2.getProperties().get("_attachments"); innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "application/foo"); innerDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk="); innerDict.put("length", 23); innerDict.put("stub", true); innerDict.put("revpos", 2); expectAttachmentDict.put("attach", innerDict); Assert.assertEquals(expectAttachmentDict, attachmentDict); // Delete the attachment: database.updateAttachment("nosuchattach", null, null, rev2.getDocId(), rev2.getRevId(), status); Assert.assertEquals(TDStatus.NOT_FOUND, status.getCode()); database.updateAttachment("nosuchattach", null, null, "nosuchdoc", "nosuchrev", status); Assert.assertEquals(TDStatus.NOT_FOUND, status.getCode()); TDRevision rev3 = database.updateAttachment("attach", null, null, rev2.getDocId(), rev2.getRevId(), status); Assert.assertEquals(TDStatus.OK, status.getCode()); Assert.assertEquals(rev2.getDocId(), rev3.getDocId()); Assert.assertEquals(3, rev3.getGeneration()); // Get the updated revision: TDRevision gotRev3 = database.getDocumentWithIDAndRev(rev3.getDocId(), rev3.getRevId(), EnumSet.noneOf(TDDatabase.TDContentOptions.class)); attachmentDict = (Map<String, Object>) gotRev3.getProperties().get("_attachments"); Assert.assertNull(attachmentDict); database.close(); }
From source file:org.wso2.msf4j.swagger.ExtendedSwaggerReader.java
private Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean isSubresource, String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags, List<Parameter> parentParameters, Set<Class<?>> scannedResources) { Map<String, Tag> tags = new HashMap<>(); List<SecurityRequirement> securities = new ArrayList<>(); String[] consumes = new String[0]; String[] produces = new String[0]; final Set<Scheme> globalSchemes = EnumSet.noneOf(Scheme.class); Api api = cls.getAnnotation(Api.class); boolean hasPathAnnotation = (ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class) != null); boolean hasApiAnnotation = (api != null); boolean isApiHidden = hasApiAnnotation && api.hidden(); // class readable only if annotated with @Path or isSubresource, or and @Api not hidden boolean classReadable = (hasPathAnnotation || isSubresource) && !isApiHidden; // readable if classReadable or (scanAllResources true in config and @Api not hidden) boolean readable = classReadable || (!isApiHidden && config.isScanAllResources()); if (!readable) { return swagger; }//from ww w . j av a 2s. c o m // api readable only if @Api present; cannot be hidden because checked in classReadable. boolean apiReadable = hasApiAnnotation; if (apiReadable) { // the value will be used as a tag for 2.0 UNLESS a Tags annotation is present Set<String> tagStrings = extractTags(api); for (String tagString : tagStrings) { Tag tag = new Tag().name(tagString); tags.put(tagString, tag); } tags.keySet().forEach(tagName -> swagger.tag(tags.get(tagName))); if (!api.produces().isEmpty()) { produces = ReaderUtils.splitContentValues(new String[] { api.produces() }); } if (!api.consumes().isEmpty()) { consumes = ReaderUtils.splitContentValues(new String[] { api.consumes() }); } globalSchemes.addAll(parseSchemes(api.protocols())); Authorization[] authorizations = api.authorizations(); for (Authorization auth : authorizations) { if (auth.value() != null && !"".equals(auth.value())) { SecurityRequirement security = new SecurityRequirement(); security.setName(auth.value()); AuthorizationScope[] scopes = auth.scopes(); for (AuthorizationScope scope : scopes) { if (scope.scope() != null && !"".equals(scope.scope())) { security.addScope(scope.scope()); } } securities.add(security); } } } if (isSubresource) { if (parentTags != null) { tags.putAll(parentTags); } } // merge consumes, produces if (consumes.length == 0 && cls.getAnnotation(Consumes.class) != null) { consumes = ReaderUtils.splitContentValues(cls.getAnnotation(Consumes.class).value()); } if (produces.length == 0 && cls.getAnnotation(Produces.class) != null) { produces = ReaderUtils.splitContentValues(cls.getAnnotation(Produces.class).value()); } // look for method-level annotated properties // handle sub-resources by looking at return type final List<Parameter> globalParameters = new ArrayList<>(); // look for constructor-level annotated properties globalParameters.addAll(ReaderUtils.collectConstructorParameters(cls, swagger)); // look for field-level annotated properties globalParameters.addAll(ReaderUtils.collectFieldParameters(cls, swagger)); // build class/interface level @ApiResponse list ApiResponses classResponseAnnotation = ReflectionUtils.getAnnotation(cls, ApiResponses.class); List<ApiResponse> classApiResponses = new ArrayList<>(); if (classResponseAnnotation != null) { classApiResponses.addAll(Arrays.asList(classResponseAnnotation.value())); } // parse the method final javax.ws.rs.Path apiPath; if (basePath != null && !basePath.isEmpty()) { apiPath = new javax.ws.rs.Path() { @Override public Class<? extends Annotation> annotationType() { return javax.ws.rs.Path.class; } @Override public String value() { return basePath; } }; } else { apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class); } Method methods[] = cls.getMethods(); for (Method method : methods) { if (ReflectionUtils.isOverriddenMethod(method, cls)) { continue; } javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class); String operationPath = getPath(apiPath, methodPath, parentPath); Map<String, String> regexMap = new HashMap<>(); operationPath = PathUtils.parsePath(operationPath, regexMap); if (operationPath != null) { if (isIgnored(operationPath)) { continue; } final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class); String httpMethod = extractOperationMethod(apiOperation, method, SwaggerExtensions.chain()); Operation operation = null; if (apiOperation != null || config.isScanAllResources() || httpMethod != null || methodPath != null) { operation = parseMethod(cls, method, globalParameters, classApiResponses); } if (operation == null) { continue; } if (parentParameters != null) { for (Parameter param : parentParameters) { operation.parameter(param); } } operation.getParameters().stream().filter(param -> regexMap.get(param.getName()) != null) .forEach(param -> { String pattern = regexMap.get(param.getName()); param.setPattern(pattern); }); if (apiOperation != null) { for (Scheme scheme : parseSchemes(apiOperation.protocols())) { operation.scheme(scheme); } } if (operation.getSchemes() == null || operation.getSchemes().isEmpty()) { for (Scheme scheme : globalSchemes) { operation.scheme(scheme); } } String[] apiConsumes = consumes; if (parentConsumes != null) { Set<String> both = new HashSet<>(Arrays.asList(apiConsumes)); both.addAll(new HashSet<>(Arrays.asList(parentConsumes))); if (operation.getConsumes() != null) { both.addAll(new HashSet<>(operation.getConsumes())); } apiConsumes = both.toArray(new String[both.size()]); } String[] apiProduces = produces; if (parentProduces != null) { Set<String> both = new HashSet<>(Arrays.asList(apiProduces)); both.addAll(new HashSet<>(Arrays.asList(parentProduces))); if (operation.getProduces() != null) { both.addAll(new HashSet<>(operation.getProduces())); } apiProduces = both.toArray(new String[both.size()]); } final Class<?> subResource = getSubResourceWithJaxRsSubresourceLocatorSpecs(method); if (subResource != null && !scannedResources.contains(subResource)) { scannedResources.add(subResource); read(subResource, operationPath, httpMethod, true, apiConsumes, apiProduces, tags, operation.getParameters(), scannedResources); // remove the sub resource so that it can visit it later in another path // but we have a room for optimization in the future to reuse the scanned result // by caching the scanned resources in the reader instance to avoid actual scanning // the the resources again scannedResources.remove(subResource); } // can't continue without a valid http method httpMethod = httpMethod == null ? parentMethod : httpMethod; if (httpMethod != null) { if (apiOperation != null) { for (String tag : apiOperation.tags()) { if (!"".equals(tag)) { operation.tag(tag); swagger.tag(new Tag().name(tag)); } } operation.getVendorExtensions() .putAll(BaseReaderUtils.parseExtensions(apiOperation.extensions())); } if (operation.getConsumes() == null) { for (String mediaType : apiConsumes) { operation.consumes(mediaType); } } if (operation.getProduces() == null) { for (String mediaType : apiProduces) { operation.produces(mediaType); } } if (operation.getTags() == null) { for (String tagString : tags.keySet()) { operation.tag(tagString); } } // Only add global @Api securities if operation doesn't already have more specific securities if (operation.getSecurity() == null) { for (SecurityRequirement security : securities) { operation.security(security); } } Path path = swagger.getPath(operationPath); if (path == null) { path = new Path(); swagger.path(operationPath, path); } path.set(httpMethod, operation); readImplicitParameters(method, operation); } } } return swagger; }
From source file:com.couchbase.cblite.testapp.tests.Attachments.java
@SuppressWarnings("unchecked") public void testPutAttachment() { CBLBlobStore attachments = database.getAttachments(); // Put a revision that includes an _attachments dict: byte[] attach1 = "This is the body of attach1".getBytes(); String base64 = Base64.encodeBytes(attach1); Map<String, Object> attachment = new HashMap<String, Object>(); attachment.put("content_type", "text/plain"); attachment.put("data", base64); Map<String, Object> attachmentDict = new HashMap<String, Object>(); attachmentDict.put("attach", attachment); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("foo", 1); properties.put("bar", false); properties.put("_attachments", attachmentDict); CBLStatus status = new CBLStatus(); CBLRevision rev1 = database.putRevision(new CBLRevision(properties), null, false, status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); // Examine the attachment store: Assert.assertEquals(1, attachments.count()); // Get the revision: CBLRevision gotRev1 = database.getDocumentWithIDAndRev(rev1.getDocId(), rev1.getRevId(), EnumSet.noneOf(CBLDatabase.TDContentOptions.class)); Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments"); Map<String, Object> innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "text/plain"); innerDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE="); innerDict.put("length", 27); innerDict.put("stub", true); innerDict.put("revpos", 1); Map<String, Object> expectAttachmentDict = new HashMap<String, Object>(); expectAttachmentDict.put("attach", innerDict); Assert.assertEquals(expectAttachmentDict, gotAttachmentDict); // Update the attachment directly: byte[] attachv2 = "Replaced body of attach".getBytes(); database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(), null, status);//w w w . j av a2s .c o m Assert.assertEquals(CBLStatus.CONFLICT, status.getCode()); database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(), "1-bogus", status); Assert.assertEquals(CBLStatus.CONFLICT, status.getCode()); CBLRevision rev2 = database.updateAttachment("attach", new ByteArrayInputStream(attachv2), "application/foo", rev1.getDocId(), rev1.getRevId(), status); Assert.assertEquals(CBLStatus.CREATED, status.getCode()); Assert.assertEquals(rev1.getDocId(), rev2.getDocId()); Assert.assertEquals(2, rev2.getGeneration()); // Get the updated revision: CBLRevision gotRev2 = database.getDocumentWithIDAndRev(rev2.getDocId(), rev2.getRevId(), EnumSet.noneOf(CBLDatabase.TDContentOptions.class)); attachmentDict = (Map<String, Object>) gotRev2.getProperties().get("_attachments"); innerDict = new HashMap<String, Object>(); innerDict.put("content_type", "application/foo"); innerDict.put("digest", "sha1-mbT3208HI3PZgbG4zYWbDW2HsPk="); innerDict.put("length", 23); innerDict.put("stub", true); innerDict.put("revpos", 2); expectAttachmentDict.put("attach", innerDict); Assert.assertEquals(expectAttachmentDict, attachmentDict); // Delete the attachment: database.updateAttachment("nosuchattach", null, null, rev2.getDocId(), rev2.getRevId(), status); Assert.assertEquals(CBLStatus.NOT_FOUND, status.getCode()); database.updateAttachment("nosuchattach", null, null, "nosuchdoc", "nosuchrev", status); Assert.assertEquals(CBLStatus.NOT_FOUND, status.getCode()); CBLRevision rev3 = database.updateAttachment("attach", null, null, rev2.getDocId(), rev2.getRevId(), status); Assert.assertEquals(CBLStatus.OK, status.getCode()); Assert.assertEquals(rev2.getDocId(), rev3.getDocId()); Assert.assertEquals(3, rev3.getGeneration()); // Get the updated revision: CBLRevision gotRev3 = database.getDocumentWithIDAndRev(rev3.getDocId(), rev3.getRevId(), EnumSet.noneOf(CBLDatabase.TDContentOptions.class)); attachmentDict = (Map<String, Object>) gotRev3.getProperties().get("_attachments"); Assert.assertNull(attachmentDict); database.close(); }
From source file:se.trixon.filebydate.Operation.java
private boolean generateFileList() { mListener.onOperationLog(""); mListener.onOperationLog(Dict.GENERATING_FILELIST.toString()); PathMatcher pathMatcher = mProfile.getPathMatcher(); EnumSet<FileVisitOption> fileVisitOptions = EnumSet.noneOf(FileVisitOption.class); if (mProfile.isFollowLinks()) { fileVisitOptions = EnumSet.of(FileVisitOption.FOLLOW_LINKS); }//from ww w.ja va 2s . co m File file = mProfile.getSourceDir(); if (file.isDirectory()) { FileVisitor fileVisitor = new FileVisitor(pathMatcher, mFiles, this); try { if (mProfile.isRecursive()) { Files.walkFileTree(file.toPath(), fileVisitOptions, Integer.MAX_VALUE, fileVisitor); } else { Files.walkFileTree(file.toPath(), fileVisitOptions, 1, fileVisitor); } if (fileVisitor.isInterrupted()) { return false; } } catch (IOException ex) { Xlog.e(getClass(), ex.getLocalizedMessage()); } } else if (file.isFile() && pathMatcher.matches(file.toPath().getFileName())) { mFiles.add(file); } if (mFiles.isEmpty()) { mListener.onOperationLog(Dict.FILELIST_EMPTY.toString()); } else { Collections.sort(mFiles); } return true; }
From source file:org.mozilla.gecko.home.HomeFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { // onContextItemSelected() is first dispatched to the activity and // then dispatched to its fragments. Since fragments cannot "override" // menu item selection handling, it's better to avoid menu id collisions // between the activity and its fragments. ContextMenuInfo menuInfo = item.getMenuInfo(); if (!(menuInfo instanceof HomeContextMenuInfo)) { return false; }/*from ww w . ja va 2 s . co m*/ final HomeContextMenuInfo info = (HomeContextMenuInfo) menuInfo; final Context context = getActivity(); final int itemId = item.getItemId(); // Track the menu action. We don't know much about the context, but we can use this to determine // the frequency of use for various actions. Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.CONTEXT_MENU, getResources().getResourceEntryName(itemId)); if (itemId == R.id.home_copyurl) { if (info.url == null) { Log.e(LOGTAG, "Can't copy address because URL is null"); return false; } Clipboard.setText(info.url); return true; } if (itemId == R.id.home_share) { if (info.url == null) { Log.e(LOGTAG, "Can't share because URL is null"); return false; } else { GeckoAppShell.openUriExternal(info.url, SHARE_MIME_TYPE, "", "", Intent.ACTION_SEND, info.getDisplayTitle()); // Context: Sharing via chrome homepage contextmenu list (home session should be active) Telemetry.sendUIEvent(TelemetryContract.Event.SHARE, TelemetryContract.Method.LIST); return true; } } if (itemId == R.id.home_add_to_launcher) { if (info.url == null) { Log.e(LOGTAG, "Can't add to home screen because URL is null"); return false; } // Fetch an icon big enough for use as a home screen icon. Favicons.getPreferredSizeFaviconForPage(context, info.url, new GeckoAppShell.CreateShortcutFaviconLoadedListener(info.url, info.getDisplayTitle())); return true; } if (itemId == R.id.home_open_private_tab || itemId == R.id.home_open_new_tab) { if (info.url == null) { Log.e(LOGTAG, "Can't open in new tab because URL is null"); return false; } // Some pinned site items have "user-entered" urls. URLs entered in // the PinSiteDialog are wrapped in a special URI until we can get a // valid URL. If the url is a user-entered url, decode the URL // before loading it. final String url = StringUtils.decodeUserEnteredUrl( info.isInReadingList() ? ReaderModeUtils.getAboutReaderForUrl(info.url) : info.url); final EnumSet<OnUrlOpenInBackgroundListener.Flags> flags = EnumSet .noneOf(OnUrlOpenInBackgroundListener.Flags.class); if (item.getItemId() == R.id.home_open_private_tab) { flags.add(OnUrlOpenInBackgroundListener.Flags.PRIVATE); } mUrlOpenInBackgroundListener.onUrlOpenInBackground(url, flags); Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.CONTEXT_MENU); return true; } if (itemId == R.id.home_edit_bookmark) { // UI Dialog associates to the activity context, not the applications'. new EditBookmarkDialog(context).show(info.url); return true; } if (itemId == R.id.home_remove) { // For Top Sites grid items, position is required in case item is Pinned. final int position = info instanceof TopSitesGridContextMenuInfo ? info.position : -1; (new RemoveItemByUrlTask(context, info.url, info.itemType, position)).execute(); return true; } return false; }
From source file:com.netflix.genie.server.repository.jpa.TestClusterSpecs.java
/** * Test the find specification./* w w w . j a v a 2 s. c om*/ */ @Test public void testFindEmptyStatuses() { final Specification<Cluster> spec = ClusterSpecs.find(NAME, EnumSet.noneOf(ClusterStatus.class), TAGS, MIN_UPDATE_TIME, MAX_UPDATE_TIME); spec.toPredicate(this.root, this.cq, this.cb); Mockito.verify(this.cb, Mockito.times(1)).like(this.root.get(Cluster_.name), NAME); Mockito.verify(this.cb, Mockito.times(1)).greaterThanOrEqualTo(this.root.get(Cluster_.updated), new Date(MIN_UPDATE_TIME)); Mockito.verify(this.cb, Mockito.times(1)).lessThan(this.root.get(Cluster_.updated), new Date(MAX_UPDATE_TIME)); for (final String tag : TAGS) { Mockito.verify(this.cb, Mockito.times(1)).isMember(tag, this.root.get(Cluster_.tags)); } for (final ClusterStatus status : STATUSES) { Mockito.verify(this.cb, Mockito.never()).equal(this.root.get(Cluster_.status), status); } }
From source file:net.iaeste.iws.core.transformers.CSVTransformer.java
static void transformStudyLevels(final Map<String, String> errors, final Verifiable obj, final OfferFields field, final CSVRecord record) { final Set<StudyLevel> value = EnumSet.noneOf(StudyLevel.class); final Boolean beginning = convertBoolean(record.get(STUDY_COMPLETED_BEGINNING.getField())); final Boolean middle = convertBoolean(record.get(STUDY_COMPLETED_MIDDLE.getField())); final Boolean end = convertBoolean(record.get(STUDY_COMPLETED_END.getField())); if (!beginning && !middle && !end) { errors.put(field.getField(), "No StudyLevel defined."); } else {//from ww w . j a v a2 s.c o m if (beginning) { value.add(StudyLevel.B); } if (middle) { value.add(StudyLevel.M); } if (end) { value.add(StudyLevel.E); } } invokeMethodOnObject(errors, obj, field, value); }
From source file:org.talend.dataprep.quality.AnalyzerService.java
/** * Build a {@link Analyzer} to analyze records with columns (in <code>columns</code>). <code>settings</code> give * all the wanted analysis settings for the analyzer. * * @param columns A list of columns, may be null or empty. * @param settings A varargs with {@link Analysis}. Duplicates are possible in varargs but will be considered only * once./*from w ww. j av a2 s.co m*/ * @return A ready to use {@link Analyzer}. */ public Analyzer<Analyzers.Result> build(List<ColumnMetadata> columns, Analysis... settings) { if (columns == null || columns.isEmpty()) { return Analyzers.with(NullAnalyzer.INSTANCE); } // Get all needed analysis final Set<Analysis> all = EnumSet.noneOf(Analysis.class); for (Analysis setting : settings) { if (setting != null) { all.add(setting); all.addAll(Arrays.asList(setting.dependencies)); } } if (all.isEmpty()) { return Analyzers.with(NullAnalyzer.INSTANCE); } // Column types DataTypeEnum[] types = TypeUtils.convert(columns); // Semantic domains List<String> domainList = columns.stream() // .map(ColumnMetadata::getDomain) // .map(d -> StringUtils.isBlank(d) ? SemanticCategoryEnum.UNKNOWN.getId() : d) // .collect(Collectors.toList()); final String[] domains = domainList.toArray(new String[domainList.size()]); // Build all analyzers List<Analyzer> analyzers = new ArrayList<>(); for (Analysis setting : settings) { switch (setting) { case SEMANTIC: final SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(builder); semanticAnalyzer.setLimit(Integer.MAX_VALUE); analyzers.add(semanticAnalyzer); break; case HISTOGRAM: analyzers.add(new StreamDateHistogramAnalyzer(columns, types, dateParser)); analyzers.add(new StreamNumberHistogramAnalyzer(types)); break; case QUALITY: final DataTypeQualityAnalyzer dataTypeQualityAnalyzer = new DataTypeQualityAnalyzer(types); columns.forEach(c -> dataTypeQualityAnalyzer .addCustomDateTimePattern(RowMetadataUtils.getMostUsedDatePattern(c))); analyzers.add(new ValueQualityAnalyzer(dataTypeQualityAnalyzer, new SemanticQualityAnalyzer(builder, domains, false), true)); // NOSONAR break; case CARDINALITY: analyzers.add(new CardinalityAnalyzer()); break; case PATTERNS: analyzers.add(buildPatternAnalyzer(columns)); break; case LENGTH: analyzers.add(new TextLengthAnalyzer()); break; case QUANTILES: boolean acceptQuantiles = false; for (DataTypeEnum type : types) { if (type == DataTypeEnum.INTEGER || type == DataTypeEnum.DOUBLE) { acceptQuantiles = true; break; } } if (acceptQuantiles) { analyzers.add(new QuantileAnalyzer(types)); } break; case SUMMARY: analyzers.add(new SummaryAnalyzer(types)); break; case TYPE: boolean shouldUseTypeAnalysis = true; for (Analysis analysis : settings) { if (analysis == Analysis.QUALITY) { shouldUseTypeAnalysis = false; break; } } if (shouldUseTypeAnalysis) { final List<String> mostUsedDatePatterns = getMostUsedDatePatterns(columns); analyzers.add(new DataTypeAnalyzer(mostUsedDatePatterns)); } else { LOGGER.warn("Disabled {} analysis (conflicts with {}).", setting, Analysis.QUALITY); } break; case FREQUENCY: analyzers.add(new DataTypeFrequencyAnalyzer()); break; default: throw new IllegalArgumentException("Missing support for '" + setting + "'."); } } // Merge all analyzers into one final Analyzer<Analyzers.Result> analyzer = Analyzers .with(analyzers.toArray(new Analyzer[analyzers.size()])); analyzer.init(); if (LOGGER.isDebugEnabled()) { // Wrap analyzer for usage monitoring (to diagnose non-closed analyzer issues). return new ResourceMonitoredAnalyzer(analyzer); } else { return analyzer; } }
From source file:de.schildbach.pte.AbstractNavitiaProvider.java
private Location parsePlace(JSONObject location, PlaceType placeType) throws IOException { try {/* w ww.j a va 2 s . c o m*/ final LocationType type = getLocationType(placeType); String id = null; if (placeType != PlaceType.ADDRESS && placeType != PlaceType.POI) id = location.getString("id"); final JSONObject coord = location.getJSONObject("coord"); final Point point = parseCoord(coord); final String name = getLocationName(location.getString("name")); String place = null; if (location.has("administrative_regions")) { JSONArray admin = location.getJSONArray("administrative_regions"); if (admin.length() > 0) place = Strings.emptyToNull(admin.getJSONObject(0).optString("name")); } Set<Product> products = null; if (location.has("stop_area") && location.getJSONObject("stop_area").has("physical_modes")) { products = EnumSet.noneOf(Product.class); JSONArray physicalModes = location.getJSONObject("stop_area").getJSONArray("physical_modes"); for (int i = 0; i < physicalModes.length(); i++) { JSONObject mode = physicalModes.getJSONObject(i); Product product = parseLineProductFromMode(mode.getString("id")); if (product != null) products.add(product); } } return new Location(type, id, point, place, name, products); } catch (final JSONException jsonExc) { throw new ParserException(jsonExc); } }
From source file:net.sourceforge.pmd.lang.java.rule.codestyle.UnnecessaryModifierRule.java
@Override public Object visit(ASTFieldDeclaration node, Object data) { Set<Modifier> unnecessary = EnumSet.noneOf(Modifier.class); if (node.isSyntacticallyPublic()) { unnecessary.add(Modifier.PUBLIC); }/* w w w . ja va 2 s . co m*/ if (node.isSyntacticallyStatic()) { unnecessary.add(Modifier.STATIC); } if (node.isSyntacticallyFinal()) { unnecessary.add(Modifier.FINAL); } checkDeclarationInInterfaceType(data, node, unnecessary); return data; }