Java SortedSet computeGraphCauselessFromGraphMms( SortedMap>> causesByDepByName)

Here you can find the source of computeGraphCauselessFromGraphMms( SortedMap>> causesByDepByName)

Description

Removes the causes.

License

Apache License

Parameter

Parameter Description
causesByDepByName The map with causes.

Exception

Parameter Description
NullPointerException if causesByDepByName is null.

Return

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

Declaration

public static SortedMap<String, SortedSet<String>> computeGraphCauselessFromGraphMms(
        SortedMap<String, SortedMap<String, SortedSet<String>>> causesByDepByName) 

Method Source Code

//package com.java2s;
/**// w  ww. j  a  v a2  s  .c  om
 * 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.Map;

import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
    /**
     * Removes the causes.
     * SortedMap<name,SortedMap<dep,SortedSet<cause>>>
     * becomes SortedMap<name,SortedSet<dep>>.
     * 
     * @param causesByDepByName The map with causes.
     * @return A new mutable map corresponding to the argument but without causes.
     * @throws NullPointerException if causesByDepByName is null.
     */
    public static SortedMap<String, SortedSet<String>> computeGraphCauselessFromGraphMms(
            SortedMap<String, SortedMap<String, SortedSet<String>>> causesByDepByName) {

        final SortedMap<String, SortedSet<String>> reduced = new TreeMap<String, SortedSet<String>>();

        // Implicit null check.
        for (Map.Entry<String, SortedMap<String, SortedSet<String>>> entry : causesByDepByName
                .entrySet()) {
            final String name = entry.getKey();
            final SortedMap<String, SortedSet<String>> causesByDep = entry
                    .getValue();

            // Removing causes.
            final SortedSet<String> deps = new TreeSet<String>(
                    causesByDep.keySet());

            final Object forCheck = reduced.put(name, deps);
            if (forCheck != null) {
                throw new AssertionError();
            }
        }

        return reduced;
    }
}

Related

  1. addMapEntry(Map> map, T1 keyEntry, T2 setEntry)
  2. arrayToSortedStringSet(Collection strings)
  3. asSortedSet(T... args)
  4. asSortedSet(T... elements)
  5. computeGraphCauselessFromGraphLmms( List>>> causesByDepByNameList)
  6. copyAndClearSet(SortedSet sourceSet)
  7. doubleForDescreteStartAndEnds(SortedSet hours)
  8. entriesSortedByValues( Map map)
  9. fillOutHourly(SortedSet hours)