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

com.redislabs.redisgraph.impl.StatisticsImpl Maven / Gradle / Ivy

There is a newer version: 2.6.0-rc3
Show newest version
package com.redislabs.redisgraph.impl;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import com.redislabs.redisgraph.Statistics;

import redis.clients.jedis.util.SafeEncoder;

public class StatisticsImpl implements Statistics  {
	private final List raw;
	private final Map statistics;
	
	StatisticsImpl(List raw){
		this.raw = raw;
		this.statistics = new EnumMap<>(Statistics.Label.class); // lazy loaded
	}
	
	@Override
	public String getStringValue(Statistics.Label label) {
		return getStatistics().get(label);
	}
	
	private Map getStatistics(){
		if(statistics.size() == 0) {		
			for(byte[]  touple : this.raw) {
			    String text = SafeEncoder.encode(touple);		    
				String[] rowTouple = text.split(":");
				if(rowTouple.length == 2) {
				  Statistics.Label label = Statistics.Label.getEnum(rowTouple[0]);
				  if(label != null) {
				    this.statistics.put( label, rowTouple[1].trim());
				  }
				} 
			}
		}
		return statistics;
	}
	
	public int getIntValue(Statistics.Label label) {
		String value = getStringValue(label);
		return value==null ? 0 : Integer.parseInt(value);
	}

	@Override
	public int nodesCreated() {
		return getIntValue(Label.NODES_CREATED);
	}

	@Override
	public int nodesDeleted() {
		return getIntValue(Label.NODES_DELETED);
	}

   @Override
   public int indicesAdded() {
        return getIntValue(Label.INDICES_ADDED);
   }
   
	
	@Override
	public int labelsAdded() {
		return getIntValue(Label.LABELS_ADDED);
	}

	@Override
	public int relationshipsDeleted() {
		return getIntValue(Label.RELATIONSHIPS_DELETED);
	}

	@Override
	public int relationshipsCreated() {
		return getIntValue(Label.RELATIONSHIPS_CREATED);
	}

	@Override
	public int propertiesSet() {
		return getIntValue(Label.PROPERTIES_SET);
	}
	
	@Override
	public String toString() {
		return getStatistics().toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy