Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Yauhenikapl committed Sep 10, 2024
1 parent b213479 commit 3134131
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,6 @@ public List<String> getSubmodelNames() {
.collect( Collectors.toList() );
}

protected String escapeUrnNamespacePart( String namespacePart ) {
if ( namespacePart.contains( "-" ) ) {
namespacePart = namespacePart.replaceAll( "-", "." );
return namespacePart;
}
if ( namespacePart.matches( AspectModelUrn.NAMESPACE_REGEX_PART ) ) {
return namespacePart;
}
throw new AspectModelGenerationException( "Encountered URI with invalid namespace part: " + namespacePart );
}

private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() {
return Collector.of( ArrayDeque::new, ArrayDeque::addFirst, ( deque1, deque2 ) -> {
deque2.addAll( deque1 );
Expand All @@ -193,13 +182,13 @@ private <T> Collector<T, ArrayDeque<T>, ArrayDeque<T>> reverseOrder() {
private String iriToReversedHostNameNotation( final IRI iri ) {
final URI uri = URI.create( iri.toString().contains( "://" ) ? iri.toString() : "https://" + iri );

String[] hostParts = uri.getHost().split( "\\." );
String[] pathParts = uri.getPath().split( "/" );
final String[] hostParts = uri.getHost().split( "\\." );
final String[] pathParts = uri.getPath().split( "/" );

String reversedHost = String.join( ".", Arrays.stream( hostParts )
final String reversedHost = String.join( ".", Arrays.stream( hostParts )
.collect( reverseOrder() ) );

String path = Arrays.stream( pathParts )
final String path = Arrays.stream( pathParts )
.filter( StringUtils::isNotBlank )
.limit( pathParts.length - 2 )
.collect( Collectors.joining( "." ) );
Expand Down

0 comments on commit 3134131

Please sign in to comment.