Skip to content

Instantly share code, notes, and snippets.

@stefjoosten
Created December 29, 2020 09:19
Show Gist options
  • Save stefjoosten/cd14441f09e5f625d7320f76def3bf55 to your computer and use it in GitHub Desktop.
Save stefjoosten/cd14441f09e5f625d7320f76def3bf55 to your computer and use it in GitHub Desktop.
This jArchi-script shows which Archi-elements in a model share the same type and name.
/* Show duplication.ajs
* Situation: Archi can make an element show up in different views. The relationships to and from that element in all these views are attached to the same element.
* Problem: If I accidentally make a copy of an element (e.g. by copying a view from one model to another), multiple elements may arise that have the same type and name.
* Such copies do not share relations, which violates an important benefit of Archi.
* Solution: This Archi-script signals the situation, so you can fix it if you want.
* (c) 2020 by Stef Joosten
*/
var debug = true;
debug ? console.show():true;
debug ? console.clear():true;
console.log("Show all elements that share type and name:");
// Every element that has duplicates is registered in the list 'registeredAsDuplicate'
// to avoid reporting them multiply.
var registeredAsDuplicate = $("#null");
$("element").each(function(elem0) {
// check if the element has not been registered already as duplicate.
if( ! registeredAsDuplicate.contains(elem0) ) {
// Find the duplicates of elem0 and store them in the list 'duplicates'.
var duplicates = $("#null");
$("element").each(function(elem1) {
if (equiv(elem0,elem1) && elem0.id!=elem1.id) {
duplicates.add(elem1);
}
});
// Report elem0 and all of its duplicates and register all as duplicates.
if (duplicates.size()>0) {
console.log ("\nType/Name combination <"+elem0.type+","+elem0.name+"> is used by these elements:" );
console.log (" - "+elem0.id );
registeredAsDuplicate.add(elem0);
duplicates.each(function(elem1) {
console.log (" - "+elem1.id );
registeredAsDuplicate.add(elem1);
})
}
}
});
// The equivalence of elements is abstracted as a function,
// so this will work for other equivalences as well.
function equiv(elem0,elem1) {
return elem0.type === elem1.type && elem0.name === elem1.name
}
if (registeredAsDuplicate.size()>1)
console.log("\nThere are, " + registeredAsDuplicate.size() + " name/type combinations that do not benefit from sharing relationships across views.");
else if (registeredAsDuplicate.size()==1)
console.log("\nThere is one name/type combination that does not benefit from sharing relationships across views.");
else
console.log("\nAll elements in this model have a unique name/type combination, so they benefit fully from sharing relationships across views.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment