GVKun编程网logo

评估list.contains JSTL中的字符串

8

想了解评估list.containsJSTL中的字符串的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于.net大数据量,查找Where优化(List的Contains与Dictiona

想了解评估list.contains JSTL中的字符串的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于.net 大数据量,查找 Where 优化(List 的 Contains 与 Dictionary 的 ContainsKey 的比较)、ArrayList 的 contains() 方法如何评估对象?、AssertContains 在 jUnit 中的字符串上、com.intellij.util.containers.ConcurrentList的实例源码的新知识。

本文目录一览:

评估list.contains JSTL中的字符串

评估list.contains JSTL中的字符串

如果JSP中存在某些值,则需要隐藏一个元素

值存储在列表中,所以我尝试了:

<c:if test="${  mylist.contains( myValue ) }">display:none;''</c:if>

但是,它不起作用。

如何评估列表是否包含JSTL中的值,列表和值是字符串。

答案1

小编典典

可悲的是,我认为JSTL除了支持所有元素的迭代来解决这个问题之外,不支持任何其他功能。过去,我在核心标签库中使用过forEach方法:

<c:set var="contains" value="false" /><c:forEach var="item" items="${myList}">  <c:if test="${item eq myValue}">    <c:set var="contains" value="true" />  </c:if></c:forEach>

运行之后,如果myList包含myValue,则$ {contains}将等于“ true”。

.net 大数据量,查找 Where 优化(List 的 Contains 与 Dictionary 的 ContainsKey 的比较)

.net 大数据量,查找 Where 优化(List 的 Contains 与 Dictionary 的 ContainsKey 的比较)

 最近优化一个 where 查询条件,查询时间很慢,改为用 Dictionary 就很快了。

 

 一、样例

 

假设:listPicsTemp 有 100w 条数据,pictures 有 1000w 条数据。

 

使用第 1 段代码执行超过 2 分钟。

var listPicsTemp = new List<string>();

pictures = pictures.AsParallel().Where(d => listPicsTemp.Contains(d.Pic)).ToList();

 

使用第 2 段代码执行十几毫秒。

var listPicsTemp = new List<string>();

var dicPicsTemp = listPicsTemp.Where(d => d != null).Distinct().ToDictionary(d => d);//使用Dictionary类型,速度快很多

pictures = pictures.AsParallel().Where(d => dicPicsTemp.ContainsKey(d.Pic)).ToList();

 

二、为什么 Dictionary 这么快呢?查看了一下微软官方文档。

 

下面截图来源:https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.generic.dictionary-2?view=netframework-4.7.2

 

 

三、查看源码

 

List 的源码:https://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs,cf7f4095e4de7646

List 的 Contains,是循环 for 查找的。

 

Dictionary 的源码: https://referencesource.microsoft.com/#mscorlib/system/collections/generic/dictionary.cs,bcd13bb775d408f1

Dictionary 的 ContainsKey,是通过 hash 查找的。

 

 

 四、小结:

1、Dictionary<TKey,TValue> 类实现为哈希表。ContainsKey () 内部是通过 Hash 查找实现的,查询的时间复杂度是 O (1)。所以,查询很快。(List 的 Contains 是通过 for 查找的)

2、Dictionary 不是线程安全的。(查看微软官方文档,确实能学到很多知识盲区。)

ArrayList 的 contains() 方法如何评估对象?

ArrayList 的 contains() 方法如何评估对象?

假设我创建了一个对象并将其添加到我的ArrayList.
如果我然后创建另一个具有完全相同的构造函数输入的对象,该contains()方法会将这两个对象评估为相同吗?假设构造函数没有对输入做任何有趣的事情,并且存储在两个对象中的变量是相同的。

ArrayList<Thing> basket = new ArrayList<Thing>();  Thing thing = new Thing(100);  basket.add(thing);  Thing another = new Thing(100);  basket.contains(another); // true or false?

class Thing {      public int value;    public Thing (int x) {        value = x;    }    equals (Thing x) {        if (x.value == value) return true;        return false;    }}

这是class应该如何实现contains()returntrue吗?

答案1

小编典典

ArrayListimplements列表接口。

如果您查看该方法的Javadoc,Listcontains您将看到它使用该equals()方法来评估两个对象是否相同。

AssertContains 在 jUnit 中的字符串上

AssertContains 在 jUnit 中的字符串上

有没有更好的方法在 jUnit 中编写

String x = "foo bar";
Assert.assertTrue(x.contains("foo"));

com.intellij.util.containers.ConcurrentList的实例源码

com.intellij.util.containers.ConcurrentList的实例源码

项目:intellij-ce-playground    文件:ControlFlowFactory.java   
private void registerControlFlow(@NotNull PsiElement element,@NotNull ControlFlow flow,boolean evaluateConstantIfCondition,boolean enableShortCircuit,@NotNull ControlFlowPolicy policy) {
  final long modificationCount = element.getManager().getModificationTracker().getModificationCount();
  ControlFlowContext controlFlowContext = createContext(evaluateConstantIfCondition,enableShortCircuit,policy,flow,modificationCount);

  ConcurrentList<ControlFlowContext> cached = getorCreateCachedFlowsForElement(element);
  cached.addIfAbsent(controlFlowContext);
}
项目:intellij-ce-playground    文件:ControlFlowFactory.java   
@NotNull
private ConcurrentList<ControlFlowContext> getorCreateCachedFlowsForElement(@NotNull PsiElement element) {
  ConcurrentList<ControlFlowContext> cached = cachedFlows.get(element);
  if (cached == null) {
    cached = ContainerUtil.createConcurrentList();
    cachedFlows.put(element,cached);
  }
  return cached;
}
项目:intellij-ce-playground    文件:InjectedLanguageUtil.java   
@NotNull
public static ConcurrentList<Documentwindow> getCachedInjectedDocuments(@NotNull PsiFile hostPsiFile) {
  // modification of cachedInjectedDocuments must be under PsiLock only
  ConcurrentList<Documentwindow> injected = hostPsiFile.getUserData(INJECTED_DOCS_KEY);
  if (injected == null) {
    injected =
      ((UserDataHolderEx)hostPsiFile).putUserDataifAbsent(INJECTED_DOCS_KEY,ContainerUtil.<Documentwindow>createConcurrentList());
  }
  return injected;
}
项目:consulo    文件:InjectedLanguageUtil.java   
/**
 * @deprecated use {@link InjectedLanguageManager#getCachedInjectedDocumentsInRange(PsiFile,TextRange)} instead
 */
@Nonnull
@Deprecated
public static ConcurrentList<Documentwindow> getCachedInjectedDocuments(@Nonnull PsiFile hostPsiFile) {
  // modification of cachedInjectedDocuments must be under InjectedLanguageManagerImpl.ourInjectionPsiLock only
  ConcurrentList<Documentwindow> injected = hostPsiFile.getUserData(INJECTED_DOCS_KEY);
  if (injected == null) {
    injected = ((UserDataHolderEx)hostPsiFile).putUserDataifAbsent(INJECTED_DOCS_KEY,ContainerUtil.createConcurrentList());
  }
  return injected;
}
项目:consulo-java    文件:ControlFlowFactory.java   
private void registerControlFlow(@NotNull PsiElement element,@NotNull ControlFlowPolicy policy)
{
    final long modificationCount = element.getManager().getModificationTracker().getModificationCount();
    ControlFlowContext controlFlowContext = createContext(evaluateConstantIfCondition,modificationCount);

    ConcurrentList<ControlFlowContext> cached = getorCreateCachedFlowsForElement(element);
    cached.addIfAbsent(controlFlowContext);
}
项目:consulo-java    文件:ControlFlowFactory.java   
@NotNull
private ConcurrentList<ControlFlowContext> getorCreateCachedFlowsForElement(@NotNull PsiElement element)
{
    ConcurrentList<ControlFlowContext> cached = cachedFlows.get(element);
    if(cached == null)
    {
        cached = ContainerUtil.createConcurrentList();
        cachedFlows.put(element,cached);
    }
    return cached;
}

今天关于评估list.contains JSTL中的字符串的介绍到此结束,谢谢您的阅读,有关.net 大数据量,查找 Where 优化(List 的 Contains 与 Dictionary 的 ContainsKey 的比较)、ArrayList 的 contains() 方法如何评估对象?、AssertContains 在 jUnit 中的字符串上、com.intellij.util.containers.ConcurrentList的实例源码等更多相关知识的信息可以在本站进行查询。

本文标签: