List of usage examples for java.util List addAll
boolean addAll(Collection<? extends E> c);
From source file:com.sunway.cbm.util.web.ReflectionUtils.java
public static List<Field> getDeclaredFields(Class<?> clazz) { List<Field> fieldRes = new ArrayList<Field>(); Class<?> superclass = clazz.getSuperclass(); if (superclass != null) { fieldRes.addAll(getDeclaredFields(superclass)); }//from w w w . ja v a 2s . c om Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { fieldRes.add(field); } return fieldRes; }
From source file:Lists.java
public static <T> List<T> addAll(List<T> list, List<T> toAdd) { switch (toAdd.size()) { case 0://from w ww . j av a 2s . com // No-op. return list; case 1: // Add one element. return add(list, toAdd.get(0)); default: // True list merge, result >= 2. switch (list.size()) { case 0: return new ArrayList<T>(toAdd); case 1: { List<T> result = new ArrayList<T>(1 + toAdd.size()); result.add(list.get(0)); result.addAll(toAdd); return result; } default: list.addAll(toAdd); return list; } } }
From source file:Lists.java
public static <T> List<T> addAll(List<T> list, T... toAdd) { switch (toAdd.length) { case 0:/* w w w .jav a 2 s. c o m*/ // No-op. return list; case 1: // Add one element. return add(list, toAdd[0]); default: // True list merge, result >= 2. switch (list.size()) { case 0: return new ArrayList<T>(Arrays.asList(toAdd)); case 1: { List<T> result = new ArrayList<T>(1 + toAdd.length); result.add(list.get(0)); result.addAll(Arrays.asList(toAdd)); return result; } default: list.addAll(Arrays.asList(toAdd)); return list; } } }
From source file:Main.java
public static List<Component> findChildComponentsOfType(Component component, Class<?> type) { List<Component> foundComponents = new ArrayList<Component>(); if (component instanceof Container) { Container container = (Container) component; for (Component child : container.getComponents()) { if (type.isAssignableFrom(child.getClass())) { foundComponents.add(child); }// www. j av a2 s .c om foundComponents.addAll(findChildComponentsOfType(child, type));// recursive } } return foundComponents; }
From source file:com.microsoft.azure.management.network.samples.ManageVirtualMachinesInParallelWithNetwork.java
/** * Main function which runs the actual sample. * @param azure instance of the azure client * @return true if sample runs successfully */// w w w .j ava 2 s . c om public static boolean runSample(Azure azure) { final int frontendVMCount = 10; final int backendVMCount = 10; final String rgName = SdkContext.randomResourceName("rgNEPP", 24); final String frontEndNsgName = SdkContext.randomResourceName("fensg", 24); final String backEndNsgName = SdkContext.randomResourceName("bensg", 24); final String networkName = SdkContext.randomResourceName("vnetCOMV", 24); final String storageAccountName = SdkContext.randomResourceName("stgCOMV", 20); final String userName = "tirekicker"; final String password = "12NewPA$$w0rd!"; try { // Create a resource group [Where all resources gets created] ResourceGroup resourceGroup = azure.resourceGroups().define(rgName).withRegion(Region.US_EAST).create(); //============================================================ // Define a network security group for the front end of a subnet // front end subnet contains two rules // - ALLOW-SSH - allows SSH traffic into the front end subnet // - ALLOW-WEB- allows HTTP traffic into the front end subnet Creatable<NetworkSecurityGroup> frontEndNSGCreatable = azure.networkSecurityGroups() .define(frontEndNsgName).withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup) .defineRule("ALLOW-SSH").allowInbound().fromAnyAddress().fromAnyPort().toAnyAddress().toPort(22) .withProtocol(SecurityRuleProtocol.TCP).withPriority(100).withDescription("Allow SSH").attach() .defineRule("ALLOW-HTTP").allowInbound().fromAnyAddress().fromAnyPort().toAnyAddress() .toPort(80).withProtocol(SecurityRuleProtocol.TCP).withPriority(101) .withDescription("Allow HTTP").attach(); //============================================================ // Define a network security group for the back end of a subnet // back end subnet contains two rules // - ALLOW-SQL - allows SQL traffic only from the front end subnet // - DENY-WEB - denies all outbound internet traffic from the back end subnet Creatable<NetworkSecurityGroup> backEndNSGCreatable = azure.networkSecurityGroups() .define(backEndNsgName).withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup) .defineRule("ALLOW-SQL").allowInbound().fromAddress("172.16.1.0/24").fromAnyPort() .toAnyAddress().toPort(1433).withProtocol(SecurityRuleProtocol.TCP).withPriority(100) .withDescription("Allow SQL").attach().defineRule("DENY-WEB").denyOutbound().fromAnyAddress() .fromAnyPort().toAnyAddress().toAnyPort().withAnyProtocol().withDescription("Deny Web") .withPriority(200).attach(); System.out.println("Creating security group for the front ends - allows SSH and HTTP"); System.out.println( "Creating security group for the back ends - allows SSH and denies all outbound internet traffic"); @SuppressWarnings("unchecked") Collection<NetworkSecurityGroup> networkSecurityGroups = azure.networkSecurityGroups() .create(frontEndNSGCreatable, backEndNSGCreatable).values(); NetworkSecurityGroup frontendNSG = null; NetworkSecurityGroup backendNSG = null; for (NetworkSecurityGroup nsg : networkSecurityGroups) { if (nsg.name().equalsIgnoreCase(frontEndNsgName)) { frontendNSG = nsg; } if (nsg.name().equalsIgnoreCase(backEndNsgName)) { backendNSG = nsg; } } System.out.println("Created a security group for the front end: " + frontendNSG.id()); Utils.print(frontendNSG); System.out.println("Created a security group for the back end: " + backendNSG.id()); Utils.print(backendNSG); // Create Network [Where all the virtual machines get added to] Network network = azure.networks().define(networkName).withRegion(Region.US_EAST) .withExistingResourceGroup(resourceGroup).withAddressSpace("172.16.0.0/16") .defineSubnet("Front-end").withAddressPrefix("172.16.1.0/24") .withExistingNetworkSecurityGroup(frontendNSG).attach().defineSubnet("Back-end") .withAddressPrefix("172.16.2.0/24").withExistingNetworkSecurityGroup(backendNSG).attach() .create(); // Prepare Creatable Storage account definition [For storing VMs disk] Creatable<StorageAccount> creatableStorageAccount = azure.storageAccounts().define(storageAccountName) .withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup); // Prepare a batch of Creatable Virtual Machines definitions List<Creatable<VirtualMachine>> frontendCreatableVirtualMachines = new ArrayList<>(); for (int i = 0; i < frontendVMCount; i++) { Creatable<VirtualMachine> creatableVirtualMachine = azure.virtualMachines().define("VM-FE-" + i) .withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup) .withExistingPrimaryNetwork(network).withSubnet("Front-end") .withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) .withRootUsername(userName).withRootPassword(password) .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .withNewStorageAccount(creatableStorageAccount); frontendCreatableVirtualMachines.add(creatableVirtualMachine); } List<Creatable<VirtualMachine>> backendCreatableVirtualMachines = new ArrayList<>(); for (int i = 0; i < backendVMCount; i++) { Creatable<VirtualMachine> creatableVirtualMachine = azure.virtualMachines().define("VM-BE-" + i) .withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup) .withExistingPrimaryNetwork(network).withSubnet("Back-end") .withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress() .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS) .withRootUsername(userName).withRootPassword(password) .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2) .withNewStorageAccount(creatableStorageAccount); backendCreatableVirtualMachines.add(creatableVirtualMachine); } System.out.println("Creating the virtual machines"); List<Creatable<VirtualMachine>> allCreatableVirtualMachines = new ArrayList<>(); allCreatableVirtualMachines.addAll(frontendCreatableVirtualMachines); allCreatableVirtualMachines.addAll(backendCreatableVirtualMachines); StopWatch stopwatch = new StopWatch(); stopwatch.start(); Collection<VirtualMachine> virtualMachines = azure.virtualMachines().create(allCreatableVirtualMachines) .values(); stopwatch.stop(); System.out.println("Created virtual machines"); for (VirtualMachine virtualMachine : virtualMachines) { System.out.println(virtualMachine.id()); } System.out.println("Virtual Machines create: (took " + (stopwatch.getTime() / 1000) + " seconds) "); return true; } catch (Exception f) { System.out.println(f.getMessage()); f.printStackTrace(); } finally { try { System.out.println("Deleting Resource Group: " + rgName); azure.resourceGroups().deleteByName(rgName); System.out.println("Deleted Resource Group: " + rgName); } catch (NullPointerException npe) { System.out.println("Did not create any resources in Azure. No clean up is necessary"); } catch (Exception g) { g.printStackTrace(); } } return false; }
From source file:Main.java
public static void getAllAttrs(Element parent, String name, List<String> lst) { for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.ELEMENT_NODE) { getAllAttrValueByName(child, name); List<String> tmp = getAllAttrValueByName(child, name); if (tmp != null) { lst.addAll(tmp); } else { // recursive childnodes getAllAttrs((Element) child, name, lst); }/* w w w . j a v a 2 s .co m*/ } } }
From source file:io.lavagna.service.BulkOperationService.java
private static <T> List<T> flatten(Collection<? extends Collection<T>> cc) { List<T> res = new ArrayList<>(); for (Collection<T> c : cc) { res.addAll(c); }//from w w w . j ava 2 s . co m return res; }
From source file:Main.java
@NonNull public static <T> List<T> childrenOfType(@NonNull View root, @NonNull Class<T> type) { final List<T> children = new ArrayList<>(); if (type.isInstance(root)) { children.add(type.cast(root));// w w w. j av a2 s. c om } if (root instanceof ViewGroup) { final ViewGroup rootGroup = (ViewGroup) root; for (int i = 0; i < rootGroup.getChildCount(); i++) { final View child = rootGroup.getChildAt(i); children.addAll(childrenOfType(child, type)); } } return children; }
From source file:com.hmsinc.epicenter.webapp.remoting.AbstractRemoteService.java
/** * Prepends a "NONE" category to a list. * /*from ww w.j a v a 2 s .c o m*/ * @param values * @return */ protected static Collection<KeyValueDTO> prependNoneCategory(final Collection<KeyValueDTO> values, final String text) { final List<KeyValueDTO> dto = new ArrayList<KeyValueDTO>(); dto.add(new KeyValueDTO(null, text)); dto.addAll(values); return dto; }
From source file:eu.riscoss.dataproviders.Main.java
public static void exec_single(String[] args) { Options options = new Options(); /* These two options are mandatory for the Risk Data Collector */ Option rdr = OptionBuilder.withArgName("url").hasArg().withDescription("Risk Data Repository URL") .create("rdr"); // Option entity = OptionBuilder.withArgName("entityId").hasArg().withDescription("Entity ID (OSS name)").create("entity"); Option entity = OptionBuilder.withArgName("properties").hasArg() .withDescription("Properties File (with component-related config)").create("properties"); options.addOption(rdr);/*from w w w . j a va2 s.c o m*/ options.addOption(entity); /* Print help if no arguments are specified. */ if (args.length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("rdc-template", options); System.exit(1); } /* Parse the command line */ CommandLineParser parser = new GnuParser(); CommandLine cmd; try { cmd = parser.parse(options, args); String riskDataRepositoryURL = cmd.getOptionValue("rdr"); if (riskDataRepositoryURL == null) { System.err.format("Risk data repository not specified."); System.exit(1); } // the name of the OSS to analyse String propertiesFile = cmd.getOptionValue("properties"); if (propertiesFile == null) { System.err.format("Properties file not specified."); System.exit(1); } /* Initialisation here, will be passed by parameters or config file */ // targetEntity = "XWiki"; //(should be parameter) if (writeProperties) //creates a new, hard-coded config properties = RdpConfig.loadWrite(propertiesFile); else { //read the default config file Properties defaultProperties = RdpConfig.loadDefaults(defaultPropertiesFile); //read the config from file properties = RdpConfig.load(propertiesFile, defaultProperties); } String targetEntity = properties.getProperty("targetEntity"); System.out.println(); System.out.println("************************************************"); System.out.printf("Starting the analysis for component %s.\n\n", targetEntity); IndicatorsMap im = new IndicatorsMap(targetEntity); /* Risk Data collector main logic called here */ DataProviderManager.init(im, properties); DataProviderManager.register(1, new FossologyDataProvider()); DataProviderManager.register(2, new MavenLicensesProvider()); DataProviderManager.register(3, new MarkmailDataProvider()); DataProviderManager.register(4, new JiraDataProvider()); DataProviderManager.register(5, new SonarDataProvider()); DataProviderManager.register(0, new ManualDataProvider()); // DataProviderManager.execAll(); DataProviderManager.exec(1); // DataProviderManager.exec(3); System.out.println("\n**** Resulting indicators ****" + im.entrySet()); System.out.flush(); /******************************************************/ /* * At the end, send the result to the Risk Data Repository * Example repository: http://riscoss-platform.devxwiki.com/rdr/xwiki?limit=10000 */ if (sendResults) { //put all the indicators into the riskData List List<RiskData> riskData = new ArrayList<RiskData>(); /* This list should be generated by the Risk Data Collector logic :) */ riskData.addAll(im.values()); //riskData.add(RiskDataFactory.createRiskData("iop", targetEntity, new Date(), RiskDataType.NUMBER, 1.0)); try { RDR.sendRiskData(riskDataRepositoryURL, riskData); System.out .println("\nIndicators sent via REST to " + riskDataRepositoryURL + "/" + targetEntity); } catch (Exception e) { System.err.print("Warning: Not able to send inicators via REST to " + riskDataRepositoryURL); e.printStackTrace(); //System.err.println(" Exception: "+e.getClass().getName()); } } if (csvresults) { System.out.println("Results in CSV format retrieved " + new Date()); for (String key : im.keySet()) { RiskData content = im.get(key); // if (content.getType().equals(RiskDataType.DISTRIBUTION) System.out.print("# " + content.getTarget() + "\t" + content.getId() + "\t"); switch (content.getType()) { case DISTRIBUTION: for (Double d : ((Distribution) content.getValue()).getValues()) System.out.print(d + "\t"); break; case NUMBER: System.out.print(content.getValue()); break; default: break; } System.out.print("\n"); } System.out.println("CSV End"); } } catch (ParseException e1) { System.err.println("Error in parsing command line arguments. Exiting."); e1.printStackTrace(); System.exit(1); } }