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