Java Code Examples for java.util.List.replaceAll()

The following are Jave code examples for showing how to use replaceAll() of the java.util.List class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ExZiff   File: ContinentsBasePolygonGenerator.java   View Source Code Vote up 6 votes
private Polygon2D modifyBasePolygonDeform(Polygon2D toModify)
{
	Vector2D center = toModify.getPointCenter();
	Vector2D point = RandomUtil.getElement(toModify.points, this.random);

	Vector2D centerToPoint = point.subtract(center);
	Vector2D ctpDirection = centerToPoint.normalize();
	Vector2D ctpOrthogonal = center.orthogonal().normalize();

	Vector2D pointDeltaForward = ctpDirection.multiply(RandomUtil.distribute(0.05, 0.1, this.random));
	Vector2D pointDeltaSideward = ctpOrthogonal.multiply(RandomUtil.distribute(0.05, 0.1, this.random));
	Vector2D pointDelta = pointDeltaForward.add(pointDeltaSideward);

	Vector2D newPoint = point.add(pointDelta);
	List<Vector2D> newPoints = new ArrayList<>(toModify.points);
	newPoints.replaceAll((p)->Objects.equals(p, point) ? newPoint : p); // replace the old point with the new one

	return new Polygon2D(newPoints);
}
 
Example 2
Project: jdk8u-jdk   File: ListDefaults.java   View Source Code Vote up 6 votes
@Test
public void testReplaceAllThrowsCME() {
    @SuppressWarnings("unchecked")
    final CollectionSupplier<List<Integer>> supplier = new CollectionSupplier(LIST_CME_SUPPLIERS, SIZE);
    for (final CollectionSupplier.TestCase<List<Integer>> test : supplier.get()) {
        final List<Integer> list = test.collection;

        if (list.size() <= 1) {
            continue;
        }
        boolean gotException = false;
        try {
            // bad predicate that modifies its list, should throw CME
            list.replaceAll(x -> {int n = 3 * x; list.add(n); return n;});
        } catch (ConcurrentModificationException cme) {
            gotException = true;
        }
        if (!gotException) {
            fail("expected CME was not thrown from " + test);
        }
    }
}
 
Example 3
Project: openjdk-jdk10   File: ListDefaults.java   View Source Code Vote up 6 votes
@Test
public void testReplaceAllThrowsCME() {
    @SuppressWarnings("unchecked")
    final CollectionSupplier<List<Integer>> supplier = new CollectionSupplier(LIST_CME_SUPPLIERS, SIZE);
    for (final CollectionSupplier.TestCase<List<Integer>> test : supplier.get()) {
        final List<Integer> list = test.collection;

        if (list.size() <= 1) {
            continue;
        }
        boolean gotException = false;
        try {
            // bad predicate that modifies its list, should throw CME
            list.replaceAll(x -> {int n = 3 * x; list.add(n); return n;});
        } catch (ConcurrentModificationException cme) {
            gotException = true;
        }
        if (!gotException) {
            fail("expected CME was not thrown from " + test);
        }
    }
}
 
Example 4
Project: Spring-5.0-Cookbook   File: EmployeeStreamService.java   View Source Code Vote up 5 votes
public List<Employee> updateNames(){
	List<Employee> newListEmps= employeeDaoImpl.getEmployees();
	newListEmps.replaceAll((e) ->{
		e.setFirstName(e.getFirstName().toUpperCase());
		e.setLastName(e.getLastName().toUpperCase());
		return e;
	});
	
	return newListEmps;
}
 
Example 5
Project: openjdk-systemtest   File: ClassLibraryLambdaTests.java   View Source Code Vote up 5 votes
void runReplaceAll(List<StringHolder> a, List<StringHolder> b) {
	a.replaceAll((StringHolder t)->{t.concat("@JJ17r");return new StringHolder(t.getString() + "@417b");});
	int x = 0;
	while (x<b.size()) {
		assertTrue("Expected \"" + b.get(x).getString() + "[email protected]@417b\" but found \"" + a.get(x).getString(),a.get(x).getString().equals(b.get(x).getString() + "[email protected]@417b"));
		x++;
	}
}
 
Example 6
Project: jrbuilder   File: ReportForm.java   View Source Code Vote up 5 votes
private void updateColumns(List<Column> newColumns) {
    List<Column> currentColumns = report.getColumns();
    newColumns = new ArrayList<>(newColumns);
    newColumns.replaceAll(column -> {
        if (currentColumns.contains(column)) {
            return currentColumns.get(currentColumns.indexOf(column));
        }
        return column;
    });
    report.clearColumns();
    newColumns.forEach(report::addColumn);
    report.setQuery(queryArea.getText().trim());
}
 
Example 7
Project: heat   File: EnvironmentHandler.java   View Source Code Vote up 5 votes
/**
 * In case of multiple value for the "heatTest" parameter, it splits the values and runs tests one by one.
 * @param testIds string containing all the test ids to run, split with a separator
 * @return a list of test ids
 */
private List<String> testIds2List(String testIds) {
    List<String> testIdsList = new ArrayList<>();

    if (testIds != null) {
        testIdsList.addAll(Arrays.asList(testIds.split(HEAT_TEST_SEPARATOR)));
        testIdsList.replaceAll(String::trim);
    }
    return testIdsList;
}
 
Example 8
Project: rlc-analyser   File: RLCTreeBuilder.java   View Source Code Vote up 4 votes
/**
 * This method will generate the resulting aggregated data tree
 *
 * @param dataStore
 *            - the RLCDataStore that was used to collect all the data for
 *            the RLCs processed
 * @param configurationDataStore
 *            - the ConfigurationDataStore that was used to collect all the
 *            data for the RLCs processed
 * @param dataStoreMap
 *            - the DataStoreMap that is used to collect the names of the
 *            different RLCs processed
 * @return JScrollPane
 */
public JScrollPane createResultTree(final RLCDataStore dataStore,
                                    final ConfigurationDataStore configurationDataStore, final Map<String, RLCDataStore> dataStoreMap) {
	final DefaultMutableTreeNode top = new DefaultMutableTreeNode("root");

	final RLCDataAnalyser dataAnalyser = new RLCDataAnalyser(dataStore);
	final List<String> fileNameHeaderList;


	final DefaultMutableTreeNode summary = new DefaultMutableTreeNode("Summary");
	final DefaultMutableTreeNode rlcSummary = new DefaultMutableTreeNode("RLC Information");

	addATreeNode(summary, "Total number of Lockers", dataStore.getTotalCounts(TotalCountDataType.Lockers));
	addATreeNode(summary, "Total number of Routes", dataStore.getTotalCounts(TotalCountDataType.Routes));
	addATreeNode(summary, "Total number of Communication Points",
	             dataStore.getTotalCounts(TotalCountDataType.CommunicationPoints));

	addATreeNode(summary, "Total number of Filters", dataAnalyser.getNumberOfFilters());
	addATreeNode(summary, "Total number of Web Services", dataStore.getTotalCounts(TotalCountDataType.WebServices));
	addATreeNode(summary, "Total number of Definitions", dataStore.getTotalCounts(TotalCountDataType.Definitions));
	addATreeNode(summary, "Total number of Message Tracking Schemes",
	             dataStore.getTotalCounts(TotalCountDataType.MessageTrackingSchemes));
	addATreeNode(summary, "Total number of REST Clients", dataStore.getTotalCounts(TotalCountDataType.RESTClients));
	addATreeNode(summary, "Total number of Variables", dataStore.getTotalCounts(TotalCountDataType.Variables));
	addATreeNode(summary, "Total number of Lookup Tables",
	             dataStore.getTotalCounts(TotalCountDataType.LookupTables));
	addATreeNode(summary, "Total number of Shared JavaScript Libraries",
	             dataStore.getTotalCounts(TotalCountDataType.SharedJSLibraries));

	fileNameHeaderList = new ArrayList<String>(dataStoreMap.keySet());
	fileNameHeaderList.replaceAll(fileName -> fileName.substring(fileName.indexOf(":") + 1));

	// Add the tree structure to the root
	addATreeNode(rlcSummary, "Total number of RLC files processed", fileNameHeaderList.size());
	addResultsTreeNode(rlcSummary, "RLCs Processed", fileNameHeaderList);

	top.add(summary);
	top.add(rlcSummary);

	return new JScrollPane(manipulateJTree(top));
}
 
Example 9
Project: pravega-samples   File: SharedConfigCli.java   View Source Code Vote up 4 votes
private boolean processCommand(String rawString) {
    boolean ret = false;
    final Scanner sc = new Scanner(rawString);
    final String command = sc.next();
    List<String> parms;
    if (sc.hasNextLine()) {
        final String[] rawParms = sc.nextLine().split(",");
        parms = Arrays.asList(rawParms);
        parms.replaceAll(String::trim);
    } else {
        parms = new ArrayList<String>();
    }
    
    switch(command.toUpperCase()) {
        case "GET_ALL" :
            doGetAll(parms);
            break;
        case "GET" :
            doGet(parms);
            break;
        case "PUT" :
            doPut(parms);
            break;
        case "PUT_IF_ABSENT" :
            doPutIfAbsent(parms);
            break;
        case "REMOVE" :
            doRemove(parms);
            break;
        case "REPLACE" :
            doReplace(parms);
            break;
        case "CLEAR" :
            doClear(parms);
            break;
        case "REFRESH" :
            doRefresh(parms);
            break;
        case "HELP" :
            doHelp(parms);
            break;
        case "QUIT" :
            ret = true;
            output("Exiting...%n");
            break;
        default :
            unknownCommand(command);
            break;
    }
    sc.close();
    return ret;
}
 
Example 10
Project: pravega-samples   File: ConsoleWriter.java   View Source Code Vote up 4 votes
private boolean processCommand(String rawString) {
    boolean ret = false;
    final Scanner sc = new Scanner(rawString);
    final String command = sc.next();
    List<String> parms;
    final String restOfLine;
    if (sc.hasNextLine()) {
        restOfLine = sc.nextLine();
        final String[] rawParms = restOfLine.split(",");
        parms = Arrays.asList(rawParms);
        parms.replaceAll(String::trim);
    } else {
        parms = new ArrayList<String>();
        restOfLine = null;
    }
    
    switch(command.toUpperCase()) {
        case "WRITE_EVENT":
            doWriteEvent(restOfLine);
            break;
        case "WRITE_EVENT_RK":
            doWriteEventRK(restOfLine);
            break;
        case "BEGIN":
            doBeginTxn(parms);
            break;
        case "GET_TXN_ID":
            doGetTxnId(parms);
            break;
        case "FLUSH":
            doFlushTxn(parms);
            break;
        case "COMMIT":
            doCommitTxn(parms);
            break;
        case "ABORT":
            doAbortTxn(parms);
            break;
        case "STATUS":
            doCheckTxnStatus(parms);
            break;
        case "HELP" :
            doHelp(parms);
            break;
        case "QUIT" :
            ret = true;
            output("Exiting...%n");
            break;
        default :
            doWriteEvent(rawString);
            break;
    }
    sc.close();
    return ret;
}
 
Example 11
Project: VTerminal   File: FontLoader.java   View Source Code Vote up 3 votes
/**
 * Loads character data from a path.
 *
 * @param inputStream
 *         The input stream.
 *
 * @return
 *         The character data.
 *
 * @throws NullPointerException
 *         If the input stream is null.
 *
 * @throws IOException
 *         If an IOException occurs while loading the character data.
 */
private static List<String> loadCharacterData(final @NonNull InputStream inputStream) throws IOException {
    // Load lines
    final InputStreamReader isr = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
    final BufferedReader br = new BufferedReader(isr);
    List<String> lines = br.lines().collect(Collectors.toList());

    // Remove unnecessary data:
    final Pattern pattern = Pattern.compile("info.*|common.*|page.*|chars.*|char id=\\d\\d\\d\\d\\d\\d.*|char id=[7-9]\\d\\d\\d\\d.*|char id=6[6-9]\\d\\d\\d.*|char id=65[6-9]\\d\\d.*|char id=655[4-9]\\d.*|char id=6553[6-9].*| xoff.*|char id=|x=|y=|width=|height=");
    lines.replaceAll(string -> pattern.matcher(string).replaceAll(""));
    lines.removeIf(String::isEmpty);

    inputStream.close();
    return lines;
}