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

com.jamonapi.MonitorComposite Maven / Gradle / Ivy

There is a newer version: 2.82
Show newest version

package com.jamonapi;


import com.jamonapi.utils.DetailData;
import com.jamonapi.utils.Misc;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Treats groups of monitors the same way you treat one monitor.  i.e. you can enable/disable/reset
 * etc a group of monitors.
 */
public class MonitorComposite extends Monitor  implements DetailData  {

    private final Monitor[] monitors;// the monitors in the composite
    private final int numRows; // rows in the composite
    private final static int TYPICAL_NUM_CHILDREN=200;// hopefully makes it so the monitor need not grow all the time

    /** Creates a new instance of MonitorComposite */
    public MonitorComposite(Monitor[] monitors) {
        this.monitors=monitors;
        numRows=(monitors==null) ? 0 : monitors.length;
    }

    MonitorComposite() {
        this(null);
    }

    public Monitor[] getMonitors() {
        return monitors;
    }

    /** Pass in an array with col1=lables, and col2=units and then call methods */
    public static MonitorComposite getMonitors(String[][] labels) {
        int numRows=(labels==null) ? 0 : labels.length;
        int numCols=(labels[0]==null) ? 0 : labels[0].length;

        Monitor[] monArray=new Monitor[numRows];

        for (int i=0; i\n");

        for (int i=0;i"+header[i]+"");

        html.append(""+header[0]+"");//repeat first header
        html.append("\n");

        for (int i=0;i");
            for (int j=0;j"+data[i][j]+"");
            }
            html.append(""+data[i][0]+"");// repeat first column
            html.append("\n");
        }


        html.append("");

        return html.toString();
    }

    /** Does this have data? */
    public boolean hasData() {
        return (getNumRows()==0) ? false : true;
    }

    // Various get row data methods (for full row, basic row, and display row
    private Object[] getRowData(MonitorImp mon) {
        List row=new ArrayList(TYPICAL_NUM_CHILDREN);
        mon.getRowData(row);
        return row.toArray();

    }

    private Object[] getBasicRowData(MonitorImp mon) {
        List row=new ArrayList();
        mon.getBasicRowData(row);
        return row.toArray();

    }


    private Object[] getRowDisplayData(MonitorImp mon) {
        List row=new ArrayList(TYPICAL_NUM_CHILDREN);
        mon.getRowDisplayData(row);
        return row.toArray();

    }


    @Override
    public void reset() {
        for (int i=0;i0) // thisDate>lastAccess
                lastAccess=thisDate;

        }

        return lastAccess;
    }


    @Override
    public double getLastValue() {
        Date date=getLastAccess();
        for (int i=0;i=0) // date>=getLastAccess)
                return monitors[i].getLastValue();
        }

        return 0;
    }


    @Override
    public double getMax() {
        double max=MonInternals.MAX_DOUBLE;

        for (int i=0;imax)
                max=thisMax;
        }

        return max;
    }


    @Override
    public double getMaxActive() {
        double max=MonInternals.MAX_DOUBLE;

        for (int i=0;imax)
                max=thisMax;
        }

        return max;
    }

    @Override
    public double getMin() {
        double min=MonInternals.MIN_DOUBLE;

        for (int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy