List of usage examples for java.util List set
E set(int index, E element);
From source file:com.clustercontrol.calendar.composite.CalendarDetailListComposite.java
/** * ????/*from ww w . j a va2 s . co m*/ */ public void up() { StructuredSelection selection = (StructuredSelection) m_tableViewer.getSelection();//.firstElement; ArrayList<?> list = (ArrayList<?>) selection.getFirstElement(); //????? Integer order = (Integer) list.get(0); List<CalendarDetailInfo> detailList = this.detailList; //order???????1 n list????? order - 1 order = order - 1; if (order > 0) { CalendarDetailInfo a = detailList.get(order); CalendarDetailInfo b = detailList.get(order - 1); detailList.set(order, b); detailList.set(order - 1, a); } update(); //?????? selectItem(order - 1); }
From source file:com.github.mojos.distribute.PackageMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (version != null) { packageVersion = version;//from ww w .j a v a 2 s.c o m } //Copy sourceDirectory final File sourceDirectoryFile = new File(sourceDirectory); final File buildDirectory = Paths.get(project.getBuild().getDirectory(), "py").toFile(); try { FileUtils.copyDirectory(sourceDirectoryFile, buildDirectory); } catch (IOException e) { throw new MojoExecutionException("Failed to copy source", e); } final File setup = Paths.get(buildDirectory.getPath(), "setup.py").toFile(); final boolean setupProvided = setup.exists(); final File setupTemplate = setupProvided ? setup : Paths.get(buildDirectory.getPath(), "setup-template.py").toFile(); try { if (!setupProvided) { //update VERSION to latest version List<String> lines = new ArrayList<String>(); final InputStream inputStream = new BufferedInputStream(new FileInputStream(setupTemplate)); try { lines.addAll(IOUtils.readLines(inputStream)); } finally { inputStream.close(); } int index = 0; for (String line : lines) { line = line.replace(VERSION, packageVersion); line = line.replace(PROJECT_NAME, packageName); lines.set(index, line); index++; } final OutputStream outputStream = new FileOutputStream(setup); try { IOUtils.writeLines(lines, "\n", outputStream); } finally { outputStream.flush(); outputStream.close(); } } //execute setup script ProcessBuilder processBuilder = new ProcessBuilder(pythonExecutable, setup.getCanonicalPath(), "bdist_egg"); processBuilder.directory(buildDirectory); processBuilder.redirectErrorStream(true); Process pr = processBuilder.start(); int exitCode = pr.waitFor(); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line = ""; while ((line = buf.readLine()) != null) { getLog().info(line); } if (exitCode != 0) { throw new MojoExecutionException("python setup.py returned error code " + exitCode); } } catch (FileNotFoundException e) { throw new MojoExecutionException("Unable to find " + setup.getPath(), e); } catch (IOException e) { throw new MojoExecutionException("Unable to read " + setup.getPath(), e); } catch (InterruptedException e) { throw new MojoExecutionException("Unable to execute python " + setup.getPath(), e); } }
From source file:gobblin.source.extractor.filebased.FileBasedSource.java
/** * This method is responsible for connecting to the source and taking * a snapshot of the folder where the data is present, it then returns * a list of the files in String format/*ww w . j a va 2 s . com*/ * @param state is used to connect to the source * @return a list of file name or paths present on the external data * directory */ public List<String> getcurrentFsSnapshot(State state) { List<String> results = new ArrayList<>(); String path = state.getProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY) + "/*" + state.getProp(ConfigurationKeys.SOURCE_ENTITY) + "*"; try { log.info("Running ls command with input " + path); results = this.fsHelper.ls(path); for (int i = 0; i < results.size(); i++) { String filePath = state.getProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY) + "/" + results.get(i); results.set(i, filePath + this.splitPattern + this.fsHelper.getFileMTime(filePath)); } } catch (FileBasedHelperException e) { log.error("Not able to fetch the filename/file modified time to " + e.getMessage() + " will not pull any files", e); } return results; }
From source file:com.haulmont.cuba.gui.components.filter.edit.FilterEditor.java
public void moveConditionDown() { AbstractCondition condition = conditionsDs.getItem(); Node<AbstractCondition> node = conditions.getNode(condition); List<Node<AbstractCondition>> siblings = node.getParent() == null ? conditions.getRootNodes() : node.getParent().getChildren(); int idx = siblings.indexOf(node); if (idx < siblings.size() - 1) { Node<AbstractCondition> next = siblings.get(idx + 1); siblings.set(idx + 1, node); siblings.set(idx, next);//w ww .java 2 s .c o m refreshConditionsDs(); conditionsTree.setSelected(condition); } }
From source file:com.streamsets.pipeline.lib.generator.delimited.TestDelimitedDataGenerator.java
@Test public void testGeneratorWithHeader() throws Exception { StringWriter writer = new StringWriter(); DataGenerator gen = new DelimitedCharDataGenerator(writer, CsvMode.CSV.getFormat(), CsvHeader.WITH_HEADER, "h", "d", null); Record record = RecordCreator.create(); List<Field> list = new ArrayList<>(); Map<String, Field> map = new HashMap<>(); map.put("h", Field.create("A")); map.put("d", Field.create("a")); list.add(Field.create(map));//from w w w . j av a 2 s .co m map.put("h", Field.create("B")); map.put("d", Field.create("b")); list.add(Field.create(map)); record.set(Field.create(list)); gen.write(record); map.put("d", Field.create("bb")); list.set(1, Field.create(map)); record.set(Field.create(list)); gen.write(record); gen.close(); Assert.assertEquals("A,B\r\na,b\r\na,bb\r\n", writer.toString()); }
From source file:com.naver.template.social.connect.DaoConnectionRepository.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }//from ww w.ja va 2 s . c o m // StringBuilder providerUsersCriteriaSql = new StringBuilder(); // MapSqlParameterSource parameters = new MapSqlParameterSource(); // parameters.addValue("userId", userId); // for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { // Entry<String, List<String>> entry = it.next(); // String providerId = entry.getKey(); // providerUsersCriteriaSql.append("providerId = :providerId_").append(providerId).append(" and providerUserId in (:providerUserIds_").append(providerId).append(")"); // parameters.addValue("providerId_" + providerId, providerId); // parameters.addValue("providerUserIds_" + providerId, entry.getValue()); // if (it.hasNext()) { // providerUsersCriteriaSql.append(" or " ); // } // } //List<Connection<?>> resultList = new NamedParameterJdbcTemplate(jdbcTemplate).query(selectFromUserConnection() + " where userId = :userId and " + providerUsersCriteriaSql + " order by providerId, rank", parameters, connectionMapper); List<Connection<?>> resultList = userConnectionDAO.selectConnections(userId, providerUsers); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:es.udc.gii.common.eaf.algorithm.operator.replace.mmga.PopulationMemoryReplaceOperator.java
private List<Individual> replaceWithParetoFront(MMGAAlgorithm mmga, List<Individual> toPopulation) { /* Get the Pareto-front. */ List<Individual> paretoFront = mmga.getParetoFront().getIndividuals(); /* Do nothing if empty. */ if (paretoFront.isEmpty()) { return toPopulation; }//from ww w .j a v a 2 s . c o m /* If the Pareto-front is too small */ if (paretoFront.size() <= getReplaceablePartSize()) { /* Copy the entire Pareto-front. */ for (int i = 0; i < paretoFront.size(); i++) { toPopulation.set(nextIndex(), paretoFront.get(i)); } } else { /* If we have not enough place for all Pareto-solutions */ /* Construct a hypercube and add the Pareto-front to it.*/ Hypercube hypercube = new Hypercube(paretoFront, mmga.getProblem().getObjectiveFunctions().size(), getHypercubeDivisions()); /* Get the cells which have some individuals. */ List<Hypercube.Cell> crowdedCells = hypercube.getCrowdedCells(); /* This array stores an index for each cell. We will pick up an * individual from each cell until the replaceable part of the * population memory is full. */ int[] indexInCell = new int[crowdedCells.size()]; /* Fill the replaceable part of the population memory. Note that we * can choose the same cell several times. We can also take the same * individual of a single cell more than once. Therefore we go through * this lists in a circular manner (employement of the modulo operator). */ for (int currentCell = 0, replaced = 0; replaced < getReplaceablePartSize(); currentCell = (currentCell + 1) % crowdedCells.size(), replaced++) { Hypercube.Cell cell = crowdedCells.get(currentCell); Individual ind = cell.getIndividual(indexInCell[currentCell]); toPopulation.set(replaced, ind); indexInCell[currentCell] = (indexInCell[currentCell] + 1) % cell.getIndividualsCount(); } } return toPopulation; }
From source file:com.jiwhiz.domain.account.impl.ConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }// w w w . j av a2s . c om MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); List<String> providerUserIds = entry.getValue(); List<UserSocialConnection> userSocialConnections = userSocialConnectionRepository .findByProviderIdAndProviderUserIdIn(providerId, providerUserIds); List<Connection<?>> connections = new ArrayList<Connection<?>>(providerUserIds.size()); for (int i = 0; i < providerUserIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); for (UserSocialConnection userSocialConnection : userSocialConnections) { String providerUserId = userSocialConnection.getProviderUserId(); int connectionIndex = providerUserIds.indexOf(providerUserId); connections.set(connectionIndex, buildConnection(userSocialConnection)); } } return connectionsForUsers; }
From source file:com.jiwhiz.domain.account.impl.MongoConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }// w ww . j a va2s . c om MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); List<String> providerUserIds = entry.getValue(); List<UserSocialConnection> userSocialConnections = this.userSocialConnectionRepository .findByProviderIdAndProviderUserIdIn(providerId, providerUserIds); List<Connection<?>> connections = new ArrayList<Connection<?>>(providerUserIds.size()); for (int i = 0; i < providerUserIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); for (UserSocialConnection userSocialConnection : userSocialConnections) { String providerUserId = userSocialConnection.getProviderUserId(); int connectionIndex = providerUserIds.indexOf(providerUserId); connections.set(connectionIndex, buildConnection(userSocialConnection)); } } return connectionsForUsers; }
From source file:io.hops.transaction.context.INodeContext.java
private List<INode> findBatchWithLocalCacheCheck(INode.Finder inodeFinder, Object[] params) throws TransactionContextException, StorageException { final String[] names = (String[]) params[0]; final long[] parentIds = (long[]) params[1]; final long[] partitionIds = (long[]) params[2]; List<String> namesRest = Lists.newArrayList(); List<Long> parentIdsRest = Lists.newArrayList(); List<Long> partitionIdsRest = Lists.newArrayList(); List<Integer> unpopulatedIndeces = Lists.newArrayList(); List<INode> result = new ArrayList<>(Collections.<INode>nCopies(names.length, null)); for (int i = 0; i < names.length; i++) { final String nameParentKey = INode.nameParentKey(parentIds[i], names[i]); INode node = inodesNameParentIndex.get(nameParentKey); if (node != null) { result.set(i, node); hit(inodeFinder, node, "name", names[i], "parent_id", parentIds[i], "partition_id", partitionIds[i]);//from w w w . j av a 2 s . c om } else { namesRest.add(names[i]); parentIdsRest.add(parentIds[i]); partitionIdsRest.add(partitionIds[i]); unpopulatedIndeces.add(i); } } if (unpopulatedIndeces.isEmpty()) { return result; } if (unpopulatedIndeces.size() == names.length) { return findBatch(inodeFinder, names, parentIds, partitionIds); } else { List<INode> batch = findBatch(inodeFinder, namesRest.toArray(new String[namesRest.size()]), Longs.toArray(parentIdsRest), Longs.toArray(partitionIdsRest)); Iterator<INode> batchIterator = batch.listIterator(); for (Integer i : unpopulatedIndeces) { if (batchIterator.hasNext()) { result.set(i, batchIterator.next()); } } return result; } }