ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/collections/ConcurrentLruCache.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/collections/ConcurrentLruCache.java
Status
scanned
Type
file
Name
ConcurrentLruCache.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3087 (3.0 KB)
MD5
1c2d6600c4059f8b0b6d2b9bdd60519d
SHA1
aae884df7b60aad891b3d5d14702609a67f43c71
SHA256
8936fd21de72f16065eea5cbe68f992fd149fe97bbb5b46e7b3143fe2f35ad5f
SHA512

      
    
SHA1_git
6e2b84e2f77617f1976b981cebf1eb9993be97fd
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ConcurrentLruCache.java | 3.0 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.util.collections; import java.io.Serial; import java.util.LinkedHashMap; import java.util.Map; public class ConcurrentLruCache<T> { private volatile LimitedLinkedHashMap<T,T> map; private final Object lock = new Object(); public ConcurrentLruCache(int limit) { setLimit(limit); } public void add(T entry) { if (map == null) { return; } synchronized (lock) { if (map == null) { return; } map.put(entry, entry); } } public boolean contains(T entry) { if (map == null) { return false; } synchronized (lock) { if (map == null) { return false; } return map.get(entry) != null; } } public void clear() { if (map == null) { return; } synchronized (lock) { if (map == null) { return; } map.clear(); } } public void setLimit(int limit) { synchronized (lock) { if (limit > 0) { Map<T,T> oldMap = map; map = new LimitedLinkedHashMap<>(limit); if (oldMap != null) { map.putAll(oldMap); } } else { map = null; } } } public int getLimit() { synchronized (lock) { if (map == null) { return -1; } else { return map.getLimit(); } } } private static class LimitedLinkedHashMap<K, V> extends LinkedHashMap<K,V> { @Serial private static final long serialVersionUID = 1L; private final int limit; LimitedLinkedHashMap(int limit) { super(16, 0.75F, true); this.limit = limit; } @Override protected boolean removeEldestEntry(Map.Entry<K,V> eldest) { return size() > limit; } private int getLimit() { return limit; } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
39.14
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9