Code Snippets in Java API Documentation (#14792)
This commit is contained in:
parent
6528856bc5
commit
2dc953dcad
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.snippettag;
|
||||
|
||||
/**
|
||||
*
|
||||
* External code snippet showing the loop process in binary search method.
|
||||
* {@snippet class="BinarySearch" region="binary"}
|
||||
*
|
||||
* Time Zone
|
||||
* {@snippet file="application.properties" region="zone"}
|
||||
*
|
||||
*/
|
||||
|
||||
public class GreetingsExternalSnippet {
|
||||
public void helloBinarySearch() {
|
||||
System.out.println("Hi, it's great knowing that binary search uses a loop under the hood");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.baeldung.snippettag;
|
||||
|
||||
|
||||
/**
|
||||
* The code below shows a full highlighted line
|
||||
* {@snippet :
|
||||
* public void helloBaeldung() {
|
||||
* System.out.println("Hello From Team Baeldung"); // @highlight
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* highlighting a substring
|
||||
* {@snippet :
|
||||
* public void helloBaeldung() {
|
||||
* System.out.println("Hello From Team Baeldung"); // @highlight substring="println"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* highlighting texts on multiple lines
|
||||
* {@snippet :
|
||||
* public void helloBaeldung() {
|
||||
* System.out.println("Hello From Team Baeldung"); // @highlight region substring="println"
|
||||
* String country = "USA";
|
||||
* System.out.println("Hello From Team " + country); // @end
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
public class GreetingsHighlightTag {
|
||||
public void helloBaeldung() {
|
||||
System.out.println("Hello From Team Baeldung");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.snippettag;
|
||||
|
||||
/**
|
||||
* The code below shows the content of {@code helloBaeldung()} method
|
||||
* {@snippet :
|
||||
* public void helloBaeldung() {
|
||||
* System.out.println("Hello From Team Baeldung");
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
public class GreetingsInlineSnippet {
|
||||
public void helloBaeldung() {
|
||||
System.out.println("Hello From Team Baeldung");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.snippettag;
|
||||
|
||||
/**
|
||||
*
|
||||
* Using the replace tag
|
||||
* {@snippet :
|
||||
* public void helloBaeldung() {
|
||||
* System.out.println("Hello From Team Baeldung"); // @replace regex='".*"' replacement="..."
|
||||
* }
|
||||
* }
|
||||
* Using the link tag
|
||||
* {@snippet :
|
||||
* public void helloBaeldung() {
|
||||
* System.out.println("Hello From Team Baeldung"); // @link substring="System.out" target="System#out"
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
public class GreetingsReplaceAndLinkTag {
|
||||
public void helloBaeldung() {
|
||||
System.out.println("Hello From Team Baeldung");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
public class BinarySearch {
|
||||
|
||||
public int search(int[] list, int item) {
|
||||
int index = Integer.MAX_VALUE;
|
||||
int low = 0;
|
||||
int high = list.length - 1;
|
||||
// @start region="binary"
|
||||
while (low <= high) {
|
||||
int mid = high - low;
|
||||
int guess = list[mid];
|
||||
if (guess == item) {
|
||||
index = mid;
|
||||
break;
|
||||
} else if (guess > item) {
|
||||
low = mid - 1;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
low++;
|
||||
}
|
||||
// @end region="binary"
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# @start region="zone"
|
||||
local.timezone = GMT+1
|
||||
local.zip = 94123
|
||||
# @end region="zone"
|
Loading…
Reference in New Issue