Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
0871526d
Commit
0871526d
authored
13 years ago
by
Daniel Ratiu
Browse files
Options
Downloads
Patches
Plain Diff
new utility method
refs 163
parent
8364d6bf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java
+75
-0
75 additions, 0 deletions
...runk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java
with
75 additions
and
0 deletions
org.fortiss.tooling.kernel/trunk/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java
0 → 100644
+
75
−
0
View file @
0871526d
/*--------------------------------------------------------------------------+
$Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
| |
| Copyright 2011 ForTISS GmbH |
| |
| 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. |
+--------------------------------------------------------------------------*/
package
org.fortiss.tooling.kernel.utils
;
import
org.eclipse.emf.common.util.BasicEList
;
import
org.eclipse.emf.common.util.ECollections
;
import
org.eclipse.emf.common.util.EList
;
/**
* Utility methods for dealing with .ecore models. These methods should be used
* to define EMF operations that make the models easier to use.
*
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating RED Hash:
*/
public
class
EcoreUtils
{
/**
* Converts an EList of a given type into an EList of one of its subtypes.
* Utility method to avoid unnecessary casts.
*
* @param targetClass
* - the class representing the subtype
* @param sourceList
* - the source list containing objects of type S, a supertype of
* T
* @return a target EList containing elements of type targetClazz
*/
@SuppressWarnings
(
"unchecked"
)
public
static
<
S
,
T
extends
S
>
EList
<
T
>
convertList
(
Class
<
T
>
targetClass
,
EList
<
S
>
sourceList
)
{
return
(
EList
<
T
>)
(
EList
<?>)
sourceList
;
}
/**
* From a given EList with source objects of type S create another
* unmodifiable EList with objects of type T, whereby T is a sub-type of S.
* The resulting EList is unmodifiable thereby it represents only a view
* over the source list.
*
* @param targetClass
* - a class representing type T
* @param sourceList
* - an EList with objects of type S
* @return an unmodifiable EList of objects of type T
*/
@SuppressWarnings
(
"unchecked"
)
public
static
<
S
,
T
extends
S
>
EList
<
T
>
pickInstanceOf
(
Class
<
T
>
targetClass
,
EList
<
S
>
sourceList
)
{
if
(
sourceList
==
null
)
return
null
;
EList
<
T
>
result
=
new
BasicEList
<
T
>();
for
(
S
sourceElement
:
sourceList
)
if
(
targetClass
.
isAssignableFrom
(
sourceElement
.
getClass
()))
result
.
add
((
T
)
sourceElement
);
return
ECollections
.
unmodifiableEList
(
result
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment