⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exportdata.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ============================================================
 * JRobin : Pure java implementation of RRDTool's functionality
 * ============================================================
 *
 * Project Info:  http://www.jrobin.org
 * Project Lead:  Sasa Markovic (saxon@jrobin.org)
 *
 * Developers:    Sasa Markovic (saxon@jrobin.org)
 *                Arne Vandamme (cobralord@jrobin.org)
 *
 * (C) Copyright 2003, by Sasa Markovic.
 *
 * This library is free software; you can redistribute it and/or modify it under the terms
 * of the GNU Lesser General Public License as published by the Free Software Foundation;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
package net.jumperz.ext.org.jrobin.graph;

import net.jumperz.ext.org.jrobin.core.RrdDataSet;
import net.jumperz.ext.org.jrobin.core.RrdException;
import net.jumperz.ext.org.jrobin.core.Util;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import java.util.HashMap;
import java.io.*;

/**
 * <p>ExportData represents a reduced dataset that is the result of a JRobin rrd export.</p>
 *
 * @author Arne Vandamme (cobralord@jrobin.org)
 */
public class ExportData implements RrdDataSet
{
	// ================================================================
	// -- Members
	// ================================================================
	private int arraySize;
	private long[] timestamps;

	private HashMap sourceByName, legends;
	private Source[] sources;

	private Print printer;

	// ================================================================
	// -- Constructors
	// ================================================================
	ExportData()
	{
		sourceByName	= new HashMap();
		legends			= new HashMap();
	}

	ExportData( long[] timestamps, Source[] sources, HashMap legends )
	{
		this.timestamps	= timestamps;
		this.sources	= sources;
		this.legends	= legends;
		this.arraySize	= timestamps.length;

		sourceByName	= new HashMap( sources.length );
		for ( int i = 0; i < sources.length; i++ )
			sourceByName.put( sources[i].getName(), sources[i] );
	}

	/**
	 * Create an ExportData object based on export XML string..
	 *
	 * @param xportXml File containing export xml.
	 * @throws RrdException Thrown in case of JRobin specific exception.
	 * @throws IOException Thrown in case of I/O related exception.
	 */
	public ExportData( String xportXml ) throws RrdException, IOException
	{
		this();

		importXml( xportXml );
	}

	/**
	 * Create an ExportData object based on export XML string..
	 *
	 * @param xportXml File containing export xml.
	 * @param useLegendNames Map datasources to legend items in the export xml.
	 * @throws RrdException Thrown in case of JRobin specific exception.
	 * @throws IOException Thrown in case of I/O related exception.
	 */
	public ExportData( String xportXml, boolean useLegendNames ) throws RrdException, IOException
	{
		this();

		importXml( xportXml, useLegendNames );
	}

	/**
	 * Create an ExportData object based on export XML string..
	 *
	 * @param xportXml File containing export xml.
	 * @param dsNamePrefix Prefix of the datasource names.
	 * @throws RrdException Thrown in case of JRobin specific exception.
	 * @throws IOException Thrown in case of I/O related exception.
	 */
	public ExportData( String xportXml, String dsNamePrefix ) throws RrdException, IOException
	{
		this();

		importXml( xportXml, dsNamePrefix );
	}

	/**
	 * Create an ExportData object based on export XML file.
	 *
	 * @param xmlFile File containing export xml.
	 * @throws RrdException Thrown in case of JRobin specific exception.
	 * @throws IOException Thrown in case of I/O related exception.
	 */
	public ExportData( File xmlFile ) throws RrdException, IOException
	{
		this();

		importXml( xmlFile );
	}

	/**
	 * Create an ExportData object based on export XML file.
	 *
	 * @param xmlFile File containing export xml.
	 * @param useLegendNames Map datasources to legend items in the export xml.
	 * @throws RrdException Thrown in case of JRobin specific exception.
	 * @throws IOException Thrown in case of I/O related exception.
	 */
	public ExportData( File xmlFile, boolean useLegendNames ) throws RrdException, IOException
	{
		this();

		importXml( xmlFile, useLegendNames );
	}

	/**
	 * Create an ExportData object based on export XML file.
	 *
	 * @param xmlFile File containing export xml.
	 * @param dsNamePrefix Prefix of the datasource names.
	 * @throws RrdException Thrown in case of JRobin specific exception.
	 * @throws IOException Thrown in case of I/O related exception.
	 */
	public ExportData( File xmlFile, String dsNamePrefix ) throws RrdException, IOException
	{
		this();

		importXml( xmlFile, dsNamePrefix );
	}


	// ================================================================
	// -- Public methods
	// ================================================================
	/**
	 * Returns the number of rows in this dataset.
	 *
	 * @return Number of rows (data samples).
	 */
	public int getRowCount() {
		return sources.length;
	}

    /**
	 * Returns the number of columns in this dataset.
	 *
	 * @return Number of columns (datasources).
	 */
	public int getColumnCount() {
		return arraySize;
	}

	/**
	 * Returns an array of timestamps covering the whole range specified in the
	 * dataset object.
	 *
	 * @return Array of equidistant timestamps.
	 */
	public long[] getTimestamps()
	{
		return timestamps;
	}

	/**
	 * Returns the step with which this data was fetched.
	 * 
	 * @return Step as long.
	 */
	public long getStep()
	{
		return timestamps[1] - timestamps[0];
	}

	/**
	 * Returns all values for a single datasource, the returned values
	 * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method.
	 *
	 * @param dsIndex Datasource index.
	 * @return Array of single datasource values.
	 */
	public double[] getValues( int dsIndex )
	{
		return sources[dsIndex].getValues();
	}

	/**
	 * Returns all values for all datasources, the returned values
	 * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method.
	 *
	 * @return Two-dimensional aray of all datasource values.
	 */
	public double[][] getValues()
	{
		double[][] values = new double[ sources.length ][ arraySize ];

		for ( int i = 0; i < sources.length; i++ )
			values[i] = sources[i].getValues();

		return values;
	}

	/**
	 * Returns all values for a single datasource. The returned values
	 * correspond to the timestamps returned with the {@link #getTimestamps() getTimestamps()} method.
	 *
	 * @param dsName Datasource name.
	 * @return Array of single datasource values.
	 * @throws RrdException Thrown if no matching datasource name is found.
	 */
	public double[] getValues( String dsName ) throws RrdException
	{
		Source src 		= getSource( dsName );

		return src.getValues();
	}

    /**
	 * Returns the first timestamp in the dataset.
	 *
	 * @return The smallest timestamp.
	 */
	public long getFirstTimestamp() {
		return timestamps[0];
	}

	/**
	 * Returns the last timestamp in the dataset.
	 *
	 * @return The biggest timestamp.
	 */
	public long getLastTimestamp() {
		return timestamps[ arraySize - 1 ];
	}

	/**
	 * Returns array of the names of all datasources in the set.
	 *
	 * @return Array of datasource names.
	 */
	public String[] getDsNames()
	{
		String[] names = new String[ sources.length ];

		for ( int i = 0; i < sources.length; i++ )
			names[i] = sources[i].getName();

		return names;
	}

	/**
	 * Retrieve the table index number of a datasource by name.
	 * Names are case sensitive.
	 *
	 * @param dsName Name of the datasource for which to find the index.
	 * @return Index number of the datasource in the value table.
	 * @throws RrdException Thrown if the given datasource name cannot be found in the dataset.
	 */
	public int getDsIndex( String dsName ) throws RrdException
	{
		for ( int i = 0; i < sources.length; i++ )
			if ( sources[i].getName().equals(dsName) )
				return i;

		throw new RrdException( "No such datasource: " + dsName );
	}

	/**
	 * Returns aggregated value from the dataset for a single datasource.
	 *
	 * @param dsName Datasource name
	 * @param consolFun Consolidation function to be applied to set datasource values datasource.
	 * Valid consolidation functions are MIN, MAX, LAST, FIRST, AVERAGE and TOTAL
	 * @return MIN, MAX, LAST, FIRST, AVERAGE or TOTAL value calculated from the dataset for the given datasource name
	 * @throws RrdException Thrown if the given datasource name cannot be found in the dataset.
	 */
	public double getAggregate( String dsName, String consolFun ) throws RrdException
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -