I'm placing this under bugs because I cannot find any problem; but it could be a mistake on my part. Here are the details:
Java version: OpenJDK 19.0.2
Command line:
$ java -jar plantuml.jar -verbose ./practice/codewars/justify.puml
(0.002 - 64 Mo) 58 Mo - SecurityProfile LEGACY
(0.009 - 64 Mo) 58 Mo - PlantUML Version 1.2023.1
(0.009 - 64 Mo) 58 Mo - GraphicsEnvironment.isHeadless() false
(0.010 - 64 Mo) 58 Mo - Forcing resource load on OpenJdk
(0.175 - 64 Mo) 58 Mo - Found 0 files
No diagram found
BTW I think the PlantUML version I'm running is 1.2023.2 since plantuml.jar is the same size as plantuml-1.2023.2.jar, so that's the jar I'm using.
$ java -jar plantuml.jar -version
PlantUML version 1.2023.1 (Sun Jan 29 08:58:56 AST 2023)
(GPL source distribution)
Java Runtime: OpenJDK Runtime Environment
JVM: OpenJDK 64-Bit Server VM
Default Encoding: Cp1252
Language: en
Country: US
PLANTUML_LIMIT_SIZE: 4096
Dot version: dot - graphviz version 2.44.1 (20200629.0846)
Installation seems OK. File generation OK
File contents:
@startuml justify_classes
title Justify Classes
class JustifiedLine {
-words: array<string>
-word_count: integer
-char_count: integer
-min_needed_spaces: integer
-num_gaps_to_increment: integer
---
+construct(word_arr)
+toString(): string
.. Getters ..
+getWords(): array<string>
+getWordCount(): integer
+getCharCount(): integer
+getMinNeededSpaces(): integer
+getNumGapsToIncrement(): integer
.. Setters ..
+setWords(array<string>): JustifiedLine
+setWordCount(integer): JustifiedLine
+setCharCount(integer): JustifiedLine
+setMinNeededSpaces(integer): JustifiedLine
+setNumGapsToIncrement(integer): JustifiedLine
}
note top of JustifiedLine
Contains an array of a single line of text
to justify plus associated methods.
end note
class JustifiedText {
-original_string:string
-target_width:integer
---
+construct(str:string, len:integer)
-explode(inout initial_index:integer): array
-add(word_arr:array<string>): void
+render(): string
.. Getters ..
+getOriginalString(): string
+getTargetWidth(): integer
+getLineList(): array[JustifiedLine]
.. Setters ..
+setOriginalString(string): JustifiedText
+setTargetWidth(integer): JustifiedText
+setLineList(array[JustifiedLine]): JustifiedText
}
note top of JustifiedText
Contains an array of objects of
JustifiedLine class.
end note
JustifiedText "1" o-- "+" JustifiedLine : line_list >
note right of JustifiedText::render()
returns the string result of the justified text.
end note
note right of JustifiedLine::num_gaps_to_increment
number of gaps to sum one to its needed spaces
end note
note right of JustifiedLine::char_count
total characters in the word array,
does not include spaces
end note
@enduml
@startuml justify_justified_text_class_constructor
title JustifiedText Class Constructor
partition "**__method__** JustifiedText::construct(//__str__//:string, //__len__//:integer)" {
:**parameters**
//__str__//
//__len__// ]
://**this**.setOriginalString(__str__)//;
://**this**.setTargetWidth(__len__)//;
://**this**.setLineList(empty)//;
:initialize //index// to zero;
while (//index//) is (not **null**)
:**this**.add(**this**.explode(//index//));
note
modifies //index// to the beginning
of the next line of text.
sets //index// to **null** to signal
the end of the string.
end note
endwhile
stop
}
@enduml
@startuml justify_justified_text_explode_method
title JustifiedText Class explode Method
partition "__**method**__ JustifiedText::explode(inout //__index__//:integer): array"
:**parameter**
//__index__// ]
if (length of //**this**.getOriginalString()//) is (less than //__index__ + **this**.getTargetWidth()-1//) then
:set //length// to //__index__+**this**.getTargetWidth()//
//-len(**this**.getOriginalString())//;
else (otherwise)
:set //length// to //**this**.getTargetWidth()//;
endif
while (original_text[__index__+length]) is (not space)
:loop decrementing the length until
the text length points to a space;
endwhile
:extract the string starting at //__index__// and through
the decremented length minus one;
:set //__index__// to //__index__ + length + 1//;
:explode the extracted string
and return the resulting array;
stop
@enduml
@startuml justify_justified_text_add_method
title JustifiedText Class add Method
partition "__**method**__ JustifiedText::add(//__word_arr__//:array<string>):JustifiedText"
:**parameter**
//__word_arr__// ]
:line_item = new JustifiedLine(//__word_arr__//);
:call //line_item.setWordCount(__word_arr__ size)//;
floating note
wi: target width
c: total characters w/o gaps
wo: total words
wo-1: word gaps
wi-c: spaces needed between words
(wi-c)/(wo-1): last gap spaces
(wi-c)%(wo-1): gaps to increment
end note
:sum the amount of characters of all
the words in //__word_arr__// and call
//line_item.setCharCount(the sum)//;
if (//(**this**.getTargetWidth()//) is (1) then
:call //line_item.setMinNeededSpaces(0);
:call //line_item.setNumGapsToIncrement(0);
else (otherwise)
:call //line_item.setMinNeededSpaces(//
//(**this**.getTargetWidth()//
//-line_item.getCharCount())//
// /(line_item.getWordCount()-1))//;
:call //line_item.setNumGapsToIncrement((**this**.target_width//
//-line_item.getCharCount())//
// **mod** (line_item.getWordCount()-1))//;
endif
:add line_item to line_list;
:return //this//;
stop
@enduml
@startuml justify_justified_text_render_method
title JustifiedText Class render Method
partition __**method**__ JustifiedText::render(): string
start
while (there is still //line_list// items)
:call //toString()// method on each
//line_list// item and append each
result+newline to //result//;
:next line_list item;
if (line_list item) is (last) then
:call //toString(yes)//;
:append string result to //result//;
:next line_list item;
endif
endwhile
:return //result//;
stop
@enduml
@startuml justify_justified_line_tostring_method
title JustifiedLine Class toString Method
partition __**method**__ JustifiedLine::toString(//__last__//=no): string
start
:**parameter**
//__last__// ]
note
The //__last__// parameter indicates
whether or not the string to
render is the last one.
end note
:initialize //word_count// to //**this**.getWordCount()//;
if (//__last__//?) is (yes) then
:initialize //min_needed_//
//spaces// to one;
:initialize //num_gaps_to_//
//increment// to zero;
else (no)
:initialize //min_needed_spaces//
to //**this**.getMinNeededSpaces()//;
:initialize //num_gaps_to_increment//
to //**this**.getNumGapsToIncrement()//;
endif
:initialize //result// to empty string;
while ()
:append the current word to //result//;
:decrement //word_count//;
if (//word_count//) is (zero) then
break
endif
:append //**this**.getMinNeededSpaces()// spaces to //result//;
if (//num_gaps_to_increment//) is (not zero) then
:append one more space to //result//;
:decrement //num_gaps_to_increment//;
endif
endwhile
:return //result//;
stop
@enduml
@startuml justify_justified_line_constructor
title JustifiedLine Class Constructor
partition __**method**__ JustifiedLine::construct(//__word_arr__//)
start
:call //**this**.setWords(__word_arr__)//;
stop
@enduml
@startuml justify_function
title justify Function
partition //__**function**__// justify(//__str__//, //__len__//)
start
:initialize //justified_text// to
new JustifiedText(//__str__//, //__len__//);
:return //justified_text//.render();
stop
@enduml
***File contents truncated to satisfy text size limits***
Any clue or hint on whatever I'm doing wrong, if any, is much appreciated.