List of usage examples for java.util WeakHashMap WeakHashMap
public WeakHashMap()
From source file:org.apache.ctakes.ytex.kernel.IntrinsicInfoContentEvaluatorImpl.java
@Override public void evaluateIntrinsicInfoContent(String conceptGraphName, String conceptGraphDir, ConceptGraph cg) throws IOException { log.info("computing subsumer counts"); // compute the subsumer count Map<String, IntrinsicICInfo> icInfoMap = new HashMap<String, IntrinsicICInfo>(); Map<String, Set<String>> subsumerMap = new WeakHashMap<String, Set<String>>(); short[] depthArray = new short[cg.getConceptList().size()]; BufferedWriter w = null;/*from ww w . j ava 2 s . co m*/ try { w = this.getOutputFile(conceptGraphName, conceptGraphDir, "subsumer"); computeSubsumerCount(cg.getConceptMap().get(cg.getRoot()), icInfoMap, subsumerMap, depthArray, w); } finally { if (w != null) { try { w.close(); } catch (IOException e) { } } } subsumerMap = null; log.info("computing max leaves"); // get the leaves in this concept graph Set<String> leafSet = null; try { w = this.getOutputFile(conceptGraphName, conceptGraphDir, "allleaf"); leafSet = this.getAllLeaves(cg, w); } finally { if (w != null) { try { w.close(); } catch (IOException e) { } } } log.info("computing leaf counts"); @SuppressWarnings("unchecked") SoftReference<HashSet<Integer>>[] leafCache = (SoftReference<HashSet<Integer>>[]) Array.newInstance( (new SoftReference<HashSet<Integer>>(new HashSet<Integer>())).getClass(), cg.getConceptList().size()); // compute leaf count of all concepts in this graph try { w = this.getOutputFile(conceptGraphName, conceptGraphDir, "leaf"); // for (String leaf : leafSet) { // computeLeafCount(cg.getConceptMap().get(leaf), icInfoMap, // leafCache, cg, w); // } this.getLeaves(cg.getConceptMap().get(cg.getRoot()), leafCache, icInfoMap, cg, w, null); } finally { if (w != null) { try { w.close(); } catch (IOException e) { } } } leafCache = null; log.info("storing intrinsic ic"); storeIntrinsicIC(conceptGraphName, leafSet.size(), icInfoMap, depthArray, cg); log.info("finished computing intrinsic ic"); }
From source file:uk.ac.lkl.cram.ui.chart.LearningExperienceChartMaker.java
private void initializeMap() { learningExperienceMap = new WeakHashMap<>(); //Create a comparator that will sort by name of tlaLineItem Comparator<TLALineItem> tlaLineItemComparator = new Comparator<TLALineItem>() { @Override//from w w w . j av a 2 s. c o m public int compare(TLALineItem a, TLALineItem b) { return a.getName().compareTo(b.getName()); } }; //set the keys and values of the map learningExperienceMap.put(PERSONALISED, new TreeSet<>(tlaLineItemComparator)); learningExperienceMap.put(SOCIAL, new TreeSet<>(tlaLineItemComparator)); learningExperienceMap.put(ONE_SIZE_FOR_ALL, new TreeSet<>(tlaLineItemComparator)); }
From source file:uk.ac.lkl.cram.ui.chart.LearningTypeChartMaker.java
private void initializeMap() { learningTypeMap = new WeakHashMap<>(); //Create a comparator that will sort by name of tlaLineItem Comparator<TLALineItem> tlaLineItemComparator = new Comparator<TLALineItem>() { @Override/*from w w w.ja va2 s. c o m*/ public int compare(TLALineItem a, TLALineItem b) { return a.getName().compareTo(b.getName()); } }; //set the keys and values of the map learningTypeMap.put(ACQUISITION, new TreeSet<>(tlaLineItemComparator)); learningTypeMap.put(COLLABORATION, new TreeSet<>(tlaLineItemComparator)); learningTypeMap.put(DISCUSSION, new TreeSet<>(tlaLineItemComparator)); learningTypeMap.put(INQUIRY, new TreeSet<>(tlaLineItemComparator)); learningTypeMap.put(PRACTICE, new TreeSet<>(tlaLineItemComparator)); learningTypeMap.put(PRODUCTION, new TreeSet<>(tlaLineItemComparator)); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Window.java
/** * Restores the transient {@link #computedStyles_} map during deserialization. * @param stream the stream to read the object from * @throws IOException if an IO error occurs * @throws ClassNotFoundException if a class is not found *///from w w w .j av a 2s . c om private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); computedStyles_ = new WeakHashMap<>(); }
From source file:com.haulmont.cuba.web.gui.components.WebAbstractTable.java
@SuppressWarnings("unchecked") @Override/*from ww w . j a v a 2 s.c o m*/ public Datasource getItemDatasource(Entity item) { if (fieldDatasources == null) { fieldDatasources = new WeakHashMap<>(); } Datasource fieldDatasource = fieldDatasources.get(item); if (fieldDatasource == null) { fieldDatasource = DsBuilder.create().setAllowCommit(false).setMetaClass(datasource.getMetaClass()) .setRefreshMode(CollectionDatasource.RefreshMode.NEVER).setViewName("_local").buildDatasource(); ((DatasourceImplementation) fieldDatasource).valid(); fieldDatasource.setItem(item); fieldDatasources.put(item, fieldDatasource); } return fieldDatasource; }
From source file:org.opennms.core.xml.JaxbUtils.java
/** * Get a JAXB unmarshaller for the given object. If no JAXBContext is provided, * JAXBUtils will create and cache a context for the given object. * @param obj The object type to be unmarshaled. * @param jaxbContext An optional JAXB context to create the unmarshaller from. * @param validate TODO/*w w w .j a v a2s. c om*/ * @return an Unmarshaller */ public static Unmarshaller getUnmarshallerFor(final Object obj, final JAXBContext jaxbContext, boolean validate) { final Class<?> clazz = (Class<?>) (obj instanceof Class<?> ? obj : obj.getClass()); Unmarshaller unmarshaller = null; Map<Class<?>, Unmarshaller> unmarshallers = m_unMarshallers.get(); if (jaxbContext == null) { if (unmarshallers == null) { unmarshallers = new WeakHashMap<Class<?>, Unmarshaller>(); m_unMarshallers.set(unmarshallers); } if (unmarshallers.containsKey(clazz)) { LOG.trace("found unmarshaller for {}", clazz); unmarshaller = unmarshallers.get(clazz); } } if (unmarshaller == null) { try { final JAXBContext context; if (jaxbContext == null) { context = getContextFor(clazz); } else { context = jaxbContext; } unmarshaller = context.createUnmarshaller(); } catch (final JAXBException e) { throw EXCEPTION_TRANSLATOR.translate("creating XML marshaller", e); } } LOG.trace("created unmarshaller for {}", clazz); if (validate) { final Schema schema = getValidatorFor(clazz); if (schema == null) { LOG.trace("Validation is enabled, but no XSD found for class {}", clazz.getSimpleName()); } unmarshaller.setSchema(schema); } if (jaxbContext == null) unmarshallers.put(clazz, unmarshaller); return unmarshaller; }
From source file:gr.aueb.cs.nlp.wordtagger.data.structure.features.FeatureBuilder.java
/** * normalize feature vectors of words using mean and stadard devaition * provided the vectora values are/*from w w w.j a v a2 s . com*/ * higher than 1. * @param words * @param indeces */ private static void normalize(List<Word> words, List<Integer> indeces) { Map<Integer, Double> means = new WeakHashMap<>(); Map<Integer, Double> stds = new WeakHashMap<>(); for (Integer i : indeces) { SummaryStatistics smt = new SummaryStatistics(); for (Word w : words) { smt.addValue(w.getFeatureVec().getValues()[i]); } means.put(i, smt.getMean()); stds.put(i, smt.getStandardDeviation()); } for (Integer i : indeces) { for (Word w : words) { double value = w.getFeatureVec().getValues()[i]; w.getFeatureVec().getValues()[i] = (value - means.get(i)) / stds.get(i); } } }
From source file:org.squale.jraf.provider.persistence.hibernate.HibernateFilter.java
/** Retourne une map de providers * @param providers/*from w w w . ja v a 2s . co m*/ * @return */ protected final Map getProviders(String providers) { // pas de providers on retourne null if (providers == null) { return null; } StringTokenizer st = new StringTokenizer(providers, ","); String providerName; IPersistenceProvider persistenceProvider = null; Map m = new WeakHashMap(); while (st.hasMoreTokens()) { providerName = st.nextToken(); persistenceProvider = (IPersistenceProvider) ProviderLocator.getProvider(providerName); if (persistenceProvider != null) { m.put(providerName, persistenceProvider); } } return m; }
From source file:org.openconcerto.sql.model.SQLDataSource.java
private SQLDataSource(DBSystemRoot sysRoot) { this.sysRoot = sysRoot; // on a besoin d'une implementation synchronise this.handlers = new Hashtable<Thread, HandlersStack>(); // weak, since this is only a hint to avoid initializing the connection // on each borrowal this.schemaUptodate = new WeakHashMap<Connection, Object>(); this.uptodate = new WeakHashMap<Connection, Object>(); this.initialShemaSet = false; this.initialShema = null; // see #getNewConnection(boolean) this.setValidationQuery("SELECT 1"); this.setTestOnBorrow(false); this.setInitialSize(3); this.setMaxActive(48); // creating connections is quite costly so make sure we always have a couple free this.setMinIdle(2); // but not too much as it can lock out other users (the server has a max connection count) this.setMaxIdle(16); this.setBlockWhenExhausted(false); // check 5 connections every 4 seconds this.setTimeBetweenEvictionRunsMillis(4000); this.setNumTestsPerEvictionRun(5); // kill extra (above minIdle) connections after 40s this.setSoftMinEvictableIdleTimeMillis(TimeUnit.SECONDS.toMillis(40)); // kill idle connections after 30 minutes (even if it means re-creating some new ones // immediately afterwards to ensure minIdle connections) this.setMinEvictableIdleTimeMillis(TimeUnit.MINUTES.toMillis(30)); // the default of many systems this.txIsolation = Connection.TRANSACTION_READ_COMMITTED; // by definition unknown without a connection this.dbTxIsolation = null; // it's rare that DB configuration changes, and it's expensive to add a trip to the server // for each new connection this.checkOnceDBTxIsolation = true; // see #createDataSource() for properties not supported by this class this.tables = Collections.emptySet(); this.descL = new PropertyChangeListener() { @Override/*from w w w .j a va2 s. co m*/ public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("descendants")) { // the dataSource must always have all tables, to listen to them for its cache setTables(((DBSystemRoot) evt.getSource()).getDescs(SQLTable.class)); } } }; this.sysRoot.addListener(this.descL); this.cache = null; this.cacheEnabled = false; }
From source file:com.stimulus.archiva.domain.Config.java
public static void startup() { filesystem = new FileSystem(); stopBlockFactory = new StopBlockFactory(); updateObservers = new WeakHashMap<UpdateObserver, UpdateObserver>(); }