All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rapture.common.RaptureCubeCell Maven / Gradle / Ivy

/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2011-2016 Incapture Technologies LLC
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
/**
s * Copyright (C) 2011-2015 Incapture Technologies LLC
 *
 * This is an autogenerated license statement. When copyright notices appear below
 * this one that copyright supercedes this statement.
 *
 * Unless required by applicable law or agreed to in writing, software is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied.
 *
 * Unless explicit permission obtained in writing this software cannot be distributed.
 */
package rapture.common;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * A cell in a cube
 *
 * @author alan
 */
public class RaptureCubeCell implements RaptureTransferObject {
    private int entryCount;

    private String value;

    private String units;

    @JsonIgnore
    private double dVal = 0.0;

    public void addEntry(String colResult, RaptureField f) {
        if (colResult == null || colResult.isEmpty()) {
            return;
        }
        if (value == null) {
            setValue(colResult);
        } else {
            switch (f.getGroupingFn()) {
                case SUM:
                    dVal += Double.valueOf(colResult);
                    value = Double.toString(dVal);
                    break;
                case AVERAGE:
                    dVal *= entryCount;
                    dVal += Double.valueOf(colResult);
                    dVal /= (entryCount + 1);
                    value = Double.toString(dVal);
                    break;
                case NONE:
                    value = value + "," + colResult;
                    break;
            }
        }
        entryCount++;
    }

    public int getEntryCount() {
        return entryCount;
    }

    public String getUnits() {
        return units;
    }

    public String getValue() {
        return value;
    }

    public void setEntryCount(int entryCount) {
        this.entryCount = entryCount;
    }

    public void setUnits(String units) {
        this.units = units;
    }

    public void setValue(String value) {
        this.value = value;
        if (value != null && !value.isEmpty()) {
            dVal = Double.valueOf(value);
        } else {
            dVal = 0.0;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy