001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 * http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing, software
008 * distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010 * See the License for the specific language governing permissions and
011 * limitations under the License.
012 */
013package org.gbif.api.model.metrics.cube;
014
015import java.util.Arrays;
016import java.util.Set;
017
018import com.google.common.base.Objects;
019import com.google.common.collect.ImmutableSet;
020
021/**
022 * A rollup defines an addressable count that is maintained for a set of dimensions.
023 */
024public class Rollup {
025
026  // Not final, only to enable easy Jackson using default constructor
027  private Set<Dimension<?>> dimensions;
028
029  /**
030   * Prefer use of the constructor taking the parameters over this method.
031   * This is provided to allow easy Jackson serialization.
032   */
033  public Rollup() {
034  }
035
036  public Rollup(Dimension<?>... d) {
037    this(new ImmutableSet.Builder<Dimension<?>>().addAll(Arrays.asList(d)).build());
038  }
039
040  public Rollup(Set<Dimension<?>> components) {
041    this.dimensions = ImmutableSet.copyOf(components); // defensive copy
042  }
043
044  public Set<Dimension<?>> getDimensions() {
045    return dimensions;
046  }
047
048  /**
049   * Where possible use the constructor and not this version
050   */
051  public void setDimensions(Set<Dimension<?>> dimensions) {
052    this.dimensions = dimensions;
053  }
054
055  @Override
056  public String toString() {
057    return Objects.toStringHelper(this).add("dimensions", dimensions).toString();
058  }
059}