List of usage examples for java.util Set toArray
<T> T[] toArray(T[] a);
From source file:org.jenkinsci.plugins.reverse_proxy_auth.auth.DefaultReverseProxyAuthoritiesPopulator.java
/** * Obtains the authorities for the user who's directory entry is represented by * the supplied LdapUserDetails object./* ww w . j a v a2 s . c om*/ * * @param userDetails the user who's authorities are required * @return the set of roles granted to the user. */ public final GrantedAuthority[] getGrantedAuthorities(ReverseProxyUserDetails userDetails) { String username = userDetails.getUsername(); Set<GrantedAuthority> roles = getGroupMembershipRoles(username); Set<GrantedAuthority> extraRoles = getAdditionalRoles(userDetails); if (extraRoles != null) { roles.addAll(extraRoles); } if (defaultRole != null) { roles.add(defaultRole); } return roles.toArray(new GrantedAuthority[roles.size()]); }
From source file:com.ms.commons.udas.impl.commons.MemcachedKeyStore.java
/** * @param allStoedKey Key?//from ww w. j a v a 2 s. co m * @param oldIndexSize */ private void restoreToRemote(Set<String> allStoedKey) { // long t1 = System.currentTimeMillis(); // ??? String[] allStoredKeyArray = allStoedKey.toArray(new String[0]); // long t2 = System.currentTimeMillis(); // logger.warn(nameSpace + "restoreToRemote: toArray() " + (t2 - t1)); // int newBundleCount = calIndexSize(allStoredKeyArray); // ?N-1? // long t3 = System.currentTimeMillis(); for (int i = 0; i < newBundleCount - 1; i++) { // String[] newKeyArray = Arrays.copyOfRange(allStoredKeyArray, 0, key_bundle_size); String[] remainKeyArray = Arrays.copyOfRange(allStoredKeyArray, key_bundle_size, allStoredKeyArray.length); allStoredKeyArray = remainKeyArray; // ? Set<String> newSet = new HashSet<String>(Arrays.asList(newKeyArray)); store(createIndexKey(i), newSet); } // long t4 = System.currentTimeMillis(); // logger.warn(nameSpace + "restoreToRemote: copyOfRange() " + newBundleCount + " " + (t4 - t3)); // ? Set<String> newSet = new HashSet<String>(Arrays.asList(allStoredKeyArray)); store(createIndexKey(newBundleCount - 1), newSet); // ??Key int currentIndex = getIndexSize(); if (newBundleCount < currentIndex) { for (int i = newBundleCount; i < currentIndex; i++) { String keyId = createIndexKey(i); deleteFromMemcached(keyId); } } // Keysize store(memcached_key_second_index_size, newBundleCount); }
From source file:eu.itesla_project.online.tools.PrintOnlineWorkflowSimulationResultsTool.java
@Override public void run(CommandLine line) throws Exception { OnlineConfig config = OnlineConfig.load(); OnlineDb onlinedb = config.getOnlineDbFactoryClass().newInstance().create(); String workflowId = line.getOptionValue("workflow"); OnlineWorkflowResults wfResults = onlinedb.getResults(workflowId); if (wfResults != null) { if (!wfResults.getUnsafeContingencies().isEmpty()) { OnlineWorkflowParameters parameters = onlinedb.getWorkflowParameters(workflowId); SecurityIndexType[] securityIndexTypes = null; if (line.hasOption(SECURITY_INDEXES)) { Set<SecurityIndexType> securityIndexesTypeSet = Arrays .stream(line.getOptionValue(SECURITY_INDEXES).split(",")) .map(SecurityIndexType::valueOf).collect(Collectors.toSet()); securityIndexTypes = securityIndexesTypeSet .toArray(new SecurityIndexType[securityIndexesTypeSet.size()]); } else { securityIndexTypes = parameters.getSecurityIndexes() == null ? SecurityIndexType.values() : parameters.getSecurityIndexes() .toArray(new SecurityIndexType[parameters.getSecurityIndexes().size()]); }//from w w w . j a va 2s .co m Table table = new Table(securityIndexTypes.length + 2, BorderStyle.CLASSIC_WIDE); StringWriter content = new StringWriter(); CsvWriter cvsWriter = new CsvWriter(content, ','); String[] headers = new String[securityIndexTypes.length + 2]; int i = 0; table.addCell("Contingency", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "Contingency"; table.addCell("State", new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = "State"; for (SecurityIndexType securityIndexType : securityIndexTypes) { table.addCell(securityIndexType.getLabel(), new CellStyle(CellStyle.HorizontalAlign.center)); headers[i++] = securityIndexType.getLabel(); } cvsWriter.writeRecord(headers); for (String contingencyId : wfResults.getUnsafeContingencies()) { for (Integer stateId : wfResults.getUnstableStates(contingencyId)) { String[] values = new String[securityIndexTypes.length + 2]; i = 0; table.addCell(contingencyId); values[i++] = contingencyId; table.addCell(stateId.toString(), new CellStyle(CellStyle.HorizontalAlign.right)); values[i++] = stateId.toString(); HashMap<String, String> indexesValues = getIndexesValues( wfResults.getIndexesData(contingencyId, stateId), securityIndexTypes); for (SecurityIndexType securityIndexType : securityIndexTypes) { table.addCell(indexesValues.get(securityIndexType.getLabel()), new CellStyle(CellStyle.HorizontalAlign.center)); values[i++] = indexesValues.get(securityIndexType.getLabel()); } cvsWriter.writeRecord(values); } } cvsWriter.flush(); if (line.hasOption("csv")) System.out.println(content.toString()); else System.out.println(table.render()); cvsWriter.close(); } else System.out.println("\nNo contingencies requiring T-D simulation"); } else System.out.println("No results for this workflow"); onlinedb.close(); }
From source file:org.web4thejob.context.DefaultSessionContext.java
protected void loadBeanDefinitions(final XmlBeanDefinitionReader reader) throws UnsupportedEncodingException { final List<PanelDefinition> panels = ContextUtil.getDRS().getAll(PanelDefinition.class); final Set<Resource> resources = new HashSet<Resource>(); for (final PanelDefinition panel : panels) { final Resource resource = new ByteArrayResource(panel.getDefinition().getBytes("UTF-8"), panel.getName());/*from w w w .j ava 2s .c om*/ resources.add(resource); } reader.loadBeanDefinitions(resources.toArray(new Resource[resources.size()])); }
From source file:com.jim.im.topic.service.TopicServiceImpl.java
public void doSubscribe(Integer[] subscriberIds, Integer ownerId, String appId, String tenantId, TopicOwnerType topicOwnerType, TopicType topicType) throws ImParamException { TopicInfo topicInfo = getSingleTopicInfo(ownerId, appId, tenantId, topicOwnerType, topicType); if (topicInfo == null) throw new ImParamException( String.format("The subscribed topic(%s - %s - %s) was not exist.", ownerId, appId, tenantId)); Set<TopicSubMap> topicSubMaps = Sets.newHashSet(); for (Integer subscriberId : subscriberIds) { topicSubMaps.add(TopicSubMap.build(subscriberId, appId, tenantId, topicInfo.getName(), topicInfo.getId(), topicType)); }/*from w w w . j a v a 2s .c om*/ topicSubMapDao.addBatch(topicSubMaps.toArray(new TopicSubMap[0])); }
From source file:fr.gael.dhus.server.http.webapp.stub.controller.admin.AdminUserController.java
private List<UserData> convertUserToUserData(Iterator<User> it, int max) { int n = 0;//from ww w . j a v a 2s . c om List<UserData> user_data_list = new ArrayList<>(); while (n < max && it.hasNext()) { User user = it.next(); Set<AccessRestriction> restrictions = user.getRestrictions(); String reason = null; if (!restrictions.isEmpty()) { reason = restrictions.toArray(new AccessRestriction[restrictions.size()])[0].getBlockingReason(); } List<RoleData> roles = new ArrayList<>(); for (Role role : user.getRoles()) { roles.add(RoleData.valueOf(role.name())); } UserData user_data = new UserData(user.getUUID(), user.getUsername(), user.getFirstname(), user.getLastname(), user.getEmail(), roles, user.getPhone(), user.getAddress(), reason, user.getCountry(), user.getUsage(), user.getSubUsage(), user.getDomain(), user.getSubDomain()); user_data_list.add(user_data); n++; } return user_data_list; }
From source file:$.AppUiTopovMessageHandler.java
private void initLinkSet() { Set<Link> links = new HashSet<>(); for (Link link : linkService.getActiveLinks()) { links.add(link);/*w w w . j av a2 s. com*/ } linkSet = links.toArray(new Link[links.size()]); linkIndex = 0; log.debug("initialized link set to {}", linkSet.length); }
From source file:com.vmware.photon.controller.deployer.deployengine.DockerProvisioner.java
public String createContainer(String containerName, String containerImage, Integer cpuShares, Long memoryMb, Map<String, String> volumeBindings, Map<Integer, Integer> portBindings, String volumesFrom, Boolean isPrivileged, Map<String, String> environmentVariables, Boolean restart, Boolean useHostNetworkMode, String... command) { if (StringUtils.isBlank(containerImage)) { throw new IllegalArgumentException("containerImage field cannot be null or blank"); }/*from w w w . j av a 2s . com*/ if (StringUtils.isBlank(containerName)) { throw new IllegalArgumentException("containerName field cannot be null or blank"); } // Create container with image and name CreateContainerCmd createContainerCmd = this.getDockerClient().createContainerCmd(containerImage); createContainerCmd = createContainerCmd.withName(containerName); if (cpuShares != null) { createContainerCmd = createContainerCmd.withCpuShares(cpuShares); } // Expose container ports to host Ports containerPortBindings = getPortBindings(portBindings); if (containerPortBindings != null) { Set<ExposedPort> exposedPorts = containerPortBindings.getBindings().keySet(); createContainerCmd.withExposedPorts(exposedPorts.toArray(new ExposedPort[exposedPorts.size()])); createContainerCmd = createContainerCmd.withPortBindings(containerPortBindings); } // Add host volumes to be mounted into the container Bind[] containerVolumeBindings = getVolumeBindings(volumeBindings); if (containerVolumeBindings != null) { createContainerCmd = createContainerCmd.withBinds(containerVolumeBindings); } // Add environment variables String[] environmentVariablesList = getEnvironmentVariablesList(environmentVariables); if (environmentVariablesList != null) { createContainerCmd = createContainerCmd.withEnv(environmentVariablesList); } // Attach volumes from container (e.g. To link data container) if (volumesFrom != null) { createContainerCmd = createContainerCmd.withVolumesFrom(new VolumesFrom(volumesFrom)); } // Run in privileged mode if (isPrivileged != null) { createContainerCmd = createContainerCmd.withPrivileged(isPrivileged); } if (restart) { createContainerCmd = createContainerCmd.withRestartPolicy(RestartPolicy.alwaysRestart()); } // TODO(ysheng): this is a temporary solution to the port binding issue that Mgmt UI faces // when trying to bind port 80 with load balancer. In the long term, we should use a different // port for Mgmt UI other than 80. if (useHostNetworkMode) { createContainerCmd = createContainerCmd.withNetworkMode("host"); } // Run init process to start lightwave server and photon controller core containers, because both of them require // lightwave related processes to run as a part of the container as systemd services. if (containerName.equals(ContainersConfig.ContainerType.Lightwave.name()) || containerName.equals(ContainersConfig.ContainerType.PhotonControllerCore.name())) { // // Implement entrypoint and cmd as configuration for containers instead of special-casing Lightwave. // createContainerCmd = createContainerCmd.withEntrypoint(DeployerDefaults.LIGHTWAVE_ENTRYPOINT); } else { createContainerCmd = createContainerCmd.withEntrypoint(DeployerDefaults.DEFAULT_ENTRYPOINT); if (command != null) { createContainerCmd = createContainerCmd.withCmd(command); } } CreateContainerResponse container = createContainerCmd.exec(); return container.getId(); }
From source file:jp.co.nemuzuka.service.impl.MilestoneServiceImpl.java
@Override public void updateSortNum(String[] sortedKeyToString, String projectKeyToString) { //?Key?//from w w w .j av a 2s . co m Set<Key> keys = new LinkedHashSet<Key>(); for (String target : sortedKeyToString) { keys.add(Datastore.stringToKey(target)); } if (keys.size() == 0) { return; } Map<Key, MilestoneModel> map = milestoneDao.getMap(projectKeyToString, keys.toArray(new Key[0])); //1???? long sortNum = 1; for (Key target : keys) { MilestoneModel model = map.get(target); if (model != null) { model.setSortNum(sortNum); milestoneDao.put(model); sortNum++; } } }
From source file:ch.cyberduck.core.ftp.FTPClient.java
/** * Query the server for a supported feature, and returns its values (if any). * Caches the parsed response to avoid resending the command repeatedly. * * @return if the feature is present, returns the feature values (empty array if none) * Returns {@code null} if the feature is not found or the command failed. * Check {@link #getReplyCode()} or {@link #getReplyString()} if so. * @throws IOException/*from w ww . ja v a2 s . c o m*/ * @since 3.0 */ public String[] featureValues(String feature) throws IOException { if (!initFeatureMap()) { return null; } Set<String> entries = features.get(feature.toUpperCase(Locale.ROOT)); if (entries != null) { return entries.toArray(new String[entries.size()]); } return null; }