-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a way to customise how component descriptions are set; also some…
… tidy-up/renaming.
- Loading branch information
1 parent
becf089
commit 1e2b19c
Showing
22 changed files
with
410 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...onent/src/main/java/com/structurizr/component/description/DefaultDescriptionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.structurizr.component.description; | ||
|
||
import com.structurizr.component.Type; | ||
import com.structurizr.component.naming.NamingStrategy; | ||
|
||
/** | ||
* Uses the type description as-is. | ||
*/ | ||
public class DefaultDescriptionStrategy implements DescriptionStrategy { | ||
|
||
@Override | ||
public String descriptionOf(Type type) { | ||
return type.getDescription(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DefaultDescriptionStrategy{}"; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...zr-component/src/main/java/com/structurizr/component/description/DescriptionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.structurizr.component.description; | ||
|
||
import com.structurizr.component.Type; | ||
|
||
public interface DescriptionStrategy { | ||
|
||
String descriptionOf(Type type); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...src/main/java/com/structurizr/component/description/FirstSentenceDescriptionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.structurizr.component.description; | ||
|
||
import com.structurizr.component.Type; | ||
import com.structurizr.util.StringUtils; | ||
|
||
/** | ||
* Uses the first sentence of the type description, or the description as-is if there are no sentences. | ||
*/ | ||
public class FirstSentenceDescriptionStrategy implements DescriptionStrategy { | ||
|
||
@Override | ||
public String descriptionOf(Type type) { | ||
String description = type.getDescription(); | ||
|
||
int index = description.indexOf('.'); | ||
if (index == -1) { | ||
return description; | ||
} else { | ||
return description.substring(0, index+1); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FirstSentenceDescriptionStrategy{}"; | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ent/src/main/java/com/structurizr/component/description/TruncatedDescriptionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.structurizr.component.description; | ||
|
||
import com.structurizr.component.Type; | ||
import com.structurizr.util.StringUtils; | ||
|
||
/** | ||
* Truncates the type description to the max length, appending "..." when truncated. | ||
*/ | ||
public class TruncatedDescriptionStrategy implements DescriptionStrategy { | ||
|
||
private final int maxLength; | ||
|
||
public TruncatedDescriptionStrategy(int maxLength) { | ||
if (maxLength < 1) { | ||
throw new IllegalArgumentException("Max length must be greater than 0"); | ||
} | ||
|
||
this.maxLength = maxLength; | ||
} | ||
|
||
@Override | ||
public String descriptionOf(Type type) { | ||
String description = type.getDescription(); | ||
|
||
if (StringUtils.isNullOrEmpty(description)) { | ||
return description; | ||
} | ||
|
||
if (description.length() > maxLength) { | ||
return description.substring(0, maxLength) + "..."; | ||
} else { | ||
return description; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TruncatedDescriptionStrategy{" + | ||
"maxLength=" + maxLength + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.