Coverage Summary for Class: SingletonImmutableTable (com.google.common.collect)

Class Class, % Method, % Line, %
SingletonImmutableTable 100% (1/1) 33.3% (3/9) 41.2% (7/17)


1 /* 2  * Copyright (C) 2009 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; 18  19 import static com.google.common.base.Preconditions.checkNotNull; 20  21 import com.google.common.annotations.GwtCompatible; 22 import java.util.Map; 23  24 /** 25  * An implementation of {@link ImmutableTable} that holds a single cell. 26  * 27  * @author Gregory Kick 28  */ 29 @GwtCompatible 30 class SingletonImmutableTable<R, C, V> extends ImmutableTable<R, C, V> { 31  final R singleRowKey; 32  final C singleColumnKey; 33  final V singleValue; 34  35  SingletonImmutableTable(R rowKey, C columnKey, V value) { 36  this.singleRowKey = checkNotNull(rowKey); 37  this.singleColumnKey = checkNotNull(columnKey); 38  this.singleValue = checkNotNull(value); 39  } 40  41  SingletonImmutableTable(Cell<R, C, V> cell) { 42  this(cell.getRowKey(), cell.getColumnKey(), cell.getValue()); 43  } 44  45  @Override 46  public ImmutableMap<R, V> column(C columnKey) { 47  checkNotNull(columnKey); 48  return containsColumn(columnKey) 49  ? ImmutableMap.of(singleRowKey, singleValue) 50  : ImmutableMap.<R, V>of(); 51  } 52  53  @Override 54  public ImmutableMap<C, Map<R, V>> columnMap() { 55  return ImmutableMap.of(singleColumnKey, (Map<R, V>) ImmutableMap.of(singleRowKey, singleValue)); 56  } 57  58  @Override 59  public ImmutableMap<R, Map<C, V>> rowMap() { 60  return ImmutableMap.of(singleRowKey, (Map<C, V>) ImmutableMap.of(singleColumnKey, singleValue)); 61  } 62  63  @Override 64  public int size() { 65  return 1; 66  } 67  68  @Override 69  ImmutableSet<Cell<R, C, V>> createCellSet() { 70  return ImmutableSet.of(cellOf(singleRowKey, singleColumnKey, singleValue)); 71  } 72  73  @Override 74  ImmutableCollection<V> createValues() { 75  return ImmutableSet.of(singleValue); 76  } 77  78  @Override 79  SerializedForm createSerializedForm() { 80  return SerializedForm.create(this, new int[] {0}, new int[] {0}); 81  } 82 }