ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/util/SmallMap.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/util/SmallMap.java
Status
scanned
Type
file
Name
SmallMap.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
2462 (2.4 KB)
MD5
f67d4a852a073e398a973903262beb0b
SHA1
ccafc51a46b0127e309bc9b8474d579f37c45699
SHA256
7dcc5edf11b21ce1def294f607522f1a33ed4a347d67ed3381d8ac8da1470467
SHA512

      
    
SHA1_git
8415128ddf2b0690b7fd29f9d128e26c23c3205b
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
SmallMap.java | 2.4 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.util; import java.util.HashMap; import java.util.Iterator; import org.h2.api.ErrorCode; import org.h2.message.DbException; /** * A simple hash table with an optimization for the last recently used object. */ public class SmallMap { private final HashMap<Integer, Object> map = new HashMap<>(); private Object cache; private int cacheId; private int lastId; private final int maxElements; /** * Create a map with the given maximum number of entries. * * @param maxElements the maximum number of entries */ public SmallMap(int maxElements) { this.maxElements = maxElements; } /** * Add an object to the map. If the size of the map is larger than twice the * maximum size, objects with a low id are removed. * * @param id the object id * @param o the object * @return the id */ public int addObject(int id, Object o) { if (map.size() > maxElements * 2) { Iterator<Integer> it = map.keySet().iterator(); while (it.hasNext()) { Integer k = it.next(); if (k + maxElements < lastId) { it.remove(); } } } if (id > lastId) { lastId = id; } map.put(id, o); cacheId = id; cache = o; return id; } /** * Remove an object from the map. * * @param id the id of the object to remove */ public void freeObject(int id) { if (cacheId == id) { cacheId = -1; cache = null; } map.remove(id); } /** * Get an object from the map if it is stored. * * @param id the id of the object * @param ifAvailable only return it if available, otherwise return null * @return the object or null * @throws DbException if isAvailable is false and the object has not been * found */ public Object getObject(int id, boolean ifAvailable) { if (id == cacheId) { return cache; } Object obj = map.get(id); if (obj == null && !ifAvailable) { throw DbException.get(ErrorCode.OBJECT_CLOSED); } return obj; } }
Detected license expression

      
    
Detected license expression (SPDX)

      
    
Percentage of license text
3.81
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License expression License clue details
(mpl-2.0 OR epl-1.0) AND proprietary-license {'score': 20.37, 'matcher': '3-seq', 'end_line': 3, 'rule_url': 'https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'from_file': None, 'start_line': 2, 'matched_text': ' * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,\n * and the EPL 1.0 (https://h2database.com/html/license.html).', 'match_coverage': 20.37, 'matched_length': 11, 'rule_relevance': 100, 'rule_identifier': 'mpl-2.0_or_epl-1.0_and_proprietary-license_2.RULE', 'license_expression': '(mpl-2.0 OR epl-1.0) AND proprietary-license', 'license_expression_spdx': '(MPL-2.0 OR EPL-1.0) AND LicenseRef-scancode-proprietary-license'}
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220