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
47cb971b
Commit
47cb971b
authored
8 years ago
by
Vincent Aravantinos
Browse files
Options
Downloads
Patches
Plain Diff
moves the corresponding utility methods (after generalizing them)
refs 2708
parent
82455d3b
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.base/trunk/src/org/fortiss/tooling/base/utils/ConstraintsBaseUtils.java
+195
-0
195 additions, 0 deletions
.../org/fortiss/tooling/base/utils/ConstraintsBaseUtils.java
with
195 additions
and
0 deletions
org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/utils/ConstraintsBaseUtils.java
0 → 100644
+
195
−
0
View file @
47cb971b
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 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.base.utils
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
ConstraintsUtils
.
getConstraintInstanceContainer
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.eclipse.emf.common.util.EList
;
import
org.fortiss.tooling.base.model.element.ConstraintConfiguration
;
import
org.fortiss.tooling.base.model.element.ElementFactory
;
import
org.fortiss.tooling.base.model.element.IConstraintBasedProcess
;
import
org.fortiss.tooling.kernel.extension.IConstraint
;
import
org.fortiss.tooling.kernel.extension.data.ITopLevelElement
;
import
org.fortiss.tooling.kernel.model.constraints.ConstrainedWithChecksum
;
import
org.fortiss.tooling.kernel.model.constraints.ConstraintInstance
;
import
org.fortiss.tooling.kernel.model.constraints.IConstrained
;
import
org.fortiss.tooling.kernel.model.constraints.IConstraintInstanceContainer
;
import
org.fortiss.tooling.kernel.service.IConstraintService
;
import
org.fortiss.tooling.kernel.service.IPersistencyService
;
/**
* Utils for constraints.
*
* @author aravantinos
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 0BAF506EABCAAB4A23F2DF8E2F4EBEA4
*/
public
class
ConstraintsBaseUtils
{
/** Name of the default configuration. */
public
static
final
String
DEFAULT_CONFIGURATION_NAME
=
"Default configuration"
;
/** Removes constraints on <code>c</code> from <code>container</code>. */
public
static
void
removeFromConstraintInstanceContainer
(
IConstrained
c
)
{
EList
<
ConstraintInstance
>
toRemove
=
c
.
getConstraintInstances
();
if
(
toRemove
.
isEmpty
())
{
// Then there is nothing to do
return
;
}
// get(0) because we just checked that the list is not empty, and because the assumption is
// made that the constraint instance container is the same for all the instances in the
// list.
IConstraintInstanceContainer
container
=
getConstraintInstanceContainer
(
toRemove
.
get
(
0
));
container
.
getConstraintInstances
().
removeAll
(
toRemove
);
for
(
ConstraintInstance
constraint
:
toRemove
)
{
for
(
ConstrainedWithChecksum
constrained
:
constraint
.
getConstrainedsWithChecksum
())
{
// c needs to be treated separately to avoid concurrent modifications
if
(
constrained
.
getConstrained
()
!=
null
&&
!
constrained
.
getConstrained
().
equals
(
c
))
{
constrained
.
getConstrained
().
getConstraintInstances
().
remove
(
constraint
);
}
}
}
c
.
getConstraintInstances
().
clear
();
}
/**
* Removes the constraint instance from its container. Also removes it from its constrained
* elements.
*/
public
static
void
removeFromConstraintInstanceContainer
(
ConstraintInstance
ci
)
{
IConstraintInstanceContainer
container
=
getConstraintInstanceContainer
(
ci
);
if
(
container
!=
null
)
{
container
.
getConstraintInstances
().
remove
(
ci
);
}
for
(
ConstrainedWithChecksum
cwc
:
ci
.
getConstrainedsWithChecksum
())
{
cwc
.
getConstrained
().
getConstraintInstances
().
remove
(
ci
);
}
}
/**
* If <code>config</code> is not already in <code>configList</code>, adds it and its included
* configurations.
*
* <code>exception</code> allows to avoid considering one particular configuration.
* Leave <code>null</code> if irrelevant.
*/
public
static
void
addConfigurationTransitively
(
List
<
ConstraintConfiguration
>
configList
,
ConstraintConfiguration
config
,
ConstraintConfiguration
exception
)
{
if
(!
configList
.
contains
(
config
)
&&
!
config
.
equals
(
exception
))
{
configList
.
add
(
config
);
for
(
ConstraintConfiguration
subConfig
:
config
.
getIncludedConfigurations
())
{
addConfigurationTransitively
(
configList
,
subConfig
,
exception
);
}
}
}
/**
* Returns all the configurations included in <code>config</code> transitively, including
* <code>config</code> itself.
*
* <code>exception</code> allows to avoid considering one particular configuration.
* Leave <code>null</code> if irrelevant.
*/
public
static
List
<
ConstraintConfiguration
>
getActiveConfigurationsTransitively
(
ConstraintConfiguration
config
,
ConstraintConfiguration
exception
)
{
List
<
ConstraintConfiguration
>
res
=
new
ArrayList
<>();
addConfigurationTransitively
(
res
,
config
,
exception
);
return
res
;
}
/**
* Returns the names of all the constraints active in the given configuration.
*
* <code>exception</code> allows to avoid considering one particular configuration.
* Leave <code>null</code> if irrelevant.
*/
public
static
List
<
String
>
getActiveConstraintNamesTransitively
(
ConstraintConfiguration
config
,
ConstraintConfiguration
exception
)
{
List
<
ConstraintConfiguration
>
configs
=
getActiveConfigurationsTransitively
(
config
,
exception
);
List
<
String
>
res
=
new
ArrayList
<>();
for
(
ConstraintConfiguration
subConfig
:
configs
)
{
res
.
addAll
(
subConfig
.
getActiveConstraints
());
}
return
res
;
}
/**
* Returns all the constraints active in the given configuration.
*
* <code>exception</code> allows to avoid considering one particular configuration.
* Leave <code>null</code> if irrelevant.
*/
public
static
List
<
Class
<?
extends
IConstraint
>>
getActiveConstraintsTransitively
(
ConstraintConfiguration
config
,
ConstraintConfiguration
exception
)
{
List
<
String
>
names
=
getActiveConstraintNamesTransitively
(
config
,
exception
);
List
<
Class
<?
extends
IConstraint
>>
res
=
new
ArrayList
<>();
for
(
String
name
:
names
)
{
res
.
add
(
IConstraintService
.
getInstance
().
getConstraintByName
(
name
));
}
return
res
;
}
/** True if the given configuration is the default one. */
public
static
boolean
isDefaultConfiguration
(
ConstraintConfiguration
c
)
{
return
c
.
getName
().
equals
(
DEFAULT_CONFIGURATION_NAME
);
}
/** Gets the default configuration of the given constraint-based development process. */
public
static
ConstraintConfiguration
getDefaultConfig
(
IConstraintBasedProcess
cbp
)
{
EList
<
ConstraintConfiguration
>
configs
=
cbp
.
getConfigurations
();
for
(
ConstraintConfiguration
config
:
configs
)
{
if
(
isDefaultConfiguration
(
config
))
{
return
config
;
}
}
return
null
;
}
/** Adds a default configuration to the given process and returns it for information. */
public
static
ConstraintConfiguration
addDefaultConfig
(
IConstraintBasedProcess
cbp
)
{
ConstraintConfiguration
newDefaultConfig
=
ElementFactory
.
eINSTANCE
.
createConstraintConfiguration
();
newDefaultConfig
.
setName
(
DEFAULT_CONFIGURATION_NAME
);
cbp
.
getConfigurations
().
add
(
newDefaultConfig
);
return
newDefaultConfig
;
}
/** Gets the default configuration if existing, or creates one otherwise. */
public
static
ConstraintConfiguration
retrieveDefaultConfig
(
IConstraintBasedProcess
cbp
)
{
ConstraintConfiguration
defaultConfig
=
getDefaultConfig
(
cbp
);
if
(
defaultConfig
!=
null
)
{
return
defaultConfig
;
}
ITopLevelElement
top
=
IPersistencyService
.
getInstance
().
getTopLevelElementFor
(
cbp
);
top
.
runAsCommand
(()
->
addDefaultConfig
(
cbp
));
return
getDefaultConfig
(
cbp
);
}
/** Initializes a {@link IConstraintBasedProcess}. Needs a {@link IConstraintInstanceContainer}. */
public
static
void
initializeConstraintBasedProcess
(
IConstraintBasedProcess
cbp
,
IConstraintInstanceContainer
cic
)
{
ConstraintConfiguration
defaultConfig
=
addDefaultConfig
(
cbp
);
cbp
.
setCurrentObjective
(
defaultConfig
);
cbp
.
setConstraintInstanceContainer
(
cic
);
}
}
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