Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
d7b7238a
Commit
d7b7238a
authored
May 18, 2012
by
David Trachtenherz
Browse files
SubComponentIterator class and findSubComponentsRecursively method removed.
refs 779
parent
5ffb2005
Changes
1
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.component/trunk/src/org/fortiss/af3/component/utils/ComponentArchitectureUtils.java
View file @
d7b7238a
...
...
@@ -19,18 +19,10 @@ package org.fortiss.af3.component.utils;
import
static
org
.
conqat
.
lib
.
commons
.
reflect
.
ReflectionUtils
.
pickInstanceOf
;
import
java.util.ArrayDeque
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.NoSuchElementException
;
import
java.util.Queue
;
import
java.util.Set
;
import
org.eclipse.emf.ecore.EObject
;
import
org.fortiss.af3.component.model.Component
;
...
...
@@ -48,15 +40,13 @@ import org.fortiss.tooling.kernel.model.INamedElement;
import
org.fortiss.tooling.kernel.model.IProjectRootElement
;
import
org.fortiss.tooling.kernel.utils.KernelModelElementUtils
;
import
test.org.fortiss.af3.component.common.SubComponentIteratorAndFindingTest
;
/**
* Utility methods for accessing parts of the component architecture.
*
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash:
4EEB8B9A917A95DDFE41099AF9CF1E91
* @ConQAT.Rating YELLOW Hash:
0FD96F1F8D9F600522BF30F433B74F16
*/
public
class
ComponentArchitectureUtils
{
...
...
@@ -149,125 +139,6 @@ public class ComponentArchitectureUtils {
return
null
;
}
/**
* Iterates recursively over all sub-components of a given parent component in BFS order.
*
*
* TODO (FH): this implementation is too complicated; use
* org.fortiss.tooling.kernel.utils.KernelModelElementUtils.findContentElementByNameAndClass(
* EObject,
* String, Class<T>)
* DT: The iterator just does a standard BFS. According to the test
* {@link SubComponentIteratorAndFindingTest#testSubComponentIterator()} it works without any
* problems.
* Or did you mean, that finding given sub-components {@link #findSubComponentsRecursively} is
* too complicated:
* well, I admit, that it isn't as obvious as
* KernelModelElementUtils.findContentElementByNameAndClass(..) but it works correctly, too (see
* {@link SubComponentIteratorAndFindingTest#testFindSubComponentsRecursively()}.
* The main difference to
* {@link org.fortiss.tooling.kernel.utils.KernelModelElementUtils#findContentElementByNameAndClass(EObject, String, Class)}
* is that {@link #findSubComponentsRecursively} is optimized for finding several sub-components
* at once (with names given in a collection):
* using KernelModelElementUtils.findContentElementByNameAndClass(..) to find N sub-components
* would entail N iterations over all elements of the entire model, while
* {@link #findSubComponentsRecursively} uses only one iteration over solely components and
* hence is way more efficient. Of course, it looks a bit more complicated, yet it works well.
* If you would like, I will add more comments in the method to explain its function better.
*
* Dan: I agree here with FloH. This quite complex implementation solves a problem that we DO
* NOT have:
* this functionality is not at all a bottleneck in performance of AF3.
* I would also strongly vote for simplicity, reuse, clarity and directness in the code.
*/
public
static
class
SubComponentIterator
implements
Iterator
<
Component
>
{
/**
* Contains the sub-components to be processed.
*/
protected
Queue
<
Component
>
subComps
;
/**
* Constructs a {@link SubComponentIterator} with the given parent component. The parent
* component itself will not be returned by the iterator.
*/
public
SubComponentIterator
(
Component
parent
)
{
this
(
parent
,
false
);
}
/**
* Constructs a {@link SubComponentIterator} with the given parent component. The parent
* component itself will not be returned by the iterator. {@code includeParent} specifies if
* the {@code parent} should be included as first element.
*/
public
SubComponentIterator
(
Component
parent
,
boolean
includeParent
)
{
if
(
includeParent
)
{
subComps
=
new
ArrayDeque
<
Component
>();
subComps
.
add
(
parent
);
}
else
{
subComps
=
new
ArrayDeque
<
Component
>(
parent
.
getSubComponents
());
}
}
/** {@inheritDoc} */
@Override
public
boolean
hasNext
()
{
return
!
subComps
.
isEmpty
();
}
/** {@inheritDoc} */
@Override
public
Component
next
()
{
if
(
subComps
.
isEmpty
())
{
throw
new
NoSuchElementException
();
}
// Retrieve and remove next sub-component.
Component
res
=
subComps
.
poll
();
// Add all sub-components of the retrieved sub-component to the queue.
subComps
.
addAll
(
res
.
getSubComponents
());
return
res
;
}
/** {@inheritDoc} */
@Override
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
}
}
/**
* Recursively searches for sub-components with names given in {@code compNames}.
*
* @param notFoundCompNames
* If not {@code null} than all names, for which no component has been found, will be
* added to it.
*/
public
static
Map
<
String
,
Component
>
findSubComponentsRecursively
(
Component
parent
,
Collection
<
String
>
compNames
,
Collection
<
String
>
notFoundCompNames
)
{
Set
<
String
>
toBeFoundSet
=
new
HashSet
<
String
>(
compNames
);
Map
<
String
,
Component
>
foundMap
=
new
HashMap
<
String
,
Component
>();
Iterator
<
Component
>
subCompIterator
=
new
SubComponentIterator
(
parent
);
while
(
subCompIterator
.
hasNext
())
{
Component
comp
=
subCompIterator
.
next
();
if
(
toBeFoundSet
.
contains
(
comp
.
getName
()))
{
foundMap
.
put
(
comp
.
getName
(),
comp
);
toBeFoundSet
.
remove
(
comp
.
getName
());
}
// Break if all components found without iterating all sub-components.
if
(
toBeFoundSet
.
isEmpty
())
{
break
;
}
}
/*
* If some components were not found and the {@code notFoundCompNames} is not {@code null}
* then add all component names that could not be found to this collection.
*/
if
(!
toBeFoundSet
.
isEmpty
()
&&
notFoundCompNames
!=
null
)
{
notFoundCompNames
.
addAll
(
toBeFoundSet
);
}
return
foundMap
;
}
/**
* Find output port by name.
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment