001/* 002// This software is subject to the terms of the Eclipse Public License v1.0 003// Agreement, available at the following URL: 004// http://www.eclipse.org/legal/epl-v10.html. 005// You must accept the terms of that agreement to use this software. 006// 007// Copyright (C) 2011-2013 Pentaho and others 008// All Rights Reserved. 009*/ 010package mondrian.rolap.agg; 011 012import mondrian.util.Pair; 013 014import java.util.*; 015 016/** 017 * Implementation of a segment body which stores the data inside 018 * a dense primitive array of integers. 019 * 020 * @author LBoudreau 021 */ 022class DenseIntSegmentBody extends AbstractSegmentBody { 023 private static final long serialVersionUID = 5391233622968115488L; 024 025 private final int[] values; 026 private final BitSet nullValues; 027 028 /** 029 * Creates a DenseIntSegmentBody. 030 * 031 * <p>Stores the given array of cell values and null indicators; caller must 032 * not modify them afterwards.</p> 033 * 034 * @param nullValues A bit-set indicating whether values are null. Each 035 * position in the bit-set corresponds to an offset in the 036 * value array. If position is null, the corresponding 037 * entry in the value array will also be 0. 038 * @param values Cell values 039 * @param axes Axes 040 */ 041 DenseIntSegmentBody( 042 BitSet nullValues, 043 int[] values, 044 List<Pair<SortedSet<Comparable>, Boolean>> axes) 045 { 046 super(axes); 047 this.values = values; 048 this.nullValues = nullValues; 049 } 050 051 @Override 052 public Object getValueArray() { 053 return values; 054 } 055 056 @Override 057 public BitSet getNullValueIndicators() { 058 return nullValues; 059 } 060 061 protected int getSize() { 062 return values.length - nullValues.cardinality(); 063 } 064 065 protected Object getObject(int i) { 066 int value = values[i]; 067 if (value == 0 && nullValues.get(i)) { 068 return null; 069 } 070 return value; 071 } 072} 073 074// End DenseIntSegmentBody.java