Example usage for org.apache.commons.collections OrderedMap containsKey

List of usage examples for org.apache.commons.collections OrderedMap containsKey

Introduction

In this page you can find the example usage for org.apache.commons.collections OrderedMap containsKey.

Prototype

boolean containsKey(Object key);

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:org.diffkit.diff.engine.DKStandardTableComparison.java

/**
 * @param lhs_/*from   w  w w .jav a 2  s.co  m*/
 *           row
 * @param rhs_
 *           row
 * @return OrderedMap ordered, as best as possible, according to
 *         _displayIndexes. keys are String; values are String
 */
@SuppressWarnings("unchecked")
public OrderedMap getRowDisplayValues(Object[] lhs_, Object[] rhs_) {

    OrderedMap lhDisplayValues = this.getRowDisplayValues(lhs_, DKSide.LEFT_INDEX);
    OrderedMap rhDisplayValues = this.getRowDisplayValues(rhs_, DKSide.RIGHT_INDEX);
    if (_log.isDebugEnabled()) {
        _log.debug("lhDisplayValues->{}", lhDisplayValues);
        _log.debug("rhDisplayValues->{}", rhDisplayValues);
    }
    MapIterator lhIterator = lhDisplayValues.orderedMapIterator();
    MapIterator rhIterator = rhDisplayValues.orderedMapIterator();
    OrderedMap result = new LinkedMap();
    while (true) {
        boolean lhHasNext = lhIterator.hasNext();
        boolean rhHasNext = rhIterator.hasNext();
        if ((!lhHasNext) && (!rhHasNext))
            break;
        String lhKey = (lhHasNext ? (String) lhIterator.next() : null);
        String rhKey = (rhHasNext ? (String) rhIterator.next() : null);
        if (lhKey == null) {
            result.put(rhKey, ":" + rhDisplayValues.get(rhKey));
        } else if (rhKey == null) {
            result.put(lhKey, lhDisplayValues.get(lhKey) + ":");
        } else if (lhKey.equals(rhKey)) {
            String lhValue = (String) lhDisplayValues.get(lhKey);
            String rhValue = (String) rhDisplayValues.get(rhKey);
            String displayValue = (lhValue.equals(rhValue) ? lhValue : (lhValue + ":" + rhValue));
            result.put(lhKey, displayValue);
        } else {
            if (!result.containsKey(lhKey))
                result.put(lhKey, (String) lhDisplayValues.get(lhKey) + ":");
            else {
                String rhValue = (String) result.get(lhKey);
                result.put(lhKey, (String) lhDisplayValues.get(lhKey) + rhValue);
            }
            if (!result.containsKey(rhKey))
                result.put(rhKey, ":" + (String) rhDisplayValues.get(rhKey));
            else {
                String lhValue = (String) result.get(rhKey);
                result.put(rhKey, lhValue + (String) rhDisplayValues.get(rhKey));
            }
        }
    }
    return result;
}