/*
* JavaInspect - Utility to visualize java software
- * Copyright (C) 2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright (C) 2013-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
*
* This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
*/
package eu.svjatoslav.inspector.java.structure;
/**
* Amount of field and method references pointing to this class.
*/
- private int incomingReferencesCount = 0;
+ private int referencesCount = 0;
+ // for interface, counts amount of found implementations
+ private int implementationsCount = 0;
+
+ // counts amount of times this class is extended
private int extensionsCount = 0;
public ClassDescriptor(final Class<? extends Object> clazz,
for (final Class interfaceClass : clazz.getInterfaces()) {
final ClassDescriptor classDescriptor = dump
.addClass(interfaceClass);
- classDescriptor.registerExtension();
+ classDescriptor.registerImplementation();
interfaces.add(classDescriptor);
}
}
public boolean areReferencesShown() {
- return incomingReferencesCount <= MAX_REFERECNES_COUNT;
+ return referencesCount <= MAX_REFERECNES_COUNT;
}
public void enlistFieldReferences(final StringBuffer result) {
return null;
}
+ /**
+ * Returns field with given name (case is ignored). Or <code>null</code> if
+ * field is not found.
+ */
+ public FieldDescriptor getFieldIgnoreCase(final String fieldToSearch) {
+
+ for (final String fieldName : nameToFieldMap.keySet())
+ if (fieldToSearch.equalsIgnoreCase(fieldName))
+ return nameToFieldMap.get(fieldName);
+
+ return null;
+ }
+
@Override
public String getGraphId() {
final String result = "class_"
return result;
}
- public String getPackageName() {
-
- final int i = fullyQualifiedName.lastIndexOf('.');
-
- if (i == -1)
- return "";
-
- return fullyQualifiedName.substring(0, i).replace("[L", "");
- }
-
// public String getReadableName() {
//
// // do not print full class name for well known system classes
// return fullyQualifiedName;
// }
+ public String getPackageName() {
+
+ final int i = fullyQualifiedName.lastIndexOf('.');
+
+ if (i == -1)
+ return "";
+
+ return fullyQualifiedName.substring(0, i).replace("[L", "");
+ }
+
public String getParentClassesName() {
int i = fullyQualifiedName.lastIndexOf('.');
final String fullClassName = fullyQualifiedName.substring(i + 1);
return superClassColor;
}
+ /**
+ * Checks if class has field with given name (case is ignored). Returns
+ * <code>true</code> if such field is found.
+ */
+ public boolean hasFieldIgnoreCase(final String fieldToSearch) {
+
+ for (final String fieldName : nameToFieldMap.keySet())
+ if (fieldToSearch.equalsIgnoreCase(fieldName))
+ return true;
+
+ return false;
+ }
+
public void hide() {
isShown = false;
}
return;
final int totalReferencesCount = getOutgoingReferencesCount()
- + incomingReferencesCount + extensionsCount;
+ + referencesCount + extensionsCount + implementationsCount;
if (totalReferencesCount == 0) {
hide();
}
/**
- * Register event when another class is extending this one, or is
- * implementing interface declared by this class.
+ * Register event when another class is extending this one.
*/
public void registerExtension() {
extensionsCount++;
}
+ public void registerImplementation() {
+ implementationsCount++;
+ }
+
public void registerReference() {
- incomingReferencesCount++;
+ referencesCount++;
}
public void setDistinctiveColor(final String distinctiveColor) {