Java Code Examples for java.util.Collections#replaceAll()

The following examples show how to use java.util.Collections#replaceAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirewallManagerImpl.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
@Override
@ActionEvent(eventType = EventTypes.EVENT_FIREWALL_EGRESS_OPEN, eventDescription = "creating egress firewall rule for network", create = true)
public FirewallRule createEgressFirewallRule(FirewallRule rule) throws NetworkRuleConflictException {
    Account caller = CallContext.current().getCallingAccount();

    Network network = _networkDao.findById(rule.getNetworkId());
    if (network.getGuestType() == Network.GuestType.Shared) {
        throw new InvalidParameterValueException("Egress firewall rules are not supported for " + network.getGuestType() + "  networks");
    }

    List<String> sourceCidrs = rule.getSourceCidrList();
    if (sourceCidrs != null && !sourceCidrs.isEmpty())
    Collections.replaceAll(sourceCidrs, "0.0.0.0/0", network.getCidr());

    return createFirewallRule(null, caller, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), sourceCidrs, rule.getDestinationCidrList(),
            rule.getIcmpCode(), rule.getIcmpType(), null, rule.getType(), rule.getNetworkId(), rule.getTrafficType(), rule.isDisplay());
}
 
Example 2
Source File: TextUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Joins the elements of the provided array into a single String containing
 * the provided list of elements.
 *
 * @param <T> type.
 * @param list the list of objects to join.
 * @param separator the separator string.
 * @param nullReplacement the value to replace nulls in list with.
 * @return the joined string.
 */
public static <T> String join( List<T> list, String separator, T nullReplacement )
{
    if ( list == null )
    {
        return null;
    }

    List<T> objects = new ArrayList<>( list );

    if ( nullReplacement != null )
    {
        Collections.replaceAll( objects, null, nullReplacement );
    }

    return StringUtils.join( objects, separator );
}
 
Example 3
Source File: ReplaceAllArrayListExample.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {

        //create an ArrayList object
        ArrayList arrayList = new ArrayList();

        //Add elements to Arraylist
        arrayList.add("A");
        arrayList.add("B");
        arrayList.add("A");
        arrayList.add("C");
        arrayList.add("D");

        System.out.println("ArrayList Contains : " + arrayList);

    /*
      To replace all occurrences of specified element of Java ArrayList use,
      static boolean replaceAll(List list, Object oldVal, Object newVal) method
      of Collections class.

      This method returns true if the list contained one more elements replaced.

    */

        Collections.replaceAll(arrayList, "A", "Replace All");

        System.out.println("After Replace All, ArrayList Contains : " + arrayList);
    }
 
Example 4
Source File: Column.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
public Column replaceAccount (final Account newAccount, final InternalColumnType ict) {
	final ColumnFeed oldFeed = ict.findInFeeds(getFeeds());
	if (oldFeed == null) throw new IllegalArgumentException("ICT " + ict + " not found in feeds: " + getFeeds());
	final List<ColumnFeed> newFeeds = new ArrayList<ColumnFeed>(getFeeds());
	Collections.replaceAll(newFeeds, oldFeed, new ColumnFeed(newAccount.getId(), oldFeed.getResource()));
	return new Column(getId(), getTitle(), new LinkedHashSet<ColumnFeed>(newFeeds), getRefreshIntervalMins(),
			getExcludeColumnIds(), isHideRetweets(), getNotificationStyle(), getInlineMediaStyle(), isHdMedia());
}
 
Example 5
Source File: PinotInstanceAssignmentRestletResource.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/tables/{tableName}/replaceInstance")
@ApiOperation(value = "Replace an instance in the instance partitions")
public Map<InstancePartitionsType, InstancePartitions> replaceInstance(
    @ApiParam(value = "Name of the table") @PathParam("tableName") String tableName,
    @ApiParam(value = "OFFLINE|CONSUMING|COMPLETED") @QueryParam("type") @Nullable InstancePartitionsType instancePartitionsType,
    @ApiParam(value = "Old instance to be replaced", required = true) @QueryParam("oldInstanceId") String oldInstanceId,
    @ApiParam(value = "New instance to replace with", required = true) @QueryParam("newInstanceId") String newInstanceId) {
  Map<InstancePartitionsType, InstancePartitions> instancePartitionsMap =
      getInstancePartitions(tableName, instancePartitionsType);
  Iterator<InstancePartitions> iterator = instancePartitionsMap.values().iterator();
  while (iterator.hasNext()) {
    InstancePartitions instancePartitions = iterator.next();
    boolean oldInstanceFound = false;
    Map<String, List<String>> partitionToInstancesMap = instancePartitions.getPartitionToInstancesMap();
    for (List<String> instances : partitionToInstancesMap.values()) {
      oldInstanceFound |= Collections.replaceAll(instances, oldInstanceId, newInstanceId);
    }
    if (oldInstanceFound) {
      persistInstancePartitionsHelper(instancePartitions);
    } else {
      iterator.remove();
    }
  }
  if (instancePartitionsMap.isEmpty()) {
    throw new ControllerApplicationException(LOGGER, "Failed to find the old instance", Response.Status.NOT_FOUND);
  } else {
    return instancePartitionsMap;
  }
}
 
Example 6
Source File: LogicVisitor.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static void collect(RexNode node, RexNode seek, Logic logic,
    List<Logic> logicList) {
  node.accept(new LogicVisitor(seek, logicList), logic);
  // Convert FALSE (which can only exist within LogicVisitor) to
  // UNKNOWN_AS_TRUE.
  Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE);
}
 
Example 7
Source File: SalesforceBulkV2Runtime.java    From components with Apache License 2.0 5 votes vote down vote up
public BulkResultSet getResultSet(InputStream input) throws IOException {
    CsvReader reader = new CsvReader(new InputStreamReader(input), getDelimitedChar(columnDelimiter));
    List<String> baseFileHeader = null;
    if (reader.readRecord()) {
        baseFileHeader = Arrays.asList(reader.getValues());
        Collections.replaceAll(baseFileHeader, "sf__Id", "salesforce_id");
        Collections.replaceAll(baseFileHeader, "sf__Created", "salesforce_created");
    }
    return new BulkResultSet(reader, baseFileHeader);
}
 
Example 8
Source File: CursorPagingTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Given a list of fieldNames, builds up a random sort string which is guaranteed to
 * have at least 3 clauses, ending with the "id" field for tie breaking
 */
public static String buildRandomSort(final Collection<String> fieldNames) {

  ArrayList<String> shuffledNames = new ArrayList<>(fieldNames);
  Collections.replaceAll(shuffledNames, "id", "score");
  Collections.shuffle(shuffledNames, random());

  final StringBuilder result = new StringBuilder();
  final int numClauses = TestUtil.nextInt(random(), 2, 5);

  for (int i = 0; i < numClauses; i++) {
    String field = shuffledNames.get(i);

    // wrap in a function sometimes
    if ( ! "score".equals(field) && 0 == TestUtil.nextInt(random(), 0, 7)) {
      // specific function doesn't matter, just proving that we can handle the concept.
      // but we do have to be careful with non numeric fields
      if (field.contains("float") || field.contains("double")
          || field.contains("int") || field.contains("long")) {
        field = "abs(" + field + ")";
      } else {
        field = "if(exists(" + field + "),47,83)";
      }
    }
    result.append(field).append(random().nextBoolean() ? " asc, " : " desc, ");
  }
  result.append("id").append(random().nextBoolean() ? " asc" : " desc");
  return result.toString();
}
 
Example 9
Source File: LogicVisitor.java    From Bats with Apache License 2.0 5 votes vote down vote up
public static void collect(RexNode node, RexNode seek, Logic logic,
    List<Logic> logicList) {
  node.accept(new LogicVisitor(seek, logicList), logic);
  // Convert FALSE (which can only exist within LogicVisitor) to
  // UNKNOWN_AS_TRUE.
  Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE);
}
 
Example 10
Source File: ReplaceAllVectorExample.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {

        //create a Vector object
        Vector v = new Vector();

        //Add elements to Vector
        v.add("A");
        v.add("B");
        v.add("A");
        v.add("C");
        v.add("D");

        System.out.println("Vector Contains : " + v);

    /*
      To replace all occurrences of specified element of Java Vector use,
      static boolean replaceAll(List list, Object oldVal, Object newVal) method
      of Collections class.

      This method returns true if the list contained one more elements replaced.

    */

        Collections.replaceAll(v, "A", "Replace All");

        System.out.println("After Replace All, Vector Contains : " + v);
    }
 
Example 11
Source File: CollectionsDemo05.java    From javacore with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
public static void main(String[] args) {
    List<String> all = new ArrayList<String>();    // 返回空的 List集合
    Collections.addAll(all, "MLDN", "LXH", "mldnjava");
    if (Collections.replaceAll(all, "LXH", "李兴华")) {// 替换内容
        System.out.println("内容替换成功!");
    }
    System.out.print("替换之后的结果:");
    System.out.print(all);
}
 
Example 12
Source File: TestScriptsBean.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public void onChange(MatrixAdapter newMatrixAdapter) {
	// replace matrixAdapter by updated one. (Search by matrixAdapter.id - refer to MatrixAdapter.equals() method)
    Collections.replaceAll(matrixAdapterList, newMatrixAdapter, newMatrixAdapter);
	try {
		scriptRunsBean.onChangeMatrixAdapter(newMatrixAdapter.clone());
	} catch (CloneNotSupportedException e) {
		logger.error(e.getMessage(), e);
	}
}
 
Example 13
Source File: ReplaceAllArrayListExample.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("A");
    arrayList.add("C");
    arrayList.add("D");

    System.out.println("ArrayList Contains : " + arrayList);

    /*
      To replace all occurrences of specified element of Java ArrayList use,
      static boolean replaceAll(List list, Object oldVal, Object newVal) method
      of Collections class.

      This method returns true if the list contained one more elements replaced.

    */

    Collections.replaceAll(arrayList, "A", "Replace All");

    System.out.println("After Replace All, ArrayList Contains : " + arrayList);
  }
 
Example 14
Source File: ReplaceAllVectorExample.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

    //create a Vector object
    Vector v = new Vector();

    //Add elements to Vector
    v.add("A");
    v.add("B");
    v.add("A");
    v.add("C");
    v.add("D");

    System.out.println("Vector Contains : " + v);

    /*
      To replace all occurrences of specified element of Java Vector use,
      static boolean replaceAll(List list, Object oldVal, Object newVal) method
      of Collections class.

      This method returns true if the list contained one more elements replaced.

    */

    Collections.replaceAll(v, "A", "Replace All");

    System.out.println("After Replace All, Vector Contains : " + v);
  }
 
Example 15
Source File: GoModCliExtractor.java    From synopsys-detect with Apache License 2.0 5 votes vote down vote up
private String convertOutputToJsonString(List<String> listUJsonOutput) {
    // go list -u -json does not provide data in a format that can be consumed by gson
    Collections.replaceAll(listUJsonOutput, "}", "},");
    String goModGraphAsString = String.join(System.lineSeparator(), listUJsonOutput);
    int lastCloseBrace = goModGraphAsString.lastIndexOf("},");
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("[" + System.lineSeparator());
    stringBuilder.append(goModGraphAsString.substring(0, lastCloseBrace));
    stringBuilder.append("}");
    stringBuilder.append(goModGraphAsString.substring(lastCloseBrace + 2));
    stringBuilder.append(System.lineSeparator() + "]");

    return stringBuilder.toString();
}
 
Example 16
Source File: LogicVisitor.java    From Quicksql with MIT License 5 votes vote down vote up
public static void collect(RexNode node, RexNode seek, Logic logic,
    List<Logic> logicList) {
  node.accept(new LogicVisitor(seek, logicList), logic);
  // Convert FALSE (which can only exist within LogicVisitor) to
  // UNKNOWN_AS_TRUE.
  Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE);
}
 
Example 17
Source File: HandlerUtil.java    From styx with Apache License 2.0 4 votes vote down vote up
static List<String> argsReplace(List<String> template, String parameter) {
  List<String> result = new ArrayList<>(template);

  Collections.replaceAll(result, "{}", parameter);
  return result;
}
 
Example 18
Source File: ScriptRunsBean.java    From sailfish-core with Apache License 2.0 4 votes vote down vote up
public synchronized void onChangeMatrixAdapter(MatrixAdapter matrixAdapter){
    logger.debug("onChangeMatrixAdapter started with {}", matrixAdapter);
    Collections.replaceAll(matrixAdapterList, matrixAdapter, matrixAdapter);
}
 
Example 19
Source File: OSMWay.java    From rcrs-server with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
   Replace a node ID in this way.
   @param oldID The old node ID.
   @param newID The new node ID.
*/
public void replace(Long oldID, Long newID) {
    Collections.replaceAll(ids, oldID, newID);
}