java.util.Collections.unmodifiableList()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(207)

本文整理了Java中java.util.Collections.unmodifiableList()方法的一些代码示例,展示了Collections.unmodifiableList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.unmodifiableList()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:unmodifiableList

Collections.unmodifiableList介绍

[英]Returns a wrapper on the specified list which throws an UnsupportedOperationException whenever an attempt is made to modify the list.
[中]返回指定列表上的包装器,每当试图修改列表时,该包装器将抛出UnsupportedOperationException。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public List<FieldError> getFieldErrors() {
  List<FieldError> result = new LinkedList<>();
  for (ObjectError objectError : this.errors) {
    if (objectError instanceof FieldError) {
      result.add((FieldError) objectError);
    }
  }
  return Collections.unmodifiableList(result);
}

代码示例来源:origin: skylot/jadx

@Override
public List<IContainer> getBranches() {
  List<IContainer> branches = new ArrayList<>(cases.size() + 1);
  branches.addAll(cases);
  branches.add(defCase);
  return Collections.unmodifiableList(branches);
}

代码示例来源:origin: prestodb/presto

private List<String> getEndpoints(String keyspace, TokenRange tokenRange)
{
  Set<Host> endpoints = session.getReplicas(keyspace, tokenRange);
  return unmodifiableList(endpoints.stream()
      .map(Host::toString)
      .collect(toList()));
}

代码示例来源:origin: alibaba/canal

mutable_bitField0_ |= 0x00000001;
    beforeColumns_.add(input.readMessage(Column.PARSER, extensionRegistry));
    break;
     mutable_bitField0_ |= 0x00000002;
    afterColumns_.add(input.readMessage(Column.PARSER, extensionRegistry));
    break;
     mutable_bitField0_ |= 0x00000004;
    props_.add(input.readMessage(Pair.PARSER, extensionRegistry));
    break;
 throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
 throw new com.google.protobuf.InvalidProtocolBufferException(
   e.getMessage()).setUnfinishedMessage(this);
} finally {
 if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
  beforeColumns_ = java.util.Collections.unmodifiableList(beforeColumns_);
  afterColumns_ = java.util.Collections.unmodifiableList(afterColumns_);
  props_ = java.util.Collections.unmodifiableList(props_);

代码示例来源:origin: prestodb/presto

public static Iterable<List<Object>> fixData(List<Column> columns, Iterable<List<Object>> data)
{
  if (data == null) {
    return null;
  }
  requireNonNull(columns, "columns is null");
  List<TypeSignature> signatures = columns.stream()
      .map(column -> parseTypeSignature(column.getType()))
      .collect(toList());
  ImmutableList.Builder<List<Object>> rows = ImmutableList.builder();
  for (List<Object> row : data) {
    checkArgument(row.size() == columns.size(), "row/column size mismatch");
    List<Object> newRow = new ArrayList<>();
    for (int i = 0; i < row.size(); i++) {
      newRow.add(fixValue(signatures.get(i), row.get(i)));
    }
    rows.add(unmodifiableList(newRow)); // allow nulls in list
  }
  return rows.build();
}

代码示例来源:origin: Netflix/servo

/**
 * Get the list of all values that are members of this cache. Does not
 * affect the access time used for eviction.
 */
public List<V> values() {
 final Collection<Entry<V>> values = map.values();
 // Note below that e.value avoids updating the access time
 final List<V> res = values.stream().map(e -> e.value).collect(Collectors.toList());
 return Collections.unmodifiableList(res);
}

代码示例来源:origin: prestodb/presto

private ComputedStatistics(
    List<String> groupingColumns,
    List<Block> groupingValues,
    Map<TableStatisticType, Block> tableStatistics,
    Map<ColumnStatisticMetadata, Block> columnStatistics)
{
  this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
  this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
  if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
  }
  this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
  if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
  }
  this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
  if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
  }
}

代码示例来源:origin: alibaba/canal

boolean done = false;
 while (!done) {
  int tag = input.readTag();
  switch (tag) {
   case 0:
     mutable_bitField0_ |= 0x00000002;
    messages_.add(input.readBytes());
    break;
 throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
 throw new com.google.protobuf.InvalidProtocolBufferException(
   e).setUnfinishedMessage(this);
} finally {
 if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
  messages_ = java.util.Collections.unmodifiableList(messages_);

代码示例来源:origin: spring-projects/spring-framework

@Override
public List<ObjectError> getGlobalErrors() {
  List<ObjectError> result = new LinkedList<>();
  for (ObjectError objectError : this.errors) {
    if (!(objectError instanceof FieldError)) {
      result.add(objectError);
    }
  }
  return Collections.unmodifiableList(result);
}

代码示例来源:origin: skylot/jadx

@Override
public List<IContainer> getSubBlocks() {
  List<IContainer> all = new ArrayList<>(cases.size() + 2);
  all.add(header);
  all.addAll(cases);
  if (defCase != null) {
    all.add(defCase);
  }
  return Collections.unmodifiableList(all);
}

代码示例来源:origin: SonarSource/sonarqube

public List<Flow> flows() {
 return this.flows.stream()
  .<Flow>map(l -> () -> unmodifiableList(new ArrayList<>(l)))
  .collect(toList());
}

代码示例来源:origin: prestodb/presto

public static Iterable<List<Object>> fixData(List<Column> columns, Iterable<List<Object>> data)
{
  if (data == null) {
    return null;
  }
  requireNonNull(columns, "columns is null");
  List<TypeSignature> signatures = columns.stream()
      .map(column -> parseTypeSignature(column.getType()))
      .collect(toList());
  ImmutableList.Builder<List<Object>> rows = ImmutableList.builder();
  for (List<Object> row : data) {
    checkArgument(row.size() == columns.size(), "row/column size mismatch");
    List<Object> newRow = new ArrayList<>();
    for (int i = 0; i < row.size(); i++) {
      newRow.add(fixValue(signatures.get(i), row.get(i)));
    }
    rows.add(unmodifiableList(newRow)); // allow nulls in list
  }
  return rows.build();
}

代码示例来源:origin: SonarSource/sonarqube

public List<String> getLeaves() {
 return unmodifiableList(relations.values()
  .stream()
  .filter(qualifier -> relations.get(qualifier).isEmpty())
  .collect(Collectors.toList()));
}

代码示例来源:origin: prestodb/presto

private ComputedStatistics(
    List<String> groupingColumns,
    List<Block> groupingValues,
    Map<TableStatisticType, Block> tableStatistics,
    Map<ColumnStatisticMetadata, Block> columnStatistics)
{
  this.groupingColumns = unmodifiableList(new ArrayList<>(requireNonNull(groupingColumns, "groupingColumns is null")));
  this.groupingValues = unmodifiableList(new ArrayList<>(requireNonNull(groupingValues, "groupingValues is null")));
  if (!groupingValues.stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("grouping value blocks are expected to be single value blocks");
  }
  this.tableStatistics = unmodifiableMap(new HashMap<>(requireNonNull(tableStatistics, "tableStatistics is null")));
  if (!tableStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed table statistics blocks are expected to be single value blocks");
  }
  this.columnStatistics = unmodifiableMap(new HashMap<>(requireNonNull(columnStatistics, "columnStatistics is null")));
  if (!columnStatistics.values().stream().allMatch(ComputedStatistics::isSingleValueBlock)) {
    throw new IllegalArgumentException("computed column statistics blocks are expected to be single value blocks");
  }
}

代码示例来源:origin: alibaba/canal

boolean done = false;
 while (!done) {
  int tag = input.readTag();
  switch (tag) {
   case 0:
     mutable_bitField0_ |= 0x00000004;
    props_.add(input.readMessage(Pair.PARSER, extensionRegistry));
    break;
 throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
 throw new com.google.protobuf.InvalidProtocolBufferException(
   e.getMessage()).setUnfinishedMessage(this);
} finally {
 if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) {
  props_ = java.util.Collections.unmodifiableList(props_);

代码示例来源:origin: spring-projects/spring-framework

public List<String> getStringValues() {
  List<String> stringList = new ArrayList<>(this.values.size());
  for (Object value : this.values) {
    stringList.add(value.toString());
  }
  return Collections.unmodifiableList(stringList);
}

代码示例来源:origin: square/okhttp

/** Returns a snapshot of the calls currently being executed. */
public synchronized List<Call> runningCalls() {
 List<Call> result = new ArrayList<>();
 result.addAll(runningSyncCalls);
 for (AsyncCall asyncCall : runningAsyncCalls) {
  result.add(asyncCall.get());
 }
 return Collections.unmodifiableList(result);
}

代码示例来源:origin: apache/storm

@Override
public void open(Map<String, Object> conf, TopologyContext context, SpoutOutputCollector collector) {
  streams = Collections.unmodifiableList(streamStats.stream()
    .map((ss) -> new OutputStreamEngineWithHisto(ss, context)).collect(Collectors.toList()));
  this.collector = collector;
}

代码示例来源:origin: org.springframework.boot/spring-boot

@SafeVarargs
public ServletContextInitializerBeans(ListableBeanFactory beanFactory,
    Class<? extends ServletContextInitializer>... initializerTypes) {
  this.initializers = new LinkedMultiValueMap<>();
  this.initializerTypes = (initializerTypes.length != 0)
      ? Arrays.asList(initializerTypes)
      : Collections.singletonList(ServletContextInitializer.class);
  addServletContextInitializerBeans(beanFactory);
  addAdaptableBeans(beanFactory);
  List<ServletContextInitializer> sortedInitializers = this.initializers.values()
      .stream()
      .flatMap((value) -> value.stream()
          .sorted(AnnotationAwareOrderComparator.INSTANCE))
      .collect(Collectors.toList());
  this.sortedList = Collections.unmodifiableList(sortedInitializers);
  logMappings(this.initializers);
}

代码示例来源:origin: alibaba/canal

boolean done = false;
 while (!done) {
  int tag = input.readTag();
  switch (tag) {
   case 0:
     mutable_bitField0_ |= 0x00000004;
    props_.add(input.readMessage(Pair.PARSER, extensionRegistry));
    break;
 throw e.setUnfinishedMessage(this);
} catch (java.io.IOException e) {
 throw new com.google.protobuf.InvalidProtocolBufferException(
   e.getMessage()).setUnfinishedMessage(this);
} finally {
 if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) {
  props_ = java.util.Collections.unmodifiableList(props_);

相关文章

微信公众号

最新文章

更多

Collections类方法