本文整理了Java中java.util.List.isEmpty()
方法的一些代码示例,展示了List.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.isEmpty()
方法的具体详情如下:
包路径:java.util.List
类名称:List
方法名:isEmpty
[英]Returns whether this List contains no elements.
[中]返回此列表是否不包含任何元素。
代码示例来源:origin: spring-projects/spring-framework
private Node getParent() {
if (!this.elements.isEmpty()) {
return this.elements.get(this.elements.size() - 1);
}
else {
return this.node;
}
}
代码示例来源:origin: square/okhttp
public Builder removePathSegment(int index) {
encodedPathSegments.remove(index);
if (encodedPathSegments.isEmpty()) {
encodedPathSegments.add(""); // Always leave at least one '/'.
}
return this;
}
代码示例来源:origin: alibaba/druid
public boolean hasBeforeComment() {
if (attributes == null) {
return false;
}
List<String> comments = (List<String>) attributes.get("format.before_comment");
if (comments == null) {
return false;
}
return !comments.isEmpty();
}
代码示例来源:origin: hankcs/HanLP
public void setPenalty(int i, int j, double penalty)
{
if (penalty_.isEmpty())
{
for (int s = 0; s < node_.size(); s++)
{
List<Double> penaltys = Arrays.asList(new Double[ysize_]);
penalty_.add(penaltys);
}
}
penalty_.get(i).set(j, penalty);
}
代码示例来源:origin: square/okhttp
/**
* Removes a path segment. When this method returns the last segment is always "", which means
* the encoded path will have a trailing '/'.
*
* <p>Popping "/a/b/c/" yields "/a/b/". In this case the list of path segments goes from ["a",
* "b", "c", ""] to ["a", "b", ""].
*
* <p>Popping "/a/b/c" also yields "/a/b/". The list of path segments goes from ["a", "b", "c"]
* to ["a", "b", ""].
*/
private void pop() {
String removed = encodedPathSegments.remove(encodedPathSegments.size() - 1);
// Make sure the path ends with a '/' by either adding an empty string or clearing a segment.
if (removed.isEmpty() && !encodedPathSegments.isEmpty()) {
encodedPathSegments.set(encodedPathSegments.size() - 1, "");
} else {
encodedPathSegments.add("");
}
}
代码示例来源:origin: facebook/litho
private static void removeCompletedStateUpdatesFromMap(
Map<String, List<StateUpdate>> currentStateUpdates,
Map<String, List<StateUpdate>> completedStateUpdates,
String key) {
List<StateUpdate> completed = completedStateUpdates.get(key);
List<StateUpdate> current = currentStateUpdates.remove(key);
if (completed != null && current != null) {
current.removeAll(completed);
}
if (current != null && !current.isEmpty()) {
currentStateUpdates.put(key, current);
}
}
代码示例来源:origin: jenkinsci/jenkins
public RenderOnDemandClosure(JellyContext context, String attributesToCapture) {
List<Script> bodyStack = new ArrayList<Script>();
for (JellyContext c = context; c!=null; c=c.getParent()) {
Script script = (Script) c.getVariables().get("org.apache.commons.jelly.body");
if(script!=null) bodyStack.add(script);
}
this.bodyStack = bodyStack.toArray(new Script[bodyStack.size()]);
assert !bodyStack.isEmpty(); // there must be at least one, which is the direct child of <l:renderOnDemand>
Map<String,Object> variables = new HashMap<String, Object>();
for (String v : Util.fixNull(attributesToCapture).split(","))
variables.put(v.intern(),context.getVariable(v));
// capture the current base of context for descriptors
currentDescriptorByNameUrl = Descriptor.getCurrentDescriptorByNameUrl();
this.variables = PackedMap.of(variables);
Set<String> _adjuncts = AdjunctsInPage.get().getIncluded();
this.adjuncts = new String[_adjuncts.size()];
int i = 0;
for (String adjunct : _adjuncts) {
this.adjuncts[i++] = adjunct.intern();
}
}
代码示例来源:origin: spring-projects/spring-framework
private static List<Element> prependWithSeparator(List<Element> elements) {
List<Element> result = new ArrayList<>(elements);
if (result.isEmpty() || !(result.get(0) instanceof Separator)) {
result.add(0, SEPARATOR);
}
return Collections.unmodifiableList(result);
}
代码示例来源:origin: apache/kafka
public Header[] toArray() {
return headers.isEmpty() ? Record.EMPTY_HEADERS : headers.toArray(new Header[headers.size()]);
}
代码示例来源:origin: google/guava
public void testAsMapGet() {
for (K key : sampleKeys()) {
List<V> expectedValues = new ArrayList<>();
for (Entry<K, V> entry : getSampleElements()) {
if (entry.getKey().equals(key)) {
expectedValues.add(entry.getValue());
}
}
Collection<V> collection = multimap().asMap().get(key);
if (expectedValues.isEmpty()) {
assertNull(collection);
} else {
assertEqualIgnoringOrder(expectedValues, collection);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
private static Profiles merge(String expression, List<Profiles> elements, @Nullable Operator operator) {
assertWellFormed(expression, !elements.isEmpty());
if (elements.size() == 1) {
return elements.get(0);
}
Profiles[] profiles = elements.toArray(new Profiles[0]);
return (operator == Operator.AND ? and(profiles) : or(profiles));
}
代码示例来源: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: apache/incubator-dubbo
@Override
public List<URL> lookup(URL url) {
List<URL> urls = new ArrayList<>();
Map<String, List<URL>> notifiedUrls = getNotified().get(url);
if (notifiedUrls != null && notifiedUrls.size() > 0) {
for (List<URL> values : notifiedUrls.values()) {
urls.addAll(values);
if (urls.isEmpty()) {
List<URL> cacheUrls = getCacheUrls(url);
if (CollectionUtils.isNotEmpty(cacheUrls)) {
urls.addAll(cacheUrls);
if (urls.isEmpty()) {
for (URL u : getRegistered()) {
if (UrlUtils.isMatch(url, u)) {
urls.add(u);
for (URL u : getSubscribed().keySet()) {
if (UrlUtils.isMatch(url, u)) {
urls.add(u);
代码示例来源:origin: spring-projects/spring-framework
/**
* Return all configured {@link MappedInterceptor MappedInterceptors} as an array.
* @return the array of {@link MappedInterceptor MappedInterceptors}, or {@code null} if none
*/
@Nullable
protected final MappedInterceptor[] getMappedInterceptors() {
List<MappedInterceptor> mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size());
for (HandlerInterceptor interceptor : this.adaptedInterceptors) {
if (interceptor instanceof MappedInterceptor) {
mappedInterceptors.add((MappedInterceptor) interceptor);
}
}
return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null);
}
代码示例来源:origin: neo4j/neo4j
@Deprecated
@Override
public Map<String,List<String>> getExensionsFor( Class<?> type )
{
Map<String,List<String>> result = new HashMap<>();
for ( Map.Entry<String,ServerExtender> extension : extensions.entrySet() )
{
List<String> methods = new ArrayList<>();
for ( PluginPoint method : extension.getValue()
.getExtensionsFor( type ) )
{
methods.add( method.name() );
}
if ( !methods.isEmpty() )
{
result.put( extension.getKey(), methods );
}
}
return result;
}
代码示例来源:origin: google/guava
public static void assertContainsAllOf(Iterable<?> actual, Object... expected) {
List<Object> expectedList = new ArrayList<>();
expectedList.addAll(Arrays.asList(expected));
for (Object o : actual) {
expectedList.remove(o);
}
if (!expectedList.isEmpty()) {
Assert.fail("Not true that " + actual + " contains all of " + Arrays.asList(expected));
}
}
代码示例来源:origin: square/okhttp
/** Returns the remote peer's principle, or null if that peer is anonymous. */
public @Nullable Principal peerPrincipal() {
return !peerCertificates.isEmpty()
? ((X509Certificate) peerCertificates.get(0)).getSubjectX500Principal()
: null;
}
代码示例来源:origin: google/guava
static <E> List<List<E>> create(List<? extends List<? extends E>> lists) {
ImmutableList.Builder<List<E>> axesBuilder = new ImmutableList.Builder<>(lists.size());
for (List<? extends E> list : lists) {
List<E> copy = ImmutableList.copyOf(list);
if (copy.isEmpty()) {
return ImmutableList.of();
}
axesBuilder.add(copy);
}
return new CartesianList<E>(axesBuilder.build());
}
代码示例来源:origin: spring-projects/spring-framework
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
Map<Method, MessageExceptionHandler> methods = MethodIntrospector.selectMethods(handlerType,
(MethodIntrospector.MetadataLookup<MessageExceptionHandler>) method ->
AnnotatedElementUtils.findMergedAnnotation(method, MessageExceptionHandler.class));
Map<Class<? extends Throwable>, Method> result = new HashMap<>();
for (Map.Entry<Method, MessageExceptionHandler> entry : methods.entrySet()) {
Method method = entry.getKey();
List<Class<? extends Throwable>> exceptionTypes = new ArrayList<>();
exceptionTypes.addAll(Arrays.asList(entry.getValue().value()));
if (exceptionTypes.isEmpty()) {
exceptionTypes.addAll(getExceptionsFromMethodSignature(method));
}
for (Class<? extends Throwable> exceptionType : exceptionTypes) {
Method oldMethod = result.put(exceptionType, method);
if (oldMethod != null && !oldMethod.equals(method)) {
throw new IllegalStateException("Ambiguous @ExceptionHandler method mapped for [" +
exceptionType + "]: {" + oldMethod + ", " + method + "}");
}
}
}
return result;
}
代码示例来源:origin: prestodb/presto
public void add(Object value)
{
if (_accumulator.isEmpty()) {
_result.add(value);
} else {
CollectionReferring ref = _accumulator.get(_accumulator.size() - 1);
ref.next.add(value);
}
}
内容来源于网络,如有侵权,请联系作者删除!