PlantUML: Unexpected result with "Arrows from/to class members" - uml

I'm trying to do something similar to this:
The only differences I have with my code are my classes are formatted with a dot, like auth.Permission:
#startuml
class auth.Permission {
+ id
+ content_type
+ codename
}
class auth.Group {
+ id
+ name
+ permissions
}
auth.Group::permissions -- auth.Permission
#enduml
As you can see, the end result is wrong: a third class is created instead of drawing the relation at the right place: https://www.plantuml.com/plantuml/uml/SoWkIImgAStDuKhEIImkLaWiBSdG2qWjoiqiBixCprEevj9Mo4m14idvUIMfUINn9PK5gM1kIcfUOcugLoqN5x9MzwByqWA4Bf0I85K0Dx0Of06XqieAIKf1LnVTVYw7rBmKeEi0
What I'm doing wrong?
Thanks.

A bit long for a comment, but how about:
#startuml
package auth {
class Permission {
+ id
+ content_type
+ codename
}
class Group {
+ id
+ name
+ permissions
}
Group::permissions -- Permission
}
#enduml
giving:

Related

how to check which constraints would be violated by a presumed solution?

In some cases the solver fails to find a solution for my model, which I think is there.
So I would like to populate a solution, and then check which constraint is violated.
How to do that with choco-solver?
Using choco-solver 4.10.6.
Forcing a solution
I ended up adding constraints to force variables to values of my presumed solution:
e.g.
// constraints to force given solution
vehicle2FirstStop[0].eq(model.intVar(4)).post();
vehicle2FirstStop[1].eq(model.intVar(3)).post();
nextStop[1].eq(model.intVar(0)).post();
nextStop[2].eq(model.intVar(1)).post();
...
and then
model.getSolver().showContradiction();
if (model.getSolver().solve()) { ....
Shows the first contradiction of the presumed solution, e.g.
/!\ CONTRADICTION (PropXplusYeqZ(sum_exp_49, mul_exp_51, ...
So the next step is to find out where terms such as sum_exp_49 come from.
Matching the contradiction terms with the code
Here is a simple fix for constraints which will hopefully provide enough information. We can override the post() and associates() methods of model, so that it dumps the java source filename and line number when a constraint is posted/variable is created.
Model model = new Model("Vrp1RpV") {
/**
* retrieve the filename and line number of first caller outside of choco-solver from stacktrace
*/
String getSource() {
String source = null;
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
// starts from 3: thread.getStackTrace() + this.getSource() + caller (post() or associates())
for (int i = 3; i < stackTraceElements.length; i++) {
// keep rewinding until we get out of choco-solver packages
if (!stackTraceElements[i].getClassName().toString().startsWith("org.chocosolver")) {
source = stackTraceElements[i].getFileName() + ":" + stackTraceElements[i].getLineNumber();
break;
}
}
return source;
}
#Override
public void post(Constraint... cs) throws SolverException {
String source=getSource();
// dump each constraint along source location
for (Constraint c : cs) {
System.err.println(source + " post: " + c);
}
super.post(cs);
}
#Override
public void associates(Variable variable) {
System.err.println(getSource() + " associates: " + variable.getName());
super.associates(variable);
}
};
This will dump things like:
Vrp1RpV2.java:182 post: ARITHM ([prop(EQ_exp_47.EQ.mul_exp_48)])
Vrp1RpV2.java:182 associates: sum_exp_49
Vrp1RpV2.java:182 post: ARITHM ([prop(mul_exp_48.EQ.sum_exp_49)])
Vrp1RpV2.java:182 associates: EQ_exp_50
Vrp1RpV2.java:182 post: BASIC_REIF ([(stop2vehicle[2] = 1) <=> EQ_exp_50])
...
From there it is possible to see where sum_exp_49 comes from.
EDIT: added associates() thanks to #cprudhom suggestion on https://gitter.im/chocoteam/choco-solver

changing / selecting a value in a dropdown box .. using Geb

As a Geb Newb, this is confusing. In attempting to click on a combo/dropdown box, I'm getting the following error:
"geb.error.RequiredPageContentNotPresent: The required page content 'pages.ecomm.NewEnrollmentPage -> countrySelected: geb.module.Select' is not present"
1. page looks like this
2. here is my source:
3. test spec code, for selecting dropdown. Error appears to indicate the 'countrySelected' content/element isn't on the page? Or I'm not even on the page?
NewEnrollmentPage.groovy
import geb.Page
import geb.module.Select
class NewEnrollmentPage extends Page {
static url = "/shop/spring/enrollment/start/78867?tagCountry=AN&customerType=D&tagLang=ENU&__checkbox_isPC=true&UNI_TODAY=true&__checkbox_UNI_TODAY=true&clearSession=1"
// "/shop/spring/enrollment/product/landing"
// below for mwebs (non-prod) --->v
//At Checker
static at = {
title == "Enrollment"
}
static content = {
// <navigatorName ><options map> <actual navigator>
CrInitOrdButton(wait: true) { driver.findElement(By.id($("[id='toProductsPage']"))) }
countrySelected { $("#countrySelected").module(Select) }
//Options Map
/* wait : true
* required : false
*
*
*
*/
}
}
test.groovy
class test extends smoke.ecomm.resource.ShopBootStrap {
def "Select Country"() {
given:
at NewEnrollmentPage
when: "select United States for Country"
**countrySelected.value('US')**
.
.
.
}
}
Your selector is incorrect. You are selecting using id of countrySelected but that's the name of your element and its id is actually countries. So you need to change your content definition to either:
countrySelected { $("#countries").module(Select) }
or
countrySelected { $(name: "countrySelected").module(Select) }

Processing 'Search' in an Arraylist

I'm stuck with the following problem within Processing for a school assignment.
I'm using a dataset in a tab seperated format, This is being read and parsed to my Activity class. The (menuAnswer, "Subagency") is used so I only get the data I need.
for(TableRow singleRow : trafficTable.findRows(menuAnswer, "SubAgency")){
Activity singleActivity = new Activity();
singleActivity.parseRow(singleRow);
activities.add(singleActivity);
}
The Activity class looks this:
class Activity{
String violationType;
String subAgency;
String race;
String gender;
Date readDate;
void parseRow(TableRow row){
this.subAgency = row.getString("SubAgency");
this.violationType = row.getString("Violation Type");
this.race = row.getString("Race");
this.gender = row.getString("Gender");
this.readDate = parseDate(row.getString("Time Of Stop") + " " + row.getString("Date"), "HH:mm:ss dd-MM-yyyy");
}
void printInfo(){
println(subAgency + " / " + race + " / " + readDate + " / " + violationType);
}
}
Every (usefull) piece of my dataset is inserted into an variable.
In my main class I want to search in the violationType String and count the ammount of "Warning"s within this String. I use the following code, which is not working:
for (Activity singleActivity : activities)
if(singleActivity.violationType == "Warning"){
warningCount++;
println("is it working?");
}
What am I doing wrong?
Mello
After searching I found my answer:
for (Activity singleActivity : activities)
if(singleActivity.violationType == "Warning"){
warningCount++;
println("is it working?");
}
My notation of my If statement is wrong and should be with .equals instead of == operator, like this:
void countWarning(){
for (Activity singleActivity : activities){
if(singleActivity.violationType.equals("Warning")){
warningCount++;
}
}
}

How to compose variable name dynamically?

I need to generate a list,and name it's items based on for-loop index
number, like this:
for(int i=0;i<someNumber;i++){
Model m_{$i}=Mock() //but this doesn't work
......
models.add(i,m_{$i})
}
then they can be distinguished by name when debugging test code(shame to tell this) within eclipse,but it doesn't work, so how to make it work?
update:add image to tell why I want to append for-loop index to variable name
You can also add some property to your Mock class at runtime thanks to Groovy's MetaClass. Take a look at this sample snippet:
class myClass {
String someProperty
}
def models = []
10.times { it ->
def instance = new myClass(someProperty: "something")
instance.metaClass.testId = it
models.add(instance)
}
// delete some
println "Removing object with testId = " + models.remove(4).testId
println "Removing object with testId = " + models.remove(7).testId
def identifiersOfObjectsAfterRemoves = models.collect { it.testId }
def removedObjectsIdentifiers = (0..9) - identifiersOfObjectsAfterRemoves
println "Identifiers of removed objects: " + removedObjectsIdentifiers

Using label control inside foreach loop to display multiple value in a single label

//program.cs
foreach (Mutant mutant in mutants)
{
label12.Text=mutant.displayInfo();
}
//Mutant.cs
public abstract int dangerQuotient();
public String displayInfo()
{
return(codename + " " + dangerQuotient().ToString());
}
//physicalMutant.cs
public override int dangerQuotient()
{
return level * IQ * strength;
}
//elementMutant.cs
public override int dangerQuotient()
{
return level * region;
}
Mutant is my base class and I have two derived classes physicalMutant and elementMutant. At final I'm getting the output for elementMutant class alone in label12. How to get output of physicalMutant too in the same label.
By using message box control inside foreach loop i can get values from the displayQuotient() in both derived classes but by using label i can able to display only the last iteration value.How to overcome this problem?
I am really not sure what you are wanting, but if it is to add all of your Mutants dangerQuotient to your label you will need to change your foreach statement to something like this. You are currently replacing the label's contents every iteration of your foreach loop.
label12.Text = ""; // or just delete the text in the designer
foreach(Mutant mutant in mutants)
{
label12.Text += mutant.displayInfo() + "\n"; // This will create a seperate line for each displayInfo
// label12.Text += mutant.displayInfo(); //This will add them on the same line
}

Resources