Home | History | Annotate | Download | only in google
      1 /*
      2  * Copyright (C) 2012 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.collect.testing.google;
     18 
     19 import com.google.common.annotations.GwtCompatible;
     20 import com.google.common.collect.ListMultimap;
     21 import com.google.common.collect.testing.Helpers;
     22 import com.google.common.collect.testing.SampleElements;
     23 
     24 import java.util.Collection;
     25 import java.util.List;
     26 import java.util.Map;
     27 import java.util.Map.Entry;
     28 
     29 /**
     30  * A skeleton generator for a {@code ListMultimap} implementation.
     31  *
     32  * @author Louis Wasserman
     33  */
     34 @GwtCompatible
     35 public abstract class TestStringListMultimapGenerator
     36     implements TestListMultimapGenerator<String, String> {
     37 
     38   @Override
     39   public SampleElements<Map.Entry<String, String>> samples() {
     40     return new SampleElements<Map.Entry<String, String>>(
     41         Helpers.mapEntry("one", "January"),
     42         Helpers.mapEntry("two", "February"),
     43         Helpers.mapEntry("three", "March"),
     44         Helpers.mapEntry("four", "April"),
     45         Helpers.mapEntry("five", "May"));
     46   }
     47 
     48   @Override
     49   public SampleElements<String> sampleKeys() {
     50     return new SampleElements<String>("one", "two", "three", "four", "five");
     51   }
     52 
     53   @Override
     54   public SampleElements<String> sampleValues() {
     55     return new SampleElements<String>("January", "February", "March", "April", "May");
     56   }
     57 
     58   @Override
     59   public Collection<String> createCollection(Iterable<? extends String> values) {
     60     return Helpers.copyToList(values);
     61   }
     62 
     63   @Override
     64   public final ListMultimap<String, String> create(Object... entries) {
     65     @SuppressWarnings("unchecked")
     66     Entry<String, String>[] array = new Entry[entries.length];
     67     int i = 0;
     68     for (Object o : entries) {
     69       @SuppressWarnings("unchecked")
     70       Entry<String, String> e = (Entry<String, String>) o;
     71       array[i++] = e;
     72     }
     73     return create(array);
     74   }
     75 
     76   protected abstract ListMultimap<String, String> create(
     77       Entry<String, String>[] entries);
     78 
     79   @Override
     80   @SuppressWarnings("unchecked")
     81   public final Entry<String, String>[] createArray(int length) {
     82     return new Entry[length];
     83   }
     84 
     85   @Override
     86   public final String[] createKeyArray(int length) {
     87     return new String[length];
     88   }
     89 
     90   @Override
     91   public final String[] createValueArray(int length) {
     92     return new String[length];
     93   }
     94 
     95   /** Returns the original element list, unchanged. */
     96   @Override
     97   public Iterable<Entry<String, String>> order(
     98       List<Entry<String, String>> insertionOrder) {
     99     return insertionOrder;
    100   }
    101 }
    102