List of usage examples for org.apache.commons.collections.bidimap TreeBidiMap TreeBidiMap
public TreeBidiMap()
From source file:com.salesmanager.core.util.StringUtil.java
public static Map parseTokenLine(String line, String delimiter) { BidiMap returnMap = new TreeBidiMap(); if (StringUtils.isBlank(line) || StringUtils.isBlank(delimiter)) { return returnMap; }// w ww. j a v a 2 s .c om StringTokenizer st = new StringTokenizer(line, delimiter); int count = 0; while (st.hasMoreTokens()) { String value = st.nextToken(); returnMap.put(value, count); count++; } return returnMap; }
From source file:de.topicmapslab.majortom.inmemory.store.internal.ReificationStore.java
/** * Create a new relation between the given reifier and the reified construct * // w w w. j av a 2 s.c o m * @param reifiable the reified construct * @param reifier the reifier * @return the old reifier or <code>null</code> */ public ITopic setReifier(final IReifiable reifiable, final ITopic reifier) { if (reification == null) { reification = new TreeBidiMap(); } if (reifier != null && reification.containsKey(reifier)) { /* * get old reification */ IReifiable old = (IReifiable) reification.get(reifier); /* * check if old reifier is the same like new reifier */ if (!old.equals(reifiable)) { throw new ModelConstraintException(reifiable, "Reifier is already bound to another reified item."); } return reifier; } /* * remove old reification */ ITopic r = getReifier(reifiable); if (r != null) { reification.removeValue(reifiable); } /* * set new reification */ if (reifier != null) { reification.put(reifier, reifiable); } return r; }
From source file:de.topicmapslab.majortom.database.transaction.cache.ReificationCache.java
/** * Create a new relation between the given reifier and the reified construct * /* w ww .ja v a2s . co m*/ * @param reifiable * the reified construct * @param reifier * the reifier * @return the old reifier or <code>null</code> */ public ITopic setReifier(final IReifiable reifiable, final ITopic reifier) { if (isRemovedConstruct(reifiable)) { throw new ConstructRemovedException(reifiable); } if (isRemovedConstruct(reifier)) { throw new ConstructRemovedException(reifier); } ITopic oldReifier = storeOldReification(reifiable); if (reification == null) { reification = new TreeBidiMap(); } if (reifier != null && reification.containsKey(reifier)) { /* * get old reification */ IReifiable old = (IReifiable) reification.get(reifier); /* * check if old reifier is the same like new reifier */ if (!old.equals(reifiable)) { throw new ModelConstraintException(reifiable, "Reifier is already bound to another reified item."); } return reifier; } /* * remove old reification */ ITopic r = getReifier(reifiable); if (r != null) { reification.removeValue(reifiable); } /* * set new reification */ if (reifier != null) { reification.put(reifier, reifiable); } return oldReifier; }
From source file:de.topicmapslab.majortom.inmemory.virtual.internal.VirtualReificationStore.java
/** * Internal method to store old reification * //from ww w. j a v a 2 s .c o m * @param reifiable * the reifiable * @return the old reifier */ private ITopic storeOldReification(IReifiable reifiable) { if (!getVirtualIdentityStore().isVirtual(reifiable)) { ITopic nonTransactionReifier = null; if (reifiable instanceof ITransaction) { nonTransactionReifier = getVirtualIdentityStore().asVirtualConstruct((ITopic) getStore() .getRealStore().doRead(reifiable.getTopicMap(), TopicMapStoreParameterType.REIFICATION)); } else { nonTransactionReifier = getVirtualIdentityStore().asVirtualConstruct((ITopic) getStore() .getRealStore().doRead(reifiable, TopicMapStoreParameterType.REIFICATION)); } if (nonTransactionReifier != null) { if (removedReifications == null || !removedReifications.containsKey(nonTransactionReifier.getId())) { if (removedReifications == null) { removedReifications = new TreeBidiMap(); } removedReifications.put(nonTransactionReifier.getId(), reifiable.getId()); } } } return getReifier(reifiable); }
From source file:de.topicmapslab.majortom.inmemory.virtual.internal.VirtualReificationStore.java
/** * Internal method to store old reification * //from w w w .j a va 2s .co m * @param reifier * the reifier * @return the old reifiable */ private IReifiable storeOldReification(ITopic reifier) { if (!getVirtualIdentityStore().isVirtual(reifier)) { IReifiable nonTransactionReifiable = getVirtualIdentityStore().asVirtualConstruct( (IReifiable) getStore().getRealStore().doRead(reifier, TopicMapStoreParameterType.REIFICATION)); if (nonTransactionReifiable != null) { if (removedReifications == null || !removedReifications.containsValue(nonTransactionReifiable.getId())) { if (removedReifications == null) { removedReifications = new TreeBidiMap(); } removedReifications.put(reifier.getId(), nonTransactionReifiable.getId()); } } } return getReified(reifier); }
From source file:de.topicmapslab.majortom.database.transaction.cache.ReificationCache.java
/** * Internal method to store old reification * //from w ww. j a v a 2 s . c o m * @param reifiable * the reifiable * @return the old reifier */ private ITopic storeOldReification(IReifiable reifiable) { ITopic nonTransactionReifier = null; if (reifiable instanceof ITransaction) { nonTransactionReifier = getTransactionStore().getIdentityStore() .createLazyStub((ITopic) getTopicMapStore().doRead(reifiable.getTopicMap(), TopicMapStoreParameterType.REIFICATION)); } else { nonTransactionReifier = getTransactionStore().getIdentityStore().createLazyStub( (ITopic) getTopicMapStore().doRead(reifiable, TopicMapStoreParameterType.REIFICATION)); } if (nonTransactionReifier != null) { if (removedReifications == null || !removedReifications.containsKey(nonTransactionReifier.getId())) { if (removedReifications == null) { removedReifications = new TreeBidiMap(); } removedReifications.put(nonTransactionReifier.getId(), reifiable.getId()); } } return getReifier(reifiable); }
From source file:de.topicmapslab.majortom.database.transaction.cache.ReificationCache.java
/** * Internal method to store old reification * //from ww w .j a v a2 s .c om * @param reifier * the reifier * @return the old reifiable */ private IReifiable storeOldReification(ITopic reifier) { IReifiable nonTransactionReifiable = getTransactionStore().getIdentityStore().createLazyStub( (IReifiable) getTopicMapStore().doRead(reifier, TopicMapStoreParameterType.REIFICATION)); if (nonTransactionReifiable != null) { if (removedReifications == null || !removedReifications.containsValue(nonTransactionReifiable.getId())) { if (removedReifications == null) { removedReifications = new TreeBidiMap(); } removedReifications.put(reifier.getId(), nonTransactionReifiable.getId()); } } return getReified(reifier); }
From source file:de.topicmapslab.majortom.cache.IdentityCache.java
/** * Cache the mapping between the id and the construct into internal store. * //from w ww . j ava2 s . c o m * @param id * the id * @param c * the construct */ public void cacheId(final String id, IConstruct c) { if (ids == null) { ids = new TreeBidiMap(); } ids.put(id, c); }
From source file:de.topicmapslab.majortom.database.transaction.cache.IdentityCache.java
/** * {@inheritDoc}//from w w w.j a v a2 s .co m */ public void setId(IConstruct c, String id) { if (lazyStubs == null) { lazyStubs = HashUtil.getHashMap(); } lazyStubs.put(id, c); if (ids == null) { ids = new TreeBidiMap(); } if (c instanceof ITopic) { if (topics == null) { topics = HashUtil.getHashSet(); } this.topics.add((ITopic) c); } this.ids.put(id, c); }
From source file:org.apache.mahout.classifier.sequencelearning.hmm.HmmModel.java
/** * Register an array of hidden state Names. We assume that the state name at * position i has the ID i/* w w w . j av a 2 s .c o m*/ * * @param stateNames names of hidden states. */ public void registerHiddenStateNames(String[] stateNames) { if (stateNames != null) { hiddenStateNames = new TreeBidiMap(); for (int i = 0; i < stateNames.length; ++i) { hiddenStateNames.put(stateNames[i], i); } } }