List of usage examples for java.util EnumSet allOf
public static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType)
From source file:org.apache.sentry.policy.solr.TestSolrAuthorizationProviderGeneralCases.java
@Test public void testManager() throws Exception { Set<SolrModelAction> updateOnly = EnumSet.of(SolrModelAction.UPDATE); doTestAuthProviderOnCollection(SUB_MANAGER, COLL_PURCHASES, updateOnly); Set<SolrModelAction> allActions = EnumSet.allOf(SolrModelAction.class); doTestAuthProviderOnCollection(SUB_MANAGER, COLL_ANALYST1, allActions); doTestAuthProviderOnCollection(SUB_MANAGER, COLL_JRANALYST1, allActions); Set<SolrModelAction> queryUpdateOnly = EnumSet.of(QUERY, UPDATE); doTestAuthProviderOnCollection(SUB_MANAGER, COLL_TMP, queryUpdateOnly); Set<SolrModelAction> queryOnly = EnumSet.of(SolrModelAction.QUERY); doTestAuthProviderOnCollection(SUB_MANAGER, COLL_PURCHASES_PARTIAL, queryOnly); }
From source file:edu.cornell.kfs.module.receiptProcessing.batch.CsvBatchInputFileTypeBase.java
/** * build the csv header list base on provided csv enum class * // ww w. ja va2 s. c om * @return */ @SuppressWarnings("rawtypes") protected List<String> getCsvHeaderList() { List<String> headerList = new ArrayList<String>(); EnumSet<CSVEnum> enums = EnumSet.allOf((Class) csvEnumClass); for (Enum<CSVEnum> e : enums) { headerList.add(e.name()); } return headerList; }
From source file:org.apache.pulsar.proxy.server.WebServer.java
public void addServlet(String basePath, ServletHolder servletHolder, List<Pair<String, Object>> attributes) { Optional<String> existingPath = servletPaths.stream().filter(p -> p.startsWith(basePath)).findFirst(); if (existingPath.isPresent()) { throw new IllegalArgumentException(String.format("Cannot add servlet at %s, path %s already exists", basePath, existingPath.get())); }/* w w w . j av a 2 s . c o m*/ servletPaths.add(basePath); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath(basePath); context.addServlet(servletHolder, "/*"); for (Pair<String, Object> attribute : attributes) { context.setAttribute(attribute.getLeft(), attribute.getRight()); } if (config.isAuthenticationEnabled()) { FilterHolder filter = new FilterHolder(new AuthenticationFilter(authenticationService)); context.addFilter(filter, MATCH_ALL, EnumSet.allOf(DispatcherType.class)); } handlers.add(context); }
From source file:sx.blah.discord.handle.impl.obj.User.java
@Override public EnumSet<Permissions> getPermissionsForGuild(IGuild guild) { if (guild.getOwner().equals(this)) return EnumSet.allOf(Permissions.class); EnumSet<Permissions> permissions = EnumSet.noneOf(Permissions.class); getRolesForGuild(guild).forEach(role -> permissions.addAll(role.getPermissions())); return permissions; }
From source file:org.jboss.as.test.integration.logging.handlers.SocketHandlerTestCase.java
@Test public void testTcpSocket() throws Exception { // Create a TCP server and start it try (JsonLogServer server = JsonLogServer.createTcpServer(PORT)) { server.start(DFT_TIMEOUT); // Add the socket handler and test all levels final ModelNode socketHandlerAddress = addSocketHandler("test-log-server", null, null); checkLevelsLogged(server, EnumSet.allOf(Logger.Level.class), "Test TCP all levels."); // Change to only allowing INFO and higher messages executeOperation(Operations.createWriteAttributeOperation(socketHandlerAddress, "level", "INFO")); checkLevelsLogged(server,/*from w w w . ja v a 2 s . com*/ EnumSet.of(Logger.Level.INFO, Logger.Level.WARN, Logger.Level.ERROR, Logger.Level.FATAL), "Test TCP INFO and higher."); } }
From source file:uk.ac.ebi.atlas.model.ExperimentConfiguration.java
public ExperimentType getExperimentType() { Element configuration = document.getDocumentElement(); String type = configuration.getAttribute(EXPERIMENT_TYPE); if (StringUtils.isEmpty(type)) { throw new IllegalStateException(String.format("Missing %s attribute on root element of %s", EXPERIMENT_TYPE, xmlConfiguration.getFileName())); }/*from ww w . j a v a 2 s .co m*/ ExperimentType experimentType = ExperimentType.get(type); if (experimentType == null) { throw new IllegalStateException(String.format("Unknown %s attribute: \"%s\". Must be one of: [%s]", EXPERIMENT_TYPE, type, Joiner.on(", ").join(EnumSet.allOf(ExperimentType.class)))); } return experimentType; }
From source file:org.photovault.swingui.selection.PhotoSelectionController.java
/** Add a new view to those that are controlled by this object. TODO: Only the new view should be set to match the model. @param view The view to add./* w w w . j a v a 2s . c om*/ */ public void addView(PhotoSelectionView view) { views.add(view); for (PhotoInfoFields f : EnumSet.allOf(PhotoInfoFields.class)) { updateViews(null, f); } folderCtrl.setViews(views); tagCtrl.setViews(views); }
From source file:eu.itesla_project.modules.rules.CheckSecurityTool.java
@Override public void run(CommandLine line) throws Exception { OfflineConfig config = OfflineConfig.load(); Path caseFile = Paths.get(line.getOptionValue("case-file")); Objects.requireNonNull(caseFile); String rulesDbName = line.hasOption("rules-db-name") ? line.getOptionValue("rules-db-name") : OfflineConfig.DEFAULT_RULES_DB_NAME; RulesDbClientFactory rulesDbClientFactory = config.getRulesDbClientFactoryClass().newInstance(); String workflowId = line.getOptionValue("workflow"); RuleAttributeSet attributeSet = RuleAttributeSet.valueOf(line.getOptionValue("attribute-set")); double purityThreshold = line.hasOption("purity-threshold") ? Double.parseDouble(line.getOptionValue("purity-threshold")) : CheckSecurityCommand.DEFAULT_PURITY_THRESHOLD; Path outputCsvFile = null;//w ww. j a v a2 s . com if (line.hasOption("output-csv-file")) { outputCsvFile = Paths.get(line.getOptionValue("output-csv-file")); } Set<SecurityIndexType> securityIndexTypes = line.hasOption("security-index-types") ? Arrays.stream(line.getOptionValue("security-index-types").split(",")) .map(SecurityIndexType::valueOf).collect(Collectors.toSet()) : EnumSet.allOf(SecurityIndexType.class); final Set<String> contingencies = line.hasOption("contingencies") ? Arrays.stream(line.getOptionValue("contingencies").split(",")).collect(Collectors.toSet()) : null; try (RulesDbClient rulesDb = rulesDbClientFactory.create(rulesDbName)) { if (Files.isRegularFile(caseFile)) { System.out.println("loading case " + caseFile + "..."); // load the network Network network = Importers.loadNetwork(caseFile); if (network == null) { throw new RuntimeException("Case '" + caseFile + "' not found"); } network.getStateManager().allowStateMultiThreadAccess(true); System.out.println("checking rules..."); Map<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> checkStatusPerContingency = SecurityRuleUtil .checkRules(network, rulesDb, workflowId, attributeSet, securityIndexTypes, contingencies, purityThreshold); if (outputCsvFile == null) { prettyPrint(checkStatusPerContingency, securityIndexTypes); } else { writeCsv(checkStatusPerContingency, securityIndexTypes, outputCsvFile); } } else if (Files.isDirectory(caseFile)) { if (outputCsvFile == null) { throw new RuntimeException( "In case of multiple impact security checks, only output to csv file is supported"); } Map<String, Map<SecurityIndexId, SecurityRuleCheckStatus>> checkStatusPerBaseCase = Collections .synchronizedMap(new LinkedHashMap<>()); Importers.loadNetworks(caseFile, true, network -> { try { Map<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> checkStatusPerContingency = SecurityRuleUtil .checkRules(network, rulesDb, workflowId, attributeSet, securityIndexTypes, contingencies, purityThreshold); Map<SecurityIndexId, SecurityRuleCheckStatus> checkStatusMap = new HashMap<>(); for (Map.Entry<String, Map<SecurityIndexType, SecurityRuleCheckStatus>> entry : checkStatusPerContingency .entrySet()) { String contingencyId = entry.getKey(); for (Map.Entry<SecurityIndexType, SecurityRuleCheckStatus> entry1 : entry.getValue() .entrySet()) { SecurityIndexType type = entry1.getKey(); SecurityRuleCheckStatus status = entry1.getValue(); checkStatusMap.put(new SecurityIndexId(contingencyId, type), status); } } checkStatusPerBaseCase.put(network.getId(), checkStatusMap); } catch (Exception e) { LOGGER.error(e.toString(), e); } }, dataSource -> System.out.println("loading case " + dataSource.getBaseName() + "...")); writeCsv2(checkStatusPerBaseCase, outputCsvFile); } } }
From source file:org.jamwiki.parser.jflex.ImageLinkTag.java
/** * *//*from www . j a v a 2 s . c o m*/ private ImageMetadata parseImageParams(ParserInput parserInput, ParserOutput parserOutput, int mode, String paramText) throws ParserException { ImageMetadata imageMetadata = new ImageMetadata(); if (StringUtils.isBlank(paramText)) { return imageMetadata; } String[] tokens = paramText.split("\\|"); Matcher matcher; String caption = ""; tokenLoop: for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; if (StringUtils.isBlank(token)) { continue; } token = token.trim(); for (ImageBorderEnum border : EnumSet.allOf(ImageBorderEnum.class)) { // special case - for legacy reasons Mediawiki supports "thumbnail" instead of "thumb" if (StringUtils.equalsIgnoreCase(token, "thumbnail")) { token = "thumb"; } if (border.toString().equalsIgnoreCase(token)) { if (border == ImageBorderEnum.BORDER) { // border can be combined with frameless, so set a second attribute to track it imageMetadata.setBordered(true); if (imageMetadata.getBorder() == ImageBorderEnum.FRAMELESS) { continue tokenLoop; } } imageMetadata.setBorder(border); continue tokenLoop; } } for (ImageHorizontalAlignmentEnum horizontalAlignment : EnumSet .allOf(ImageHorizontalAlignmentEnum.class)) { if (horizontalAlignment.toString().equalsIgnoreCase(token)) { imageMetadata.setHorizontalAlignment(horizontalAlignment); continue tokenLoop; } } for (ImageVerticalAlignmentEnum verticalAlignment : EnumSet.allOf(ImageVerticalAlignmentEnum.class)) { if (verticalAlignment.toString().equalsIgnoreCase(token)) { imageMetadata.setVerticalAlignment(verticalAlignment); continue tokenLoop; } } // if none of the above tokens matched then check for size or caption if (token.toLowerCase().endsWith("px")) { matcher = IMAGE_SIZE_PATTERN.matcher(token); if (matcher.find()) { String maxWidth = matcher.group(1); if (!StringUtils.isBlank(maxWidth)) { imageMetadata.setMaxWidth(Integer.valueOf(maxWidth)); } String maxHeight = matcher.group(2); if (!StringUtils.isBlank(maxHeight)) { imageMetadata.setMaxHeight(Integer.valueOf(maxHeight)); } continue tokenLoop; } } if (token.toLowerCase().startsWith("alt")) { matcher = IMAGE_ALT_PATTERN.matcher(token); if (matcher.find()) { imageMetadata.setAlt(matcher.group(1).trim()); continue tokenLoop; } } if (token.toLowerCase().startsWith("link")) { matcher = IMAGE_LINK_PATTERN.matcher(token); if (matcher.find()) { imageMetadata.setLink(matcher.group(1).trim()); continue tokenLoop; } } // this is a bit hackish. string together any remaining content as a possible // caption, then parse it and strip out anything after the first pipe character caption += (StringUtils.isBlank(caption)) ? token : "|" + token; } // parse the caption and strip anything prior to the last "|" to handle syntax of // the form "[[File:Example.gif|caption1|caption2]]". if (!StringUtils.isBlank(caption)) { caption = JFlexParserUtil.parseFragment(parserInput, parserOutput, caption, mode); int pos = caption.indexOf('|'); if (pos != -1) { caption = (pos >= (caption.length() - 1)) ? " " : caption.substring(pos + 1); } imageMetadata.setCaption(caption); } if (imageMetadata.getVerticalAlignment() != ImageVerticalAlignmentEnum.NOT_SPECIFIED && (imageMetadata.getBorder() == ImageBorderEnum.THUMB || imageMetadata.getBorder() == ImageBorderEnum.FRAME)) { // per spec, vertical alignment can only be set for non-thumb and non-frame imageMetadata.setVerticalAlignment(ImageVerticalAlignmentEnum.NOT_SPECIFIED); } if (imageMetadata.getBorder() == ImageBorderEnum.THUMB || imageMetadata.getBorder() == ImageBorderEnum.FRAME) { // per spec, link can only be set for non-thumb and non-frame imageMetadata.setLink(null); } if (imageMetadata.getBorder() != ImageBorderEnum.THUMB && imageMetadata.getBorder() != ImageBorderEnum.FRAME && imageMetadata.getBorder() != ImageBorderEnum._GALLERY) { // per spec, captions are only displayed for thumbnails, framed images // and galleries, but the caption will be used as the alt and title for // other image types. if (!StringUtils.isBlank(imageMetadata.getCaption())) { // avoid double-escaping since the link builder escapes the title tag imageMetadata.setTitle(StringEscapeUtils.unescapeHtml4(imageMetadata.getCaption())); } if (imageMetadata.getAlt() == null) { // avoid double-escaping since the link builder escapes the alt tag imageMetadata.setAlt(StringEscapeUtils.unescapeHtml4(imageMetadata.getCaption())); } imageMetadata.setCaption(null); } if (imageMetadata.getBorder() == ImageBorderEnum.FRAME) { // per spec, frame cannot be resized imageMetadata.setMaxHeight(-1); imageMetadata.setMaxWidth(-1); } if ((imageMetadata.getBorder() == ImageBorderEnum.THUMB || imageMetadata.getBorder() == ImageBorderEnum.FRAMELESS) && imageMetadata.getMaxWidth() <= 0) { imageMetadata.setMaxWidth(DEFAULT_THUMBNAIL_WIDTH); } if (imageMetadata.getBordered() && (imageMetadata.getBorder() != ImageBorderEnum.BORDER && imageMetadata.getBorder() != ImageBorderEnum.FRAMELESS)) { // thumb, frame, etc handle borders differently imageMetadata.setBordered(false); } if (imageMetadata.getBorder() == ImageBorderEnum._GALLERY) { // internal use only imageMetadata.setHorizontalAlignment(ImageHorizontalAlignmentEnum.CENTER); // 10 pixels is for padding imageMetadata.setGalleryHeight(imageMetadata.getMaxHeight() + 10); // galleries use either the file name or nothing as the alt tag if (!StringUtils.isBlank(imageMetadata.getCaption())) { imageMetadata.setAlt(""); } } return imageMetadata; }
From source file:org.apache.hadoop.hdfs.security.token.block.TestBlockToken.java
private void tokenGenerationAndVerification(BlockTokenSecretManager master, BlockTokenSecretManager slave) throws Exception { // single-mode tokens for (BlockTokenSecretManager.AccessMode mode : BlockTokenSecretManager.AccessMode.values()) { // generated by master Token<BlockTokenIdentifier> token1 = master.generateToken(block1, EnumSet.of(mode)); master.checkAccess(token1, null, block1, mode); slave.checkAccess(token1, null, block1, mode); // generated by slave Token<BlockTokenIdentifier> token2 = slave.generateToken(block2, EnumSet.of(mode)); master.checkAccess(token2, null, block2, mode); slave.checkAccess(token2, null, block2, mode); }//from ww w .ja v a2 s . c o m // multi-mode tokens Token<BlockTokenIdentifier> mtoken = master.generateToken(block3, EnumSet.allOf(BlockTokenSecretManager.AccessMode.class)); for (BlockTokenSecretManager.AccessMode mode : BlockTokenSecretManager.AccessMode.values()) { master.checkAccess(mtoken, null, block3, mode); slave.checkAccess(mtoken, null, block3, mode); } }