55use PHPJava \Exceptions \ReadOnlyException ;
66use PHPJava \Utilities \BinaryTool ;
77
8- class _Utf8 implements StructureInterface
8+ class _Utf8 implements StructureInterface, FreezableInterface
99{
1010 use \PHPJava \Kernel \Core \BinaryReader;
1111 use \PHPJava \Kernel \Core \ConstantPool;
1212 use \PHPJava \Kernel \Core \DebugTool;
1313
1414 private $ length = 0 ;
1515 private $ string = '' ;
16- private $ isWritable = false ;
16+ private $ isWritable = null ;
17+ private $ isFrozen = false ;
1718
1819 /**
1920 * @var \PHPJava\Packages\java\lang\_String $stringObject
@@ -29,39 +30,46 @@ public function execute(): void
2930 $ this ->stringObject = new \PHPJava \Packages \java \lang \_String ($ this );
3031 }
3132
32- public function getLength ()
33+ public function getLength (): int
3334 {
3435 return $ this ->length ;
3536 }
3637
37- /**
38- * @param bool $enable
39- * @return _Utf8
40- */
4138 public function enableWrite (bool $ enable ): self
4239 {
43- $ this ->isWritable = $ enable ;
40+ if (!$ this ->isFrozen ) {
41+ $ this ->isWritable = $ enable ;
42+ }
4443 return $ this ;
4544 }
4645
47- public function getString ()
46+ public function freeze (): void
47+ {
48+ $ this ->isFrozen = true ;
49+ $ this ->enableWrite (false );
50+ }
51+
52+ public function getString (): string
4853 {
4954 return $ this ->string ;
5055 }
5156
52- public function __toString (): string
57+ public function getStringObject (): \ PHPJava \ Packages \ java \ lang \ _String
5358 {
54- return $ this ->getString () ;
59+ return $ this ->stringObject ;
5560 }
5661
5762 public function setStringObject (\PHPJava \Packages \java \lang \_String $ stringObject ): self
5863 {
59- $ this ->stringObject = $ stringObject ;
64+ if ($ this ->isWritable ) {
65+ $ this ->stringObject = $ stringObject ;
66+ $ this ->freeze ();
67+ }
6068 return $ this ;
6169 }
6270
63- public function getStringObject (): \ PHPJava \ Packages \ java \ lang \ _String
71+ public function __toString (): string
6472 {
65- return $ this ->stringObject ;
73+ return $ this ->getString () ;
6674 }
6775}
0 commit comments