001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.utils.collections;
020
021import java.util.*;
022
023/**
024 * A sorted map whose values are sorted sets of a given component type.
025 * @param <K> the type of keys in the map.
026 * @param <V> the type of values in the collections mapped to the keys.
027 * @author Laurent Cohen
028 */
029public class SortedSetSortedMap<K, V> extends AbstractCollectionSortedMap<K, V> {
030  /**
031   * Explicit serialVersionUID.
032   */
033  private static final long serialVersionUID = 1L;
034  /**
035   * Comparator used to sort the keys.
036   */
037  protected Comparator<V> valueComparator = null;
038
039  /**
040   * Default cosntructor.
041   */
042  public SortedSetSortedMap() {
043    super();
044  }
045
046  /**
047   * Default cosntructor.
048   * @param comparator tomparator used to sort the keys.
049   */
050  public SortedSetSortedMap(final Comparator<K> comparator) {
051    super(comparator);
052  }
053
054  /**
055   * Default cosntructor.
056   * @param keyComparator comparator used to sort the keys.
057   * @param valueComparator comparator used to sort the values.
058   */
059  public SortedSetSortedMap(final Comparator<K> keyComparator, final Comparator<V> valueComparator) {
060    super(keyComparator);
061    this.valueComparator = valueComparator;
062  }
063
064  @Override
065  protected Collection<V> newCollection() {
066    return valueComparator == null ? new TreeSet<V>() : new TreeSet<>(valueComparator);
067  }
068}