List of usage examples for org.apache.commons.collections.map LRUMap get
public Object get(Object key)
From source file:de.hybris.platform.test.LRUMapTest.java
@Test public void testAgain() { final LRUMap map = new LRUMap(2); map.put("2", "zwei"); map.put("3", "drei"); map.get("2"); map.put("4", "vier"); assertEquals("zwei", map.get("2")); assertEquals(null, map.get("3")); assertEquals("vier", map.get("4")); }
From source file:de.hybris.platform.test.LRUMapTest.java
@Test public void testBug() { final LRUMap map = new LRUMap(2); map.put("1", "eins"); map.put("2", "zwei"); assertEquals("eins", map.get("1")); assertEquals("zwei", map.get("2")); map.put("3", "drei"); assertEquals(null, map.get("1")); assertEquals("zwei", map.get("2")); assertEquals("drei", map.get("3")); map.get("2"); map.put("4", "vier"); assertEquals(null, map.get("1")); assertEquals("zwei", map.get("2")); assertEquals(null, map.get("3")); assertEquals("vier", map.get("4")); }
From source file:edu.mayo.informatics.lexgrid.convert.directConversions.UMLSToSQL.java
private void loadOtherProperties(String UMLSCodingSchemeName, String cui, String codingSchemeName, String conceptCode, LRUMap TValues) throws SQLException { // Drop the CUI in. supportedPropertyTypes_.add("UMLS_CUI"); addToEntityProperty(codingSchemeName, SQLTableConstants.ENTITYTYPE_CONCEPT, conceptCode, "CUI-" + cuiCounter_++, "property", "UMLS_CUI", null, null, null, null, null, null, cui); // get the semantic type(s) supportedPropertyTypes_.add("Semantic_Type"); PreparedStatement getSemTypes = umlsConnection_.prepareStatement("SELECT STY FROM MRSTY WHERE CUI = ?"); getSemTypes.setString(1, cui);//from www. j av a 2s .c o m ResultSet semTypes = getSemTypes.executeQuery(); while (semTypes.next()) { addToEntityProperty(codingSchemeName, SQLTableConstants.ENTITYTYPE_CONCEPT, conceptCode, "SemType-" + semTypeCounter_++, "property", "Semantic_Type", null, SQLTableConstants.TBLCOLVAL_FORMAT_TXT_PLAIN, null, null, null, null, semTypes.getString("STY")); } getSemTypes.close(); // load the other properties PreparedStatement getProperties = umlsConnection_ .prepareStatement("SELECT ATN, ATV, STYPE, METAUI FROM MRSAT WHERE CODE = ? AND SAB = ?"); getProperties.setString(1, conceptCode); getProperties.setString(2, UMLSCodingSchemeName); ResultSet properties = getProperties.executeQuery(); ArrayList auiProps = new ArrayList(); while (properties.next()) { String propertyFlag = properties.getString("ATN"); String propertyValue = properties.getString("ATV"); String propertyStype = properties.getString("STYPE"); String propertyMetaui = properties.getString("METAUI"); String propertyId = null; String propertyName = null; String propertyType = null; String representationalForm = null; Boolean isPreferred = null; if (mrsatMap_.get(propertyFlag) != null && (propertyStype.equalsIgnoreCase("CODE") || propertyStype.equalsIgnoreCase("SCUI") || propertyStype.equalsIgnoreCase("SDUI"))) { Integer type = (Integer) mrsatMap_.get(propertyFlag); if (type.intValue() == SKIP.intValue()) { continue; } else if (type.intValue() == COMMENT.intValue()) { propertyId = "C-" + commentCounter_++; propertyType = SQLTableConstants.TBLCOLVAL_COMMENT; propertyName = SQLTableConstants.TBLCOLVAL_COMMENT; isPreferred = new Boolean(false); } else if (type.intValue() == INSTRUCTION.intValue()) { propertyId = "I-" + instructionCounter_++; propertyType = SQLTableConstants.TBLCOLVAL_INSTRUCTION; propertyName = SQLTableConstants.TBLCOLVAL_INSTRUCTION; isPreferred = new Boolean(false); } else if (type.intValue() == PRESENTATION.intValue()) { propertyId = "T-" + presentationCounter_++; propertyType = SQLTableConstants.TBLCOLVAL_PRESENTATION; propertyName = SQLTableConstants.TBLCOLVAL_TEXTUALPRESENTATION; TValues.put(propertyMetaui, propertyId); isPreferred = new Boolean(false); } } else if (propertyStype.equalsIgnoreCase("SAUI")) { auiProps.add(new AUI_PROP(propertyFlag, propertyValue, propertyStype, propertyMetaui)); continue; } else { propertyId = "P-" + propertyCounter_++; propertyType = SQLTableConstants.TBLCOLVAL_PROPERTY; propertyName = propertyFlag; } representationalForm = (String) atnRepresentationalMap_.get(propertyFlag); supportedPropertyTypes_.add(propertyName); addToEntityProperty(codingSchemeName, SQLTableConstants.ENTITYTYPE_CONCEPT, conceptCode, propertyId, propertyType, propertyName, null, SQLTableConstants.TBLCOLVAL_FORMAT_TXT_PLAIN, isPreferred, null, null, representationalForm, propertyValue); } Iterator aPIter = auiProps.iterator(); while (aPIter.hasNext()) { AUI_PROP ap = (AUI_PROP) aPIter.next(); String apPropertyId = (String) TValues.get(ap.metaui); if (apPropertyId == null) continue; if (!supportedPropertyQualifiers_.contains(ap.atn)) supportedPropertyQualifiers_.add(ap.atn); addConceptToEntityPropertyMultiAttributes(codingSchemeName, SQLTableConstants.ENTITYTYPE_CONCEPT, conceptCode, apPropertyId, SQLTableConstants.TBLCOLVAL_QUALIFIER, ap.atn, ap.atv, ""); } getProperties.close(); }
From source file:org.apache.accumulo.core.client.mapred.AccumuloFileOutputFormat.java
@Override public RecordWriter<Key, Value> getRecordWriter(FileSystem ignored, JobConf job, String name, Progressable progress) throws IOException { // get the path of the temporary output file final Configuration conf = job; final AccumuloConfiguration acuConf = FileOutputConfigurator.getAccumuloConfiguration(CLASS, job); final String extension = acuConf.get(Property.TABLE_FILE_TYPE); final Path file = new Path(getWorkOutputPath(job), getUniqueName(job, "part") + "." + extension); final LRUMap validVisibilities = new LRUMap(ConfiguratorBase.getVisibilityCacheSize(conf)); return new RecordWriter<Key, Value>() { FileSKVWriter out = null;// w w w .j a v a2s . com @Override public void close(Reporter reporter) throws IOException { if (out != null) out.close(); } @Override public void write(Key key, Value value) throws IOException { Boolean wasChecked = (Boolean) validVisibilities.get(key.getColumnVisibilityData()); if (wasChecked == null) { byte[] cv = key.getColumnVisibilityData().toArray(); new ColumnVisibility(cv); validVisibilities.put(new ArrayByteSequence(Arrays.copyOf(cv, cv.length)), Boolean.TRUE); } if (out == null) { out = FileOperations.getInstance().newWriterBuilder() .forFile(file.toString(), file.getFileSystem(conf), conf) .withTableConfiguration(acuConf).build(); out.startDefaultLocalityGroup(); } out.append(key, value); } }; }
From source file:org.apache.accumulo.core.client.mapreduce.AccumuloFileOutputFormat.java
@Override public RecordWriter<Key, Value> getRecordWriter(TaskAttemptContext context) throws IOException { // get the path of the temporary output file final Configuration conf = context.getConfiguration(); final AccumuloConfiguration acuConf = FileOutputConfigurator.getAccumuloConfiguration(CLASS, context.getConfiguration()); final String extension = acuConf.get(Property.TABLE_FILE_TYPE); final Path file = this.getDefaultWorkFile(context, "." + extension); final LRUMap validVisibilities = new LRUMap(1000); return new RecordWriter<Key, Value>() { FileSKVWriter out = null;//w ww . ja v a 2 s . co m @Override public void close(TaskAttemptContext context) throws IOException { if (out != null) out.close(); } @Override public void write(Key key, Value value) throws IOException { Boolean wasChecked = (Boolean) validVisibilities.get(key.getColumnVisibilityData()); if (wasChecked == null) { byte[] cv = key.getColumnVisibilityData().toArray(); new ColumnVisibility(cv); validVisibilities.put(new ArrayByteSequence(Arrays.copyOf(cv, cv.length)), Boolean.TRUE); } if (out == null) { out = FileOperations.getInstance().newWriterBuilder() .forFile(file.toString(), file.getFileSystem(conf), conf) .withTableConfiguration(acuConf).build(); out.startDefaultLocalityGroup(); } out.append(key, value); } }; }
From source file:org.apache.jackrabbit.core.query.lucene.DocNumberCache.java
/** * Puts a document number into the cache using a uuid as key. An entry is * only overwritten if the according reader is younger than the reader * associated with the existing entry./*w w w .j a v a 2s .c o m*/ * * @param uuid the key. * @param reader the index reader from where the document number was read. * @param n the document number. */ void put(String uuid, CachingIndexReader reader, int n) { LRUMap cacheSegment = docNumbers[getSegmentIndex(uuid.charAt(0))]; synchronized (cacheSegment) { Entry e = (Entry) cacheSegment.get(uuid); if (e != null) { // existing entry // ignore if reader is older than the one in entry if (reader.getCreationTick() <= e.creationTick) { if (log.isDebugEnabled()) { log.debug("Ignoring put(). New entry is not from a newer reader. " + "existing: " + e.creationTick + ", new: " + reader.getCreationTick()); } e = null; } } else { // entry did not exist e = new Entry(reader.getCreationTick(), n); } if (e != null) { cacheSegment.put(uuid, e); } } }
From source file:org.apache.jackrabbit.core.query.lucene.DocNumberCache.java
/** * Returns the cache entry for <code>uuid</code>, or <code>null</code> if * no entry exists for <code>uuid</code>. * * @param uuid the key.//www . j a va 2 s. c o m * @return cache entry or <code>null</code>. */ Entry get(String uuid) { LRUMap cacheSegment = docNumbers[getSegmentIndex(uuid.charAt(0))]; Entry entry; synchronized (cacheSegment) { entry = (Entry) cacheSegment.get(uuid); } if (log.isInfoEnabled()) { accesses++; if (entry == null) { misses++; } // log at most after 1000 accesses and every 10 seconds if (accesses > 1000 && System.currentTimeMillis() - lastLog > LOG_INTERVAL) { long ratio = 100; if (misses != 0) { ratio -= misses * 100L / accesses; } StringBuffer statistics = new StringBuffer(); int inUse = 0; for (LRUMap docNumber : docNumbers) { inUse += docNumber.size(); } statistics.append("size=").append(inUse); statistics.append("/").append(docNumbers[0].maxSize() * CACHE_SEGMENTS); statistics.append(", #accesses=").append(accesses); statistics.append(", #hits=").append((accesses - misses)); statistics.append(", #misses=").append(misses); statistics.append(", cacheRatio=").append(ratio).append("%"); log.info(statistics.toString()); accesses = 0; misses = 0; lastLog = System.currentTimeMillis(); } } return entry; }
From source file:org.apache.jena.security.impl.SecuredItemImpl.java
/** * get the cached value./* www . j a va2 s.c o m*/ * @param key The key to look for. * @return the value of the security check or <code>null</code> if the value has not been cached. */ private Boolean cacheGet(final CacheKey key) { final LRUMap cache = SecuredItemImpl.CACHE.get(); return (cache == null) ? null : (Boolean) cache.get(key); }
From source file:org.exoplatform.services.jcr.impl.core.query.lucene.DocNumberCache.java
/** * Puts a document number into the cache using a uuid as key. An entry is * only overwritten if the according reader is younger than the reader * associated with the existing entry.//from w ww . ja v a 2 s . c o m * * @param uuid the key. * @param reader the index reader from where the document number was read. * @param n the document number. */ void put(String uuid, CachingIndexReader reader, int n) { LRUMap cacheSegment = docNumbers[getSegmentIndex(uuid.charAt(0))]; //UUID key = UUID.fromString(uuid); String key = uuid; synchronized (cacheSegment) { Entry e = (Entry) cacheSegment.get(key); if (e != null) { // existing entry // ignore if reader is older than the one in entry if (reader.getCreationTick() <= e.creationTick) { if (log.isDebugEnabled()) { log.debug("Ignoring put(). New entry is not from a newer reader. " + "existing: " + e.creationTick + ", new: " + reader.getCreationTick()); } e = null; } } else { // entry did not exist e = new Entry(reader.getCreationTick(), n); } if (e != null) { cacheSegment.put(key, e); } } }
From source file:org.exoplatform.services.jcr.impl.core.query.lucene.DocNumberCache.java
/** * Returns the cache entry for <code>uuid</code>, or <code>null</code> if * no entry exists for <code>uuid</code>. * * @param uuid the key.//from w ww. ja v a2 s . c o m * @return cache entry or <code>null</code>. */ Entry get(String uuid) { LRUMap cacheSegment = docNumbers[getSegmentIndex(uuid.charAt(0))]; // uuid may be invalid // if (uuid.length() != UUID.UUID_FORMATTED_LENGTH) { // return null; // } String key = uuid; Entry entry; synchronized (cacheSegment) { entry = (Entry) cacheSegment.get(key); } if (log.isDebugEnabled()) { accesses++; if (entry == null) { misses++; } // log at most after 1000 accesses and every 10 seconds if (accesses > 1000 && System.currentTimeMillis() - lastLog > LOG_INTERVAL) { long ratio = 100; if (misses != 0) { ratio -= misses * 100L / accesses; } StringBuilder statistics = new StringBuilder(); int inUse = 0; for (int i = 0; i < docNumbers.length; i++) { inUse += docNumbers[i].size(); } statistics.append("size=").append(inUse); statistics.append("/").append(docNumbers[0].maxSize() * CACHE_SEGMENTS); statistics.append(", #accesses=").append(accesses); statistics.append(", #hits=").append((accesses - misses)); statistics.append(", #misses=").append(misses); statistics.append(", cacheRatio=").append(ratio).append("%"); log.debug(statistics.toString()); accesses = 0; misses = 0; lastLog = System.currentTimeMillis(); } } return entry; }