File UiVisualizer.java
has 705 lines of code (exceeds 250 allowed). Consider refactoring. Open
/* UiVisualizer.java
Purpose:
Description:
Method getResponses
has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring. Open
public List<AuResponse> getResponses(Collection<Component> renderedComps) throws IOException {
_ending = true; //no more modifying UI (invalidate/addSmartUpdate...)
/* if (log.finerable())
log.finer("ei: "+this+"\nInvalidated: "+_invalidated+"\nSmart Upd: "+_smartUpdated
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
UiVisualizer
has 46 methods (exceeds 20 allowed). Consider refactoring. Open
/*package*/ class UiVisualizer implements Visualizer {
// private static final Logger log = LoggerFactory.getLogger(UiVisualizer.class);
/** The parent exec info. */
private final UiVisualizer _parent;
Method removeRedundant
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
private void removeRedundant() {
int initsz = (_invalidated.size() + _attached.size()) / 2 + 30;
final Set<Component> ins = new HashSet<Component>(initsz), //one of ancestor in _invalidated or _attached
outs = new HashSet<Component>(initsz); //none of ancestor in _invalidated nor _attached
final List<Component> ancs = new ArrayList<Component>(50);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addResponsesForCreatedPerSiblings
has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring. Open
private static void addResponsesForCreatedPerSiblings(List<AuResponse> responses, Set<Component> newsibs,
Map<Component, Set<? extends Component>> croppingInfos) throws IOException {
final Component parent;
final Page page;
{
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getResponses
has 105 lines of code (exceeds 25 allowed). Consider refactoring. Open
public List<AuResponse> getResponses(Collection<Component> renderedComps) throws IOException {
_ending = true; //no more modifying UI (invalidate/addSmartUpdate...)
/* if (log.finerable())
log.finer("ei: "+this+"\nInvalidated: "+_invalidated+"\nSmart Upd: "+_smartUpdated
Method crop
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
private void crop(Set coll, Map<Component, Set<? extends Component>> croppingInfos, boolean bResponse) {
for (Iterator it = coll.iterator(); it.hasNext();) {
final Object o = it.next();
if (!(o instanceof Component))
continue;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if (_recovering || _disabled || (newpg == null && oldpg == null)
|| (newpg == null && (oldpg instanceof VolatilePage || !_exec.isAsyncUpdate(oldpg))) //detach from loading pg
|| (oldpg == null && (newpg instanceof VolatilePage || !_exec.isAsyncUpdate(newpg))) //attach to loading pg
|| isCUDisabled(comp) || (oldparent != null && isCUDisabled(oldparent)))
return; //to avoid redundant AuRemove
Method checkPageRemoved
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
private void checkPageRemoved(Set<Component> removed) {
//1. scan once
final Desktop desktop = _exec.getDesktop();
Set<Page> pages = null;
for (Page page : desktop.getPages()) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addResponse
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public void addResponse(String key, AuResponse response, int priority) {
if (response == null)
throw new IllegalArgumentException();
//relative fix BUG ZK-1464
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method removeRedundant
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void removeRedundant() {
int initsz = (_invalidated.size() + _attached.size()) / 2 + 30;
final Set<Component> ins = new HashSet<Component>(initsz), //one of ancestor in _invalidated or _attached
outs = new HashSet<Component>(initsz); //none of ancestor in _invalidated nor _attached
final List<Component> ancs = new ArrayList<Component>(50);
Method addMoved
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public void addMoved(Component comp, Component oldparent, Page oldpg, Page newpg) {
if (_recovering || _disabled || (newpg == null && oldpg == null)
|| (newpg == null && (oldpg instanceof VolatilePage || !_exec.isAsyncUpdate(oldpg))) //detach from loading pg
|| (oldpg == null && (newpg instanceof VolatilePage || !_exec.isAsyncUpdate(newpg))) //attach to loading pg
|| isCUDisabled(comp) || (oldparent != null && isCUDisabled(oldparent)))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addResponsesForCreatedPerSiblings
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static void addResponsesForCreatedPerSiblings(List<AuResponse> responses, Set<Component> newsibs,
Map<Component, Set<? extends Component>> croppingInfos) throws IOException {
final Component parent;
final Page page;
{
Method checkPageRemoved
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
private void checkPageRemoved(Set<Component> removed) {
//1. scan once
final Desktop desktop = _exec.getDesktop();
Set<Page> pages = null;
for (Page page : desktop.getPages()) {
Method doDetached
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private void doDetached() {
l_out: for (Map.Entry<Component, Component> me : _detached.entrySet()) {
Component p = me.getValue();
for (; p != null; p = p.getParent())
if (_moved.contains(p) || _detached.containsKey(p) || _invalidated.contains(p) || _attached.contains(p))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addResponse
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public void addResponse(String key, AuResponse response, int priority) {
if (response == null)
throw new IllegalArgumentException();
//relative fix BUG ZK-1464
Method doMoved
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private Set<Component> doMoved(List<AuResponse> responses) {
//Remove components that have to removed from the client
final Set<Component> removed = new LinkedHashSet<Component>();
for (Component comp : _moved) {
final Page page = comp.getPage();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if (_recovering || _disabled || page == null || page instanceof VolatilePage || !_exec.isAsyncUpdate(page)
|| _invalidated.contains(comp) || isCUDisabled(comp))
return null; //nothing to do
Avoid deeply nested control flow statements. Open
if (ck != null && ck.getParent() == parent) {
newsibs.add(ck);
attached[k] = null;
}
Method compareTo
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public int compareTo(Object o) {
final TimedValue tv = (TimedValue) o;
return _priority == tv._priority ? _timed > tv._timed ? 1 : _timed == tv._timed ? 0 : -1
: _priority > tv._priority ? -1 : 1; //higher priority, earlier (smaller)
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Consider simplifying this complex logical expression. Open
if (_recovering || _disabled || page == null || page instanceof VolatilePage || !_exec.isAsyncUpdate(page)
|| isCUDisabled(comp))
return; //nothing to do
Consider simplifying this complex logical expression. Open
if (ownerPage == null //detached
|| (_pgInvalid != null && _pgInvalid.contains(ownerPage))
|| isAncestor(_invalidated, owner, true) || isAncestor(_attached, owner, true)
|| isAncestor(removed, owner, true)) {
addPageRemoved(page);
Method addSmartUpdate0
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private void addSmartUpdate0(Component comp, String attr, Object value, boolean append, int priority) {
Method clearInInvalidPage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private void clearInInvalidPage(Collection<Component> coll) {
for (Iterator<Component> it = coll.iterator(); it.hasNext();) {
final Component comp = it.next();
final Page page = comp.getPage();
if (page != null && ((_pgRemoved != null && _pgRemoved.contains(page))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getAvailableAtClient
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private static Set<? extends Component> getAvailableAtClient(Component comp,
Map<Component, Set<? extends Component>> croppingInfos) {
final Object xc = ((ComponentCtrl) comp).getExtraCtrl();
if (xc instanceof Cropper) {
//we don't need to check isCropper first since its component's job
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addInvalidate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public void addInvalidate(Component comp) {
final Page page = comp.getPage();
if (_recovering || _disabled || page == null || page instanceof VolatilePage || !_exec.isAsyncUpdate(page)
|| isCUDisabled(comp))
return; //nothing to do
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method isCUDisabled
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private final boolean isCUDisabled(Component comp) {
if (_updDisabled != null) {
//no need to check comp.getPage() since it was checked before calling
for (; comp != null; comp = comp.getParent())
if (_updDisabled.contains(comp))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method addSmartUpdate0
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private void addSmartUpdate0(Component comp, String attr, Object value, boolean append, int priority) {
if (comp == null)
throw new IllegalArgumentException();
//main fix for BUG ZK-1464
if (_ending && (comp.getPage() == null || (_pgRemoved != null && _pgRemoved.contains(comp.getPage())))) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method disableClientUpdate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public boolean disableClientUpdate(Component comp, boolean disable) {
if (disable) {
if (_updDisabled == null)
_updDisabled = new HashSet<Component>(4);
return !_updDisabled.add(comp);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method isAncestor
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private boolean isAncestor(Collection<Component> coll, Component comp, boolean includingEquals) {
for (Iterator<Component> it = coll.iterator(); it.hasNext();) {
final Component c = it.next();
if ((includingEquals || c != comp) && Components.isAncestor(c, comp))
return true;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Identical blocks of code found in 2 locations. Consider refactoring. Open
while ((p = p.getParent()) != null) { //don't check p in _invalidated
if (outs.contains(p)) //checked
break;
if (ins.contains(p) || _invalidated.contains(p) || _attached.contains(p)) {
it.remove();
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 78.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
while ((p = p.getParent()) != null) { //don't check p in _attached
if (outs.contains(p)) //checked
break;
if (ins.contains(p) || _invalidated.contains(p) || _attached.contains(p)) {
it.remove();
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 78.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76