de.uniks.networkparser.graph.GraphMember Maven / Gradle / Ivy
package de.uniks.networkparser.graph;
import de.uniks.networkparser.buffer.CharacterBuffer;
/*
NetworkParser
The MIT License
Copyright (c) 2010-2016 Stefan Lindel https://github.com/fujaba/NetworkParser/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import de.uniks.networkparser.interfaces.Condition;
import de.uniks.networkparser.list.SimpleSet;
public abstract class GraphMember {
public static final String PROPERTY_NAME="name";
public static final String PROPERTY_CLASSNAME = "className";
public static final String PROPERTY_PARENT="parent";
public static final String PROPERTY_CHILD="child";
public static final String PROPERTY_VISIBILITY = "visibility";
public static final String PROPERTY_MODIFIERS = "modifiers";
public static final String PROPERTY_THIS = "this";
protected String name;
protected Object children;
protected Object parentNode;
public Object getValue(String attribute) {
if(PROPERTY_VISIBILITY.equalsIgnoreCase(attribute)) {
Modifier modifier = this.getModifier();
if (modifier == null) {
return Modifier.PRIVATE.getName();
}
return modifier.getName();
}
if(PROPERTY_MODIFIERS.equalsIgnoreCase(attribute)) {
CharacterBuffer buffer = new CharacterBuffer();
Modifier modifier = this.getModifier();
if(modifier != null) {
modifier = modifier.getModifier();
while(modifier != null) {
buffer.with(modifier.getName());
modifier = modifier.getModifier();
if(modifier != null) {
buffer.with(' ');
}
}
}
return buffer.toString();
}
if(PROPERTY_NAME.equalsIgnoreCase(attribute)) {
return this.name;
}
if (PROPERTY_CLASSNAME.equalsIgnoreCase(attribute)) {
return this.getClass().getName();
}
int pos = attribute.indexOf('.');
String attrName;
if(pos>0) {
attrName = attribute.substring(0, pos);
}else {
attrName = attribute;
}
if(PROPERTY_PARENT.equalsIgnoreCase(attrName)) {
if (pos > 0) {
if (parentNode instanceof GraphMember) {
GraphMember item = (GraphMember) this.getParent();
return item.getValue(attribute.substring(pos + 1));
}
return null;
}
return this.parentNode;
}
if(PROPERTY_CHILD.equalsIgnoreCase(attrName)) {
if (pos > 0) {
if (pos > 0) {
GraphSimpleSet item = this.getChildren();
return item.getValue(attribute.substring(pos + 1));
}
}
return this.children;
}
if(PROPERTY_THIS.equalsIgnoreCase(attrName)) {
// Check if Static or not
if(this.getModifier().has(Modifier.STATIC)) {
return getValue(PROPERTY_PARENT);
}
return PROPERTY_THIS;
}
return null;
}
@SuppressWarnings("unchecked")
protected boolean check(GraphMember element, Condition>... filters) {
if(filters == null) {
return element != null;
}
boolean result=true;
for(Condition> item : filters) {
Condition
© 2015 - 2025 Weber Informatics LLC | Privacy Policy