File tree 14 files changed +173
-24
lines changed
main/java/ch/digitalfondue/jfiveparse
test/java/ch/digitalfondue/jfiveparse
14 files changed +173
-24
lines changed Original file line number Diff line number Diff line change 15
15
distribution : ' corretto'
16
16
- name : Publish package
17
17
env :
18
- JRELEASER_NEXUS2_USERNAME : ${{ secrets.TOKEN_JRELEASER_NEXUS2_USERNAME }}
19
- JRELEASER_NEXUS2_TOKEN : ${{ secrets.TOKEN_JRELEASER_NEXUS2_TOKEN }}
18
+ JRELEASER_NEXUS2_USERNAME : ${{ secrets.TOKEN_JRELEASER_SONATYPE_USERNAME }}
19
+ JRELEASER_NEXUS2_TOKEN : ${{ secrets.TOKEN_JRELEASER_SONATYPE_TOKEN }}
20
20
JRELEASER_GPG_PASSPHRASE : ${{ secrets.JRELEASER_GPG_PASSPHRASE }}
21
21
JRELEASER_GPG_SECRET_KEY : ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
22
22
JRELEASER_GPG_PUBLIC_KEY : ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
Original file line number Diff line number Diff line change 72
72
<dependency >
73
73
<groupId >org.jsoup</groupId >
74
74
<artifactId >jsoup</artifactId >
75
- <version >1.18.3 </version >
75
+ <version >1.19.1 </version >
76
76
<scope >test</scope >
77
77
</dependency >
78
+ <!--
79
+ <dependency>
80
+ <groupId>tools.profiler</groupId>
81
+ <artifactId>async-profiler</artifactId>
82
+ <version>3.0</version>
83
+ <scope>test</scope>
84
+ </dependency>
85
+ -->
78
86
</dependencies >
79
87
80
88
<build >
203
211
</signing >
204
212
<deploy >
205
213
<maven >
206
- <nexus2 >
207
- <maven-central >
214
+ <mavenCentral >
215
+ <sonatype >
208
216
<active >ALWAYS</active >
209
- <url >https://oss.sonatype.org/service/local</url >;
210
- <closeRepository >true</closeRepository >
211
- <releaseRepository >true</releaseRepository >
217
+ <url >https://central.sonatype.com/api/v1/publisher</url >
212
218
<stagingRepositories >target/staging-deploy</stagingRepositories >
213
- </maven-central >
214
- </nexus2 >
219
+ </sonatype >
220
+ </mavenCentral >
215
221
</maven >
216
222
</deploy >
217
223
</jreleaser >
Original file line number Diff line number Diff line change @@ -103,8 +103,7 @@ public boolean equals(Object obj) {
103
103
getValue ().equals (other .getValue ()) && //
104
104
Objects .equals (prefix , other .prefix ) && //
105
105
Objects .equals (namespace , other .namespace );
106
- } else {
107
- return false ;
108
106
}
107
+ return false ;
109
108
}
110
109
}
Original file line number Diff line number Diff line change @@ -43,11 +43,10 @@ public boolean equals(Object obj) {
43
43
return true ;
44
44
}
45
45
46
- if (!( obj instanceof Attributes ) ) {
47
- return false ;
46
+ if (obj instanceof Attributes ) {
47
+ return Objects . equals ( attributes , (( Attributes ) obj ). attributes ) ;
48
48
}
49
-
50
- return Objects .equals (attributes , ((Attributes ) obj ).attributes );
49
+ return false ;
51
50
}
52
51
53
52
public Attributes copy () {
@@ -64,7 +63,7 @@ public AttributeNode get(String key) {
64
63
}
65
64
66
65
Set <String > keySet () {
67
- return attributes == null ? Collections . emptySet () : attributes .keySet ();
66
+ return attributes == null ? Set . of () : attributes .keySet ();
68
67
}
69
68
70
69
private void ensureMap () {
Original file line number Diff line number Diff line change 15
15
*/
16
16
package ch .digitalfondue .jfiveparse ;
17
17
18
+ import java .util .Objects ;
19
+
18
20
/**
19
21
* Represent a comment.
20
22
*/
@@ -61,4 +63,15 @@ public String getNodeName() {
61
63
public Node cloneNode (boolean deep ) {
62
64
return new Comment (getData ());
63
65
}
66
+
67
+ @ Override
68
+ public boolean isEqualNode (Node other ) {
69
+ if (this == other ) {
70
+ return true ;
71
+ }
72
+ if (other instanceof Comment ) {
73
+ return Objects .equals (getData (), ((Comment ) other ).getData ());
74
+ }
75
+ return false ;
76
+ }
64
77
}
Original file line number Diff line number Diff line change @@ -117,4 +117,28 @@ public Node cloneNode(boolean deep) {
117
117
}
118
118
return cloned ;
119
119
}
120
+
121
+ @ Override
122
+ public boolean isEqualNode (Node other ) {
123
+ if (this == other ) {
124
+ return true ;
125
+ }
126
+ if (other instanceof Document ) {
127
+ Document otherDocument = (Document ) other ;
128
+ if (!Node .nodesEquals (doctype , otherDocument .doctype )) {
129
+ return false ;
130
+ }
131
+ int count = getChildCount ();
132
+ if (count != otherDocument .getChildCount ()) {
133
+ return false ;
134
+ }
135
+ for (var i = 0 ; i < count ; i ++) {
136
+ if (!Node .nodesEquals (childNodes .get (i ), otherDocument .childNodes .get (i ))) {
137
+ return false ;
138
+ }
139
+ }
140
+ return true ;
141
+ }
142
+ return false ;
143
+ }
120
144
}
Original file line number Diff line number Diff line change 15
15
*/
16
16
package ch .digitalfondue .jfiveparse ;
17
17
18
+ import java .util .Objects ;
19
+
18
20
/**
19
21
* Represent a document type.
20
22
*/
@@ -59,4 +61,18 @@ public String getNodeName() {
59
61
public Node cloneNode (boolean deep ) {
60
62
return new DocumentType (getName (), getPublicId (), getSystemId ());
61
63
}
64
+
65
+ @ Override
66
+ public boolean isEqualNode (Node other ) {
67
+ if (this == other ) {
68
+ return true ;
69
+ }
70
+ if (other instanceof DocumentType ) {
71
+ DocumentType otherDocType = (DocumentType ) other ;
72
+ return Objects .equals (name , otherDocType .name ) &&
73
+ Objects .equals (publicId , otherDocType .publicId ) &&
74
+ Objects .equals (systemId , otherDocType .systemId );
75
+ }
76
+ return false ;
77
+ }
62
78
}
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ private void ensureAttributesPresence() {
87
87
*/
88
88
@ Override
89
89
public List <Node > getChildNodes () {
90
- return childNodes == null ? Collections . emptyList () : Collections .unmodifiableList (childNodes );
90
+ return childNodes == null ? List . of () : Collections .unmodifiableList (childNodes );
91
91
}
92
92
93
93
@ Override
@@ -343,6 +343,33 @@ public Node cloneNode(boolean deep) {
343
343
return clone ;
344
344
}
345
345
346
+ @ Override
347
+ public boolean isEqualNode (Node other ) {
348
+ if (this == other ) {
349
+ return true ;
350
+ }
351
+ if (other instanceof Element ) {
352
+ Element otherElement = (Element ) other ;
353
+ var count = getChildCount ();
354
+ var equalityCheck = Objects .equals (getNodeName (), otherElement .getNodeName ()) &&
355
+ Objects .equals (getNamespaceURI (), otherElement .getNamespaceURI ()) &&
356
+ Objects .equals (count , otherElement .getChildCount ()) &&
357
+ Objects .equals (getAttributes (), otherElement .getAttributes ());
358
+
359
+ if (!equalityCheck ) {
360
+ return false ;
361
+ }
362
+
363
+ for (var i = 0 ; i < count ; i ++) {
364
+ if (!Node .nodesEquals (childNodes .get (i ), otherElement .childNodes .get (i ))) {
365
+ return false ;
366
+ }
367
+ }
368
+ return true ;
369
+ }
370
+ return false ;
371
+ }
372
+
346
373
/**
347
374
* Get the html content of the child of this node.
348
375
*/
Original file line number Diff line number Diff line change 22
22
*/
23
23
public abstract class Node {
24
24
25
- private static final List <Node > EMPTY_LIST = Collections . emptyList ();
25
+ private static final List <Node > EMPTY_LIST = List . of ();
26
26
27
27
Node parentNode ;
28
28
@@ -547,6 +547,30 @@ public boolean isSameNode(Node other) {
547
547
*/
548
548
public abstract Node cloneNode (boolean deep );
549
549
550
+ /**
551
+ * Check if the node is equal to the parameter.
552
+ *
553
+ * See <a href="https://dom.spec.whatwg.org/#concept-node-equals">...</a>
554
+ *
555
+ * @param other
556
+ * @return
557
+ */
558
+ public abstract boolean isEqualNode (Node other );
559
+
560
+ /**
561
+ * Null safe static isEqualNode helper
562
+ *
563
+ * @param a
564
+ * @param b
565
+ * @return
566
+ */
567
+ static boolean nodesEquals (Node a , Node b ) {
568
+ if (a != null && b != null ) {
569
+ return a .isEqualNode (b );
570
+ } else {
571
+ return a == null && b == null ;
572
+ }
573
+ }
550
574
551
575
private void replaceTextNodeWith (Node text , StringBuilder concatenatedText ) {
552
576
if (concatenatedText .length () == 0 ) {
Original file line number Diff line number Diff line change 15
15
*/
16
16
package ch .digitalfondue .jfiveparse ;
17
17
18
+ import java .util .Objects ;
19
+
18
20
/**
19
21
* Represent a text node.
20
22
*/
@@ -65,4 +67,15 @@ public String getNodeName() {
65
67
public Node cloneNode (boolean deep ) {
66
68
return new Text (getData ());
67
69
}
70
+
71
+ @ Override
72
+ public boolean isEqualNode (Node other ) {
73
+ if (this == other ) {
74
+ return true ;
75
+ }
76
+ if (other instanceof Text ) {
77
+ return Objects .equals (getData (), ((Text ) other ).getData ());
78
+ }
79
+ return false ;
80
+ }
68
81
}
Original file line number Diff line number Diff line change 1
1
package ch .digitalfondue .jfiveparse ;
2
2
3
+ //import one.profiler.AsyncProfiler;
4
+
3
5
import java .io .IOException ;
4
6
import java .nio .charset .StandardCharsets ;
5
7
import java .nio .file .Files ;
@@ -10,12 +12,17 @@ public class CheckRead {
10
12
// test class for gathering profiling stats & co...
11
13
public static void main (String [] args ) throws IOException {
12
14
var content = Files .readString (Path .of ("src/test/resources/wikipedia.html" ), StandardCharsets .UTF_8 );
13
-
15
+ //AsyncProfiler profiler = AsyncProfiler.getInstance();
16
+ //profiler.execute("start,event=cpu,file=test.html");
17
+ var start = System .currentTimeMillis ();
14
18
for (int i = 0 ; i < 100_000 ; i ++) {
15
19
Document doc = JFiveParse .parse (content );
16
20
17
21
Element e = doc .getElementById ("mp-dyk-h2" );
18
22
String c = e .getOuterHTML ();
19
23
}
24
+ var end = System .currentTimeMillis ();
25
+ //profiler.execute("stop");
26
+ System .out .println ("total :" + ((end - start ) / 1000.0 ) + "s" );
20
27
}
21
28
}
Original file line number Diff line number Diff line change @@ -280,4 +280,26 @@ void sameNode() {
280
280
assertTrue (b .isSameNode (b ));
281
281
}
282
282
283
+
284
+ private static boolean areFragmentEquals (String a , String b ) {
285
+ return JFiveParse .parseFragment (a ).get (0 ).isEqualNode (JFiveParse .parseFragment (b ).get (0 ));
286
+ }
287
+
288
+ @ Test
289
+ void isEqualNodeCheck () {
290
+ assertTrue (areFragmentEquals ("<p>a</p>" , "<p>a</p>" ));
291
+ assertTrue (areFragmentEquals ("<p id=test>a</p>" , "<p id='test'>a</p>" ));
292
+ assertTrue (areFragmentEquals ("<p id=test>a<!-- comment --></p>" , "<p id='test'>a<!-- comment --></p>" ));
293
+ assertTrue (areFragmentEquals ("<p><span><span><span>b</span></span></span></p>" , "<p><span><span><span>b</span></span></span></p>" ));
294
+
295
+ assertFalse (areFragmentEquals ("<p>a</p>" , "<li>a</li>" ));
296
+ assertFalse (areFragmentEquals ("<p>a</p>" , "<p>b</p>" ));
297
+ assertFalse (areFragmentEquals ("<p id=testa>a</p>" , "<p id='testb'>a</p>" ));
298
+ assertFalse (areFragmentEquals ("<p id=test>a<!-- comment --></p>" , "<p id='test'>a<!-- commentb --></p>" ));
299
+ assertFalse (areFragmentEquals ("<p><span><span><span>b</span></span></span></p>" , "<p><span><span><span>c</span></span></span></p>" ));
300
+
301
+
302
+ assertTrue (JFiveParse .parse ("<html><body>hello</body></html>" ).isEqualNode (JFiveParse .parse ("<html><body>hello</body></html>" )));
303
+ assertFalse (JFiveParse .parse ("<!DOCTYPE html><html><body>hello</body></html>" ).isEqualNode (JFiveParse .parse ("<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN\" \" http://www.w3.org/TR/html4/loose.dtd\" >\n <html><body>hello</body></html>" )));
304
+ }
283
305
}
Original file line number Diff line number Diff line change 5
5
import static org .junit .jupiter .api .Assertions .assertEquals ;
6
6
7
7
8
- class Resizable {
8
+ class ResizableTest {
9
9
10
10
@ Test
11
11
void checkTest () {
Original file line number Diff line number Diff line change 7
7
import java .io .IOException ;
8
8
9
9
import static org .junit .jupiter .api .Assertions .assertEquals ;
10
- import java .nio .charset .StandardCharsets ;
11
10
import java .nio .file .Files ;
12
11
import java .nio .file .Paths ;
13
12
@@ -19,11 +18,12 @@ public class TestParsePerf {
19
18
20
19
@ BeforeEach
21
20
void load () throws IOException {
22
- file = new String ( Files .readAllBytes (Paths .get ("src/test/resources/test.html" )), StandardCharsets . UTF_8 );
21
+ file = Files .readString (Paths .get ("src/test/resources/test.html" ));
23
22
}
24
23
25
24
int round = 20_000_000 ;
26
25
26
+ @ Disabled
27
27
@ Test
28
28
void check () {
29
29
assertEquals (91 , parser .parse (file ).getAllNodesMatching (Selector .select ().element ("div" ).toMatcher ()).size ());
@@ -35,7 +35,6 @@ void check() {
35
35
@ Disabled
36
36
@ Test
37
37
public void parse () {
38
-
39
38
long start = System .nanoTime ();
40
39
for (int i = 0 ; i < round ; i ++) {
41
40
parser .parse (file );
You can’t perform that action at this time.
0 commit comments