List of usage examples for org.apache.commons.collections.map ListOrderedMap lastKey
public Object lastKey()
From source file:com.denksoft.springstarter.util.webflow.ProgressFlowExecutionListener.java
@Override @SuppressWarnings(value = "unchecked") public void viewRendering(RequestContext context, View view, StateDefinition viewState) { String currentFlow = viewState.getOwner().getId(); Map<String, ProgressInfo> progressMap = (Map<String, ProgressInfo>) context.getConversationScope() .get(PROGRESS_INFORMATION_MAP_VAR_NAME); ProgressInfo progress = progressMap.get(currentFlow); if (progress == null) { progress = new ProgressInfo(currentFlow); progressMap.put(currentFlow, progress); } else {/*from w w w .j av a2s .c o m*/ ListOrderedMap orderedMap = (ListOrderedMap) progressMap; String lastFlow = orderedMap.lastKey().toString(); if (!lastFlow.equalsIgnoreCase(currentFlow)) ((ListOrderedMap) progressMap).remove(progressMap.size() - 1); } int index = Integer.parseInt(viewState.getAttributes().get(PROGRESS_INDEX_VAR_NAME).toString()); progress.setStateNumber(index); progress.setStateTotal(maxLen); }
From source file:org.etk.entity.engine.plugins.transaction.TransactionUtil.java
/** * Remove the stamp from stack (when resuming) */// www .ja v a 2s . com private static void popTransactionStartStamp() { ListOrderedMap map = (ListOrderedMap) suspendedTxStartStamps.get(); if (map.size() > 0) { transactionStartStamp.set((Timestamp) map.remove(map.lastKey())); } else { logger.debug("Error in transaction handling - no saved start stamp found - using NOW."); transactionStartStamp.set(UtilDateTime.nowTimestamp()); } }
From source file:org.jahia.services.content.ConflictResolver.java
private List<Diff> compare(JCRNodeWrapper sourceNode, JCRNodeWrapper targetNode, String basePath) throws RepositoryException { List<Diff> diffs = new ArrayList<Diff>(); boolean remotelyPublished = targetNode.isNodeType("jmix:remotelyPublished"); if (!remotelyPublished) { final ListOrderedMap targetUuids = getChildEntries(targetNode, targetNode.getSession()); final ListOrderedMap sourceUuids = getChildEntries(sourceNode, sourceNode.getSession()); if (!targetUuids.values().equals(sourceUuids.values())) { for (Iterator<?> iterator = sourceUuids.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); if (targetUuids.containsKey(key) && !targetUuids.get(key).equals(sourceUuids.get(key))) { diffs.add(new ChildRenamedDiff(key, addPath(basePath, (String) targetUuids.get(key)), addPath(basePath, (String) sourceUuids.get(key)))); }// w w w . j a v a2 s. co m } } // Child nodes if (!targetUuids.keyList().equals(sourceUuids.keyList())) { @SuppressWarnings("unchecked") List<String> addedUuids = new ArrayList<String>(sourceUuids.keySet()); addedUuids.removeAll(targetUuids.keySet()); @SuppressWarnings("unchecked") List<String> removedUuids = new ArrayList<String>(targetUuids.keySet()); removedUuids.removeAll(sourceUuids.keySet()); // Ordering if (targetNode.getPrimaryNodeType().hasOrderableChildNodes()) { Map<String, String> newOrdering = getOrdering(sourceUuids, Collections.<String>emptyList()); @SuppressWarnings("unchecked") List<String> oldUuidsList = new ArrayList<String>(targetUuids.keySet()); oldUuidsList.removeAll(removedUuids); @SuppressWarnings("unchecked") List<String> newUuidsList = new ArrayList<String>(sourceUuids.keySet()); newUuidsList.removeAll(addedUuids); if (!oldUuidsList.equals(newUuidsList)) { for (int i = 1; i < oldUuidsList.size(); i++) { String x = oldUuidsList.get(i); int j = i; while (j > 0 && sourceUuids.indexOf(oldUuidsList.get(j - 1)) > sourceUuids.indexOf(x)) { oldUuidsList.set(j, oldUuidsList.get(j - 1)); j--; } if (j != i) { String orderBeforeUuid = (j + 1 == oldUuidsList.size()) ? null : oldUuidsList.get(j + 1); diffs.add(new ChildNodeReorderedDiff(x, orderBeforeUuid, addPath(basePath, (String) sourceUuids.get(x)), (String) sourceUuids.get(orderBeforeUuid), newOrdering)); logger.debug("reorder " + sourceUuids.get(x) + " before " + sourceUuids.get(orderBeforeUuid)); oldUuidsList.set(j, x); } } } } // Removed nodes for (String removedUuid : removedUuids) { try { this.sourceNode.getSession().getNodeByUUID(removedUuid); } catch (ItemNotFoundException e) { // Item has been moved diffs.add(new ChildRemovedDiff(removedUuid, addPath(basePath, (String) targetUuids.get(removedUuid)), removedUuid)); } } // Added nodes for (String addedUuid : addedUuids) { diffs.add(new ChildAddedDiff(addedUuid, addPath(basePath, (String) sourceUuids.get(addedUuid)), addedUuid.equals(sourceUuids.lastKey()) ? null : (String) sourceUuids .get(sourceUuids.get(sourceUuids.indexOf(addedUuid) + 1)))); } } } PropertyIterator targetProperties = targetNode.getProperties(); while (targetProperties.hasNext()) { JCRPropertyWrapper targetProperty = (JCRPropertyWrapper) targetProperties.next(); String propertyName = targetProperty.getName(); if (IGNORED_PROPRTIES.contains(propertyName)) { continue; } if (!sourceNode.hasProperty(propertyName)) { if (targetProperty.isMultiple()) { Value[] values = targetProperty.getRealValues(); for (Value value : values) { diffs.add(new PropertyRemovedDiff(addPath(basePath, propertyName), value)); } } else { diffs.add(new PropertyChangedDiff(addPath(basePath, propertyName), null)); } } else { JCRPropertyWrapper sourceProperty = sourceNode.getProperty(propertyName); if (targetProperty.isMultiple() != sourceProperty.isMultiple()) { throw new RepositoryException(); } if (targetProperty.isMultiple()) { List<? extends Value> targetValues = Arrays.asList(targetProperty.getRealValues()); List<? extends Value> sourceValues = Arrays.asList(sourceProperty.getRealValues()); Map<String, Value> addedValues = new HashMap<String, Value>(); for (Value value : sourceValues) { addedValues.put(value.getString(), value); } for (Value value : targetValues) { addedValues.remove(value.getString()); } for (Value value : addedValues.values()) { diffs.add(new PropertyAddedDiff(addPath(basePath, propertyName), value)); } Map<String, Value> removedValues = new HashMap<String, Value>(); for (Value value : targetValues) { removedValues.put(value.getString(), value); } for (Value value : sourceValues) { removedValues.remove(value.getString()); } for (Value value : removedValues.values()) { diffs.add(new PropertyRemovedDiff(addPath(basePath, propertyName), value)); } } else { if (!equalsValue(targetProperty.getRealValue(), sourceProperty.getRealValue())) { diffs.add(new PropertyChangedDiff(addPath(basePath, propertyName), sourceProperty.getRealValue())); } } } } PropertyIterator sourceProperties = sourceNode.getProperties(); while (sourceProperties.hasNext()) { JCRPropertyWrapper sourceProperty = (JCRPropertyWrapper) sourceProperties.next(); String propertyName = sourceProperty.getName(); if (IGNORED_PROPRTIES.contains(propertyName)) { continue; } if (!targetNode.hasProperty(propertyName)) { if (sourceProperty.isMultiple()) { Value[] values = sourceProperty.getRealValues(); for (Value value : values) { diffs.add(new PropertyAddedDiff(addPath(basePath, sourceProperty.getName()), value)); } } else { diffs.add(new PropertyChangedDiff(addPath(basePath, sourceProperty.getName()), sourceProperty.getRealValue())); } } } for (Diff diff : new ArrayList<Diff>(diffs)) { if (diff instanceof PropertyAddedDiff && ((PropertyAddedDiff) diff).propertyPath.endsWith(Constants.JCR_MIXINTYPES)) { diffs.remove(diff); diffs.add(0, diff); } } for (Diff diff : new ArrayList<Diff>(diffs)) { if (diff instanceof PropertyRemovedDiff && ((PropertyRemovedDiff) diff).propertyPath.endsWith(Constants.JCR_MIXINTYPES)) { diffs.remove(diff); diffs.add(0, diff); } } if (!remotelyPublished) { NodeIterator targetSubNodes = targetNode.getNodes(); while (targetSubNodes.hasNext()) { JCRNodeWrapper targetSubNode = (JCRNodeWrapper) targetSubNodes.next(); if (sourceNode.hasNode(targetSubNode.getName()) && !targetSubNode.isVersioned() && !sourceNode.getNode(targetSubNode.getName()).isVersioned() && JCRPublicationService.supportsPublication(targetSubNode.getSession(), targetSubNode)) { diffs.addAll(compare(sourceNode.getNode(targetSubNode.getName()), targetSubNode, addPath(basePath, targetSubNode.getName()))); } } } return diffs; }
From source file:org.noerp.entity.transaction.TransactionUtil.java
/** * Remove the stamp from stack (when resuming) *//*from www .j av a 2 s.c o m*/ private static void popTransactionStartStamp() { ListOrderedMap map = (ListOrderedMap) suspendedTxStartStamps.get(); if (map.size() > 0) { transactionStartStamp.set((Timestamp) map.remove(map.lastKey())); } else { Debug.logError("Error in transaction handling - no saved start stamp found - using NOW.", module); transactionStartStamp.set(UtilDateTime.nowTimestamp()); } }