java.util.List.clear()方法的使用及代码示例

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

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

List.clear介绍

[英]Removes all elements from this List, leaving it empty.
[中]删除此列表中的所有元素,将其保留为空。

代码示例

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

/**
 * Configure "streaming" media types for which flushing should be performed
 * automatically vs at the end of the stream.
 * <p>By default this is set to {@link MediaType#APPLICATION_STREAM_JSON}.
 * @param mediaTypes one or more media types to add to the list
 * @see HttpMessageEncoder#getStreamingMediaTypes()
 */
public void setStreamingMediaTypes(List<MediaType> mediaTypes) {
  this.streamingMediaTypes.clear();
  this.streamingMediaTypes.addAll(mediaTypes);
}

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

/**
 * Set the locale of the request, overriding any previous locales.
 * @param locale the locale, or {@code null} to reset it
 * @see #locale(Locale...)
 */
public MockHttpServletRequestBuilder locale(@Nullable Locale locale) {
  this.locales.clear();
  if (locale != null) {
    this.locales.add(locale);
  }
  return this;
}

代码示例来源:origin: libgdx/libgdx

private void takeSnapshot () {
  mainDependenciesSnapshot.clear();
  for (int i = 0; i < mainDependencies.size(); i++) {
    mainDependenciesSnapshot.add(mainDependencies.get(i));
  }
}

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

public void addRecentFile(String filePath) {
  recentFiles.remove(filePath);
  recentFiles.add(0, filePath);
  int count = recentFiles.size();
  if (count > RECENT_FILES_COUNT) {
    recentFiles.subList(RECENT_FILES_COUNT, count).clear();
  }
  partialSync(settings -> settings.recentFiles = recentFiles);
}

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

/**
 * Remove all registered transformers, in inverse order of registration.
 */
public void removeTransformers() {
  synchronized (this.transformers) {
    if (this.instrumentation != null && !this.transformers.isEmpty()) {
      for (int i = this.transformers.size() - 1; i >= 0; i--) {
        this.instrumentation.removeTransformer(this.transformers.get(i));
      }
      this.transformers.clear();
    }
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
public void writeRowEnd()
{
 // Avoid writing blank lines, users may confuse them with the trailer.
 final boolean quoteEverything = currentLine.size() == 1 && currentLine.get(0).isEmpty();
 writer.writeNext(currentLine.toArray(new String[0]), quoteEverything);
 currentLine.clear();
}

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

private void ack(List<Tuple> tuples) {
  if (!tuples.isEmpty()) {
    LOG.debug("Acking {} tuples", tuples.size());
    for (Tuple tuple : tuples) {
      collector.delegate.ack(tuple);
    }
    tuples.clear();
  }
}

代码示例来源:origin: thinkaurelius/titan

@Override
protected void action() {
  MessageEnvelope msg;
  //Opportunistically drain the queue for up to the batch-send-size number of messages before evaluating condition
  while (toSend.size()<sendBatchSize && (msg=outgoingMsg.poll())!=null) {
    toSend.add(msg);
  }
  //Evaluate send condition: 1) Is the oldest message waiting longer than the delay? or 2) Do we have enough messages to send?
  if (!toSend.isEmpty() && (maxSendDelay.compareTo(timeSinceFirstMsg()) <= 0 || toSend.size() >= sendBatchSize)) {
    try {
      sendMessages(toSend);
    } finally {
      toSend.clear();
    }
  }
}

代码示例来源:origin: twosigma/beakerx

public void jobStart(int jobId, List<String> executorIds) {
 activeJobId = jobId;
 if (!jobs.contains(jobId)) {
  jobs.add(jobId);
  stagesPerJob.put(jobId, new ArrayList<Integer>());
 }
 if (!executorIds.isEmpty()) {
  this.executorIds.clear();
  this.executorIds.addAll(executorIds);
 }
}

代码示例来源:origin: JetBrains/ideavim

public void reset() {
 myRows.clear();
 for (Map.Entry<KeyStroke, ShortcutOwner> entry : VimPlugin.getKey().getShortcutConflicts().entrySet()) {
  final KeyStroke keyStroke = entry.getKey();
  final List<AnAction> actions = VimPlugin.getKey().getKeymapConflicts(keyStroke);
  if (!actions.isEmpty()) {
   myRows.add(new Row(keyStroke, actions.get(0), entry.getValue()));
  }
 }
 Collections.sort(myRows);
}

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

/**
 * Drain all the calls from newCalls into pendingCalls.
 *
 * This function holds the lock for the minimum amount of time, to avoid blocking
 * users of AdminClient who will also take the lock to add new calls.
 */
private synchronized void drainNewCalls() {
  if (!newCalls.isEmpty()) {
    pendingCalls.addAll(newCalls);
    newCalls.clear();
  }
}

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

private static void insertAtStart(BlockNode block, List<InsnNode> insns) {
  List<InsnNode> blockInsns = block.getInstructions();
  List<InsnNode> newInsnList = new ArrayList<>(insns.size() + blockInsns.size());
  newInsnList.addAll(insns);
  newInsnList.addAll(blockInsns);
  blockInsns.clear();
  blockInsns.addAll(newInsnList);
}

代码示例来源:origin: bumptech/glide

public synchronized void setBucketPriorityList(@NonNull List<String> buckets) {
 List<String> previousBuckets = new ArrayList<>(bucketPriorityList);
 bucketPriorityList.clear();
 bucketPriorityList.addAll(buckets);
 for (String previousBucket : previousBuckets) {
  if (!buckets.contains(previousBucket)) {
   // Keep any buckets from the previous list that aren't included here, but but them at the
   // end.
   bucketPriorityList.add(previousBucket);
  }
 }
}

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

private void updateFilters() {
  if (this.filters.isEmpty()) {
    return;
  }
  List<WebFilter> filtersToUse = this.filters.stream()
      .peek(filter -> {
        if (filter instanceof ForwardedHeaderTransformer && this.forwardedHeaderTransformer == null) {
          this.forwardedHeaderTransformer = (ForwardedHeaderTransformer) filter;
        }
      })
      .filter(filter -> !(filter instanceof ForwardedHeaderTransformer))
      .collect(Collectors.toList());
  this.filters.clear();
  this.filters.addAll(filtersToUse);
}

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

public boolean test(List<String> l1, List<String> l2) {
    if (l2.size() > 0) {
      l1.clear();
    }
    return l1.size() == 0;
  }
}

代码示例来源:origin: commons-io/commons-io

/**
 * @see java.io.ByteArrayOutputStream#reset()
 */
public synchronized void reset() {
  count = 0;
  filledBufferSum = 0;
  currentBufferIndex = 0;
  if (reuseBuffers) {
    currentBuffer = buffers.get(currentBufferIndex);
  } else {
    //Throw away old buffers
    currentBuffer = null;
    final int size = buffers.get(0).length;
    buffers.clear();
    needNewBuffer(size);
    reuseBuffers = true;
  }
}

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

@Override
public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
    Function<ClientResponse, Mono<? extends Throwable>> exceptionFunction) {
  if (this.statusHandlers.size() == 1 && this.statusHandlers.get(0) == DEFAULT_STATUS_HANDLER) {
    this.statusHandlers.clear();
  }
  this.statusHandlers.add(new StatusHandler(statusPredicate,
      (clientResponse, request) -> exceptionFunction.apply(clientResponse)));
  return this;
}

代码示例来源:origin: google/ExoPlayer

public void rollUp() {
 rolledUpCaptions.add(buildSpannableString());
 captionStringBuilder.setLength(0);
 cueStyles.clear();
 int numRows = Math.min(captionRowCount, row);
 while (rolledUpCaptions.size() >= numRows) {
  rolledUpCaptions.remove(0);
 }
}

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

/**
 * Remove all registered transformers, in inverse order of registration.
 */
public void removeTransformers() {
  synchronized (this.transformers) {
    if (this.instrumentation != null && !this.transformers.isEmpty()) {
      for (int i = this.transformers.size() - 1; i >= 0; i--) {
        this.instrumentation.removeTransformer(this.transformers.get(i));
      }
      this.transformers.clear();
    }
  }
}

代码示例来源:origin: google/j2objc

public void setMethodForStubbing(InvocationMatcher invocation) {
  invocationForStubbing = invocation;
  assert hasAnswersForStubbing();
  for (int i = 0; i < answersForStubbing.size(); i++) {
    addAnswer(answersForStubbing.get(i), i != 0);
  }
  answersForStubbing.clear();
}

相关文章