Example usage for org.apache.commons.collections.map LRUMap put

List of usage examples for org.apache.commons.collections.map LRUMap put

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LRUMap put.

Prototype

public Object put(Object key, Object value) 

Source Link

Document

Puts a key-value mapping into this map.

Usage

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 loadConcept(String UMLSCodingSchemeName, String codingSchemeName,
        ConceptPresentation[] conceptPresentations) throws SQLException {
    // order them - this will organize them by language, and put the "best"
    // presentation
    // first for each language. default language will be the at the very
    // top.//  w ww. j  a v  a 2s.c o m
    Arrays.sort(conceptPresentations, new ConceptPresentationSorter());

    // now set each isPreferred to true for the first entry of each language
    String prevLang = conceptPresentations[0].language;
    conceptPresentations[0].isPreferred = new Boolean(true);
    for (int i = 1; i < conceptPresentations.length; i++) {
        if (!conceptPresentations[i].language.equals(prevLang)) {
            conceptPresentations[i].isPreferred = new Boolean(true);
        }
        prevLang = conceptPresentations[i].language;
    }

    // load the entry into the concepts table - must be at least 1 row. the
    // first one will
    // be the best text presentation to use here.
    try {
        addConceptToConcepts(codingSchemeName, conceptPresentations[0].conceptCode, null, null, null,
                new Boolean(true), null, new Boolean(false), SQLTableConstants.TBLCOL_ISACTIVE,
                new Boolean(false), conceptPresentations[0].value);
    } catch (SQLException e) {
        // Recover from a failure adding a new code. Likely caused by trying
        // to insert a duplicate code - some code systems are case sensitive
        // - and
        // most of our databases aren't.
        log.error("Problem inserting new code " + conceptPresentations[0].conceptCode, e);
        messages_.info("ERROR - Problem inserting new code " + conceptPresentations[0].conceptCode);
        return;
    }

    LRUMap TValues = new LRUMap(20);

    // load its properties
    for (int i = 0; i < conceptPresentations.length; i++) {
        String propertyId = "T-" + presentationCounter_++;
        addToEntityProperty(codingSchemeName, SQLTableConstants.ENTITYTYPE_CONCEPT,
                conceptPresentations[i].conceptCode, propertyId, SQLTableConstants.TBLCOLVAL_PRESENTATION,
                SQLTableConstants.TBLCOLVAL_TEXTUALPRESENTATION, conceptPresentations[i].language,
                conceptPresentations[i].presentationFormat, conceptPresentations[i].isPreferred, null, null,
                conceptPresentations[i].representationForm, conceptPresentations[i].value);
        TValues.put(conceptPresentations[i].AUI, propertyId);
    }

    // load the definitions
    addToDefinitions(UMLSCodingSchemeName, conceptPresentations[0].cui, codingSchemeName,
            conceptPresentations[0].conceptCode);

    // load the other properties
    loadOtherProperties(UMLSCodingSchemeName, conceptPresentations[0].cui, codingSchemeName,
            conceptPresentations[0].conceptCode, TValues);

    // TODO dig the history out - add the modVersion (not now)
    // addConceptToConceptsMultiAttributes(codingSchemeName, conceptCode,
    // "modVersion", "");

    // this is where the usageContext would be loaded - but we don't have
    // any.
    // also, if we were to load the UMLS as a coding scheme (instead of
    // individual coding schemes) this is
    // where we would put the source information
    // addConceptToConceptPropertyMultiAttributes(codingSchemeName,
    // conceptCode, propertyId, "", "", "",
    // "");
}

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);//w w w  .  j a  v  a  2s  .  com

    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;/*from ww w.  j a va 2  s  .co  m*/

        @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;/*from w  w  w.jav  a 2  s .  c  o 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./*from  w  ww  .  j ava2 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))];
    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.jena.security.impl.SecuredItemImpl.java

/**
 * set teh cache value.//  www.j  a  v a2 s . c o m
 * @param key The key to set the value for.
 * @param value The value to set.
 */
void cachePut(final CacheKey key, final boolean value) {
    final LRUMap cache = SecuredItemImpl.CACHE.get();
    if (cache != null) {
        cache.put(key, value);
        SecuredItemImpl.CACHE.set(cache);
    }
}

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./*ww  w. j  ava  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))];
    //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.lexevs.dao.database.operation.transitivity.DefaultTransitivityBuilder.java

private boolean insertIntoTransitiveClosure(String associationPredicateId, StringTuple sourceCode,
        StringTuple targetCode, LRUMap insertedCache, String path,
        BatchInsertController batchInsertController) {
    String key = sourceCode.code + ":" + sourceCode.namespace + ":" + targetCode.code + ":"
            + targetCode.namespace;// www.  j  a  v  a2 s  .co m

    boolean iInserted = false;

    if (!insertedCache.containsKey(key)) {
        // if it is not loaded in the main table, or already loaded
        // in the transitive table

        insertedCache.put(key, null);
        iInserted = true;
        batchInsertController.insertIntoTransitiveClosure(sourceCode.code, sourceCode.namespace,
                targetCode.code, targetCode.namespace, associationPredicateId, path);

    }
    return iInserted;
}