Java SortedMap Usage computePathCauselessLms( List>> depCausesByNameList)

Here you can find the source of computePathCauselessLms( List>> depCausesByNameList)

Description

Removes the causes.

License

Apache License

Parameter

Parameter Description
depCausesByNameList A list of maps with causes.

Exception

Parameter Description
IllegalArgumentException if equal keys are among the maps.
NullPointerException if causesByNameList is null.

Return

A new mutable map corresponding to the argument but without causes.

Declaration

public static List<String> computePathCauselessLms(
        List<SortedMap<String, SortedSet<String>>> depCausesByNameList) 

Method Source Code

//package com.java2s;
/**/*from   w  ww.ja  va 2 s  . c o m*/
 * Copyright 2015 Jeff Hain
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;

import java.util.List;

import java.util.SortedMap;
import java.util.SortedSet;

public class Main {
    /**
     * Removes the causes.
     * List<SortedMap<name,SortedSet<depCause>>>>
     * becomes List<name>.
     * 
     * @param depCausesByNameList A list of maps with causes.
     * @return A new mutable map corresponding to the argument but without
     *         causes.
     * @throws IllegalArgumentException if equal keys are among the maps.
     * @throws NullPointerException if causesByNameList is null.
     */
    public static List<String> computePathCauselessLms(
            List<SortedMap<String, SortedSet<String>>> depCausesByNameList) {

        final List<String> nameList = new ArrayList<String>();

        // Implicit null check.
        final int size = depCausesByNameList.size();

        for (int i = 0; i < size; i++) {
            final SortedMap<String, SortedSet<String>> depCausesByName = depCausesByNameList
                    .get(i);
            if (depCausesByName.size() != 1) {
                throw new IllegalArgumentException(
                        "map size must be 1, but map is " + depCausesByName);
            }
            final String name = depCausesByName.firstKey();
            if (i == size - 1) {
                final SortedSet<String> depCauses = depCausesByName
                        .get(name);
                if (depCauses.size() != 0) {
                    throw new IllegalArgumentException(
                            "last causes set must be empty, but is "
                                    + depCauses);
                }
            }
            nameList.add(name);
        }

        return nameList;
    }
}

Related

  1. computeByteSizeM( SortedMap byteSizeByName)
  2. filterPrefix( SortedMap baseMap, String prefix)
  3. find(SortedMap map, String baseName)
  4. firstElement(Collection c)
  5. firstElement(Collection c)