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

com.gemstone.gemfire.management.internal.cli.domain.RegionInformation Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */
package com.gemstone.gemfire.management.internal.cli.domain;

import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Scope;

import java.io.Serializable;
import java.util.*;

/***
 * Gives the most basic common information of a region
 * Used by the GetRegionsFunction for 'list region' command
 * @author bansods
 *	since 7.0
 */
public class RegionInformation implements Serializable {
	
	private static final long	serialVersionUID	= 1L;
	protected String name;
	protected String path;
	protected Scope scope;
	protected DataPolicy dataPolicy;
	protected boolean isRoot;
	protected String parentRegion;
	
	private Set subRegionInformationSet = null;
	
	public RegionInformation(Region region, boolean recursive) {
		this.name = region.getFullPath().substring(1);
		this.path = region.getFullPath().substring(1);
		this.scope = region.getAttributes().getScope();
		this.dataPolicy = region.getAttributes().getDataPolicy();
		
		if (region.getParentRegion() == null) {
			this.isRoot = true;
			
			if (recursive) {
				Set> subRegions = region.subregions(recursive);
				subRegionInformationSet = getSubRegions(subRegions);
			}
		} else {
			this.isRoot = false;
			this.parentRegion = region.getParentRegion().getFullPath();
		}
	}
	
	private Set getSubRegions(Set> subRegions) {
	  Set subRegionInformation = new HashSet();
	  
	  for (Region region : subRegions) {
	    RegionInformation regionInformation = new RegionInformation(region, false);
	    subRegionInformation.add(regionInformation);
	  }
	  
	  return subRegionInformation;
	}
	
	public Set getSubRegionNames() {
	  Set subRegionNames = new HashSet();
	  
	  if (subRegionInformationSet != null) {
	    for (RegionInformation regInfo : subRegionInformationSet) {
	      subRegionNames.add(regInfo.getName());
	    }
	  }
	  
	  return subRegionNames;
	}

	public String getName() {
		return name;
	}
	
	public String getPath() {
		return path;
	}
	
	public Scope getScope() {
		return scope;
	}
	
	public DataPolicy getDataPolicy() {
		return dataPolicy;
	}
	
	public Set getSubRegionInformation() {
		return subRegionInformationSet;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof RegionInformation) {
			RegionInformation regionInfoObj = (RegionInformation) obj;
			return this.name.equals(regionInfoObj.getName())
							&& this.path.equals(regionInfoObj.getPath())
							&& this.isRoot == regionInfoObj.isRoot
							&& this.dataPolicy.equals(regionInfoObj.getDataPolicy())
							&& this.scope.equals(regionInfoObj.getScope());
		} else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return	this.name.hashCode()
						^ this.path.hashCode()
						^ this.dataPolicy.hashCode()
						^ this.scope.hashCode();
	}
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("\nName          :\t");
		sb.append(this.getName());
		sb.append("\nPath          :\t");
		sb.append(this.getPath());
		sb.append("\nScope         :\t");
		sb.append(this.getScope().toString());
		sb.append("\nData Policy   :\t");
		sb.append(this.getDataPolicy().toString());
		
		if (this.parentRegion != null) {
			sb.append("\nParent Region :\t");
			sb.append(this.parentRegion);
		}
		
		return sb.toString();
	}
	
	public String getSubRegionInfoAsString() {
		StringBuilder sb = new StringBuilder();
		if (this.isRoot) {
			
			for (RegionInformation regionInfo : this.subRegionInformationSet) {
				sb.append("\n");
				sb.append(regionInfo.getName());
			}
		}
		return sb.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy