List of usage examples for com.google.common.collect MapMaker MapMaker
public MapMaker()
From source file:io.warp10.standalone.StandaloneDirectoryClient.java
private void store(Metadata metadata) throws IOException { // Compute labelsId and classId // 128BITS//from w w w .j av a2 s . co m long classId = GTSHelper.classId(this.classLongs, metadata.getName()); long labelsId = GTSHelper.labelsId(this.labelsLongs, metadata.getLabels()); //ByteBuffer bb = ByteBuffer.wrap(new byte[1 + 8 + 8]).order(ByteOrder.BIG_ENDIAN); //bb.put(METADATA_PREFIX); //bb.putLong(classId); //bb.putLong(labelsId); byte[] bytes = new byte[1 + 8 + 8]; System.arraycopy(METADATA_PREFIX, 0, bytes, 0, METADATA_PREFIX.length); int idx = METADATA_PREFIX.length; bytes[idx++] = (byte) ((classId >> 56) & 0xff); bytes[idx++] = (byte) ((classId >> 48) & 0xff); bytes[idx++] = (byte) ((classId >> 40) & 0xff); bytes[idx++] = (byte) ((classId >> 32) & 0xff); bytes[idx++] = (byte) ((classId >> 24) & 0xff); bytes[idx++] = (byte) ((classId >> 16) & 0xff); bytes[idx++] = (byte) ((classId >> 8) & 0xff); bytes[idx++] = (byte) (classId & 0xff); bytes[idx++] = (byte) ((labelsId >> 56) & 0xff); bytes[idx++] = (byte) ((labelsId >> 48) & 0xff); bytes[idx++] = (byte) ((labelsId >> 40) & 0xff); bytes[idx++] = (byte) ((labelsId >> 32) & 0xff); bytes[idx++] = (byte) ((labelsId >> 24) & 0xff); bytes[idx++] = (byte) ((labelsId >> 16) & 0xff); bytes[idx++] = (byte) ((labelsId >> 8) & 0xff); bytes[idx++] = (byte) (labelsId & 0xff); metadata.setClassId(classId); metadata.setLabelsId(labelsId); if (null == metadata.getAttributes()) { metadata.setAttributes(new HashMap<String, String>()); } TSerializer serializer = new TSerializer(new TCompactProtocol.Factory()); try { if (null != this.db) { byte[] serialized = serializer.serialize(metadata); if (null != this.aesKey) { serialized = CryptoUtils.wrap(this.aesKey, serialized); } //this.db.put(bb.array(), serialized); //this.db.put(bytes, serialized); store(bytes, serialized); } synchronized (metadatas) { if (!metadatas.containsKey(metadata.getName())) { metadatas.put(metadata.getName(), (Map) new MapMaker().concurrencyLevel(64).makeMap()); } metadatas.get(metadata.getName()).put(labelsId, metadata); } // // Store Metadata under 'id' // byte[] idbytes = new byte[16]; GTSHelper.fillGTSIds(idbytes, 0, classId, labelsId); BigInteger id = new BigInteger(idbytes); this.metadatasById.put(id, metadata); } catch (TException te) { throw new RuntimeException(te); } }
From source file:ome.services.sessions.SessionManagerImpl.java
@SuppressWarnings("unchecked") private void setEnvironmentVariable(String session, String key, Object object, String env) { Ehcache cache = inMemoryCache(session); Element elt = cache.get(env); Map<String, Object> map; if (elt == null) { map = new MapMaker().makeMap(); elt = new Element(env, map); cache.put(elt);/*from w ww . j a v a2s . c o m*/ } else { map = (Map<String, Object>) elt.getObjectValue(); } if (object == null) { map.remove(key); } else { map.put(key, object); } }
From source file:edu.berkeley.compbio.ncbitaxonomy.NcbiTaxonomyPhylogeny.java
public Map<Integer, String> getFriendlyLabelMap() { return new MapMaker().makeComputingMap(new Function<Integer, String>() { public String apply(@Nullable final Integer id) { try { return getScientificName(id); } catch (NoSuchNodeException e) { return id.toString(); }/*from ww w. j av a 2s. c o m*/ } }); }
From source file:com.ardor3d.scenegraph.MeshData.java
/** * Sets the id for a vbo based on interleaving this MeshData's buffer, in regards to the given OpenGL context. * // www.j a v a2 s . com * @param glContext * the object representing the OpenGL context a vbo belongs to. See * {@link RenderContext#getGlContextRep()} * @param vboId * the vbo id of a vbo. To be valid, this must be != 0. * @throws IllegalArgumentException * if vboId is equal to 0. */ public void setVBOInterleavedID(final Object glContext, final int vboId) { if (vboId == 0) { throw new IllegalArgumentException("vboId must != 0"); } if (_vboIdCache == null) { _vboIdCache = new MapMaker().initialCapacity(1).weakKeys().makeMap(); } _vboIdCache.put(glContext, vboId); }
From source file:com.quinsoft.zeidon.standardoe.EntityInstanceImpl.java
/** * Link newInstance with 'this'. Will create this.linkedInstances if necessary. * @param newInstance/* w w w .jav a2s . c om*/ */ private void addLinkedInstance(EntityInstanceImpl newInstance) { synchronized (getTask()) { if (linkedInstances == null) { if (newInstance.linkedInstances != null) { // Make all the linked entities share the new source attributes. for (EntityInstanceImpl ei : newInstance.linkedInstances.keySet()) ei.persistentAttributes = persistentAttributes; linkedInstances = newInstance.linkedInstances; linkedInstances.putIfAbsent(this, Boolean.TRUE); return; } // Create a concurrent map that uses weak references for the keys. // This will allow the GC to clean up if a linked instance goes away. // Initialize it with firstInstance. linkedInstances = new MapMaker().concurrencyLevel(2).weakKeys().makeMap(); linkedInstances.put(this, Boolean.TRUE); } // Check to see if targetInstance is already linked and if it is remove // it. This can happen when merging an OI committed on a web server. if (newInstance.linkedInstances != null) newInstance.linkedInstances.remove(newInstance); linkedInstances.putIfAbsent(newInstance, Boolean.TRUE); newInstance.linkedInstances = linkedInstances; newInstance.persistentAttributes = persistentAttributes; assert assertLinkedInstances() : "Error with linked instances"; } }