com.gemstone.gemfire.internal.admin.remote.CacheDisplay Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
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.internal.admin.remote;
import com.gemstone.gemfire.internal.admin.GemFireVM;
import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
public final class CacheDisplay {
public static Object getCachedObjectDisplay(Object obj, int inspectionType) {
switch(inspectionType) {
case GemFireVM.LIGHTWEIGHT_CACHE_VALUE:
if (obj == null) {
return "null";
}
String toString = obj.toString();
Class clazz = obj.getClass();
String name = null;
if (clazz.isArray()) {
return getArrayDisplayName(obj);
} else {
name = getClassName(clazz);
}
//if (toString.indexOf('@') >= 0) { //probably Object.toString()
// return "a " + name;
//} else {
return name + " \"" + toString + "\"";
//}
case GemFireVM.PHYSICAL_CACHE_VALUE:
Object physicalVal = EntryValueNodeImpl.createFromValueRoot(obj, false);
return (physicalVal == null) ? "null" : physicalVal;
case GemFireVM.LOGICAL_CACHE_VALUE:
Object logicalVal = EntryValueNodeImpl.createFromValueRoot(obj, true);
return (logicalVal == null) ? "null" : logicalVal;
default:
throw new IllegalArgumentException(LocalizedStrings.CacheDisplay_INVALID_INSPECTIONTYPE_PASSED_TO_CACHEDISPLAYGETCACHEDOBJECTDISPLAY.toLocalizedString());
}
}
private static String getArrayDisplayName(Object instance) {
if (instance instanceof Object[]) {
String className = instance.getClass().getName();
return "an array of " + getClassName(className.substring(2, className.length()-1)) + " with " + ((Object[])instance).length + " elements";
} else if (instance instanceof int[]) {
return "an array of int with " + ((int[])instance).length + " elements";
} else if (instance instanceof double[]) {
return "an array of double with " + ((double[])instance).length + " elements";
} else if (instance instanceof char[]) {
return "an array of char with " + ((char[])instance).length + " elements";
} else if (instance instanceof byte[]) {
return "an array of byte with " + ((byte[])instance).length + " elements";
} else if (instance instanceof boolean[]) {
return "an array of boolean with " + ((boolean[])instance).length + " elements";
} else if (instance instanceof long[]) {
return "an array of long with " + ((long[])instance).length + " elements";
} else if (instance instanceof float[]) {
return "an array of float with " + ((float[])instance).length + " elements";
} else if (instance instanceof short[]) {
return "an array of short with " + ((short[])instance).length + " elements";
} else return null;
}
private static String getClassName(Class clazz) {
return getClassName(clazz.getName());
}
private static String getClassName(String name) {
return (name.length() > 64) ? name.substring(name.lastIndexOf(".")+1) : name;
}
}