r/learnjava • u/ADhoom • Feb 19 '19
Mod approved Introducing DocFetcher: the document retrieving bot!
DocFetcher is a bot that retrieves programming language documentation information. Right now, DocFetcher only works with Java 7, 8, and 11 To use DocFetcher simply leave a comment like this:
!DocFetcher <java7or8or11> <class>
The bot will respond with information about the Integer class and a link to the Java 7 documentation about the Integer class. To call the other version just do java7, java8, or java11
In the future, DocFetcher will work with other languages(c++, python, swift, JavaScript) hopefully starting with python. The bot is still in development, for questions and suggestions, please send a message.
2
u/warpedspockclone Feb 19 '19
!DocFetcher java8 optional
6
u/ADhoom Feb 19 '19
sorry I should mention, you have to use the proper class name (capitalize the first letter) so that would Optional
1
u/DocFetcher btproof Feb 19 '19
I was not able to find any information about optional in the oracle documentation.
I am a bot still in development. For questions or suggestions, you can message /u/ADhoom
1
u/IllTryToReadComments Feb 19 '19
Can you add macros so that it can be shorter?
!df j8 Integer
2
2
u/ADhoom Feb 20 '19
!df j8 Integer
1
u/DocFetcher btproof Feb 20 '19
here's what I found about the Integer class:
Java 8
public final class Integer extends Number implements Comparable<Integer>The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int.
In addition, this class provides several methods for converting an int to a String and a String to an int, as well as other constants and methods useful when dealing with an int.
Implementation note: The implementations of the "bit twiddling" methods (such as highestOneBit and numberOfTrailingZeros) are based on material from Henry S. Warren, Jr.'s Hacker's Delight, (Addison Wesley, 2002).
I am a bot still in development. For questions or suggestions, you can message /u/ADhoom
2
1
u/dhawal0008 May 04 '19
!DocFetcher java8 Singleton
1
u/ADhoom May 04 '19
Hey sorry, the bot is down atm, I am currently updating some functionality in it, once it's up again it will reply.
1
u/DocFetcher btproof May 04 '19
I was not able to find any information about Singleton in the oracle documentation.
I am a bot still in development. For questions or suggestions, you can message /u/ADhoom
2
u/warpedspockclone Feb 19 '19
!DocFetcher java8 Optional
4
u/DocFetcher btproof Feb 19 '19
here's what I found about the Optional class:
Java 8
public final class Optional<T> extends ObjectA container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
Additional methods that depend on the presence or absence of a contained value are provided, such as orElse() (return a default value if value not present) and ifPresent() (execute a block of code if the value is present).
This is a value-based class; use of identity-sensitive operations (including reference equality (==), identity hash code, or synchronization) on instances of Optional may have unpredictable results and should be avoided.
I am a bot still in development. For questions or suggestions, you can message /u/ADhoom
1
1
1
1
1
1
1
0
Feb 19 '19
[deleted]
2
u/DocFetcher btproof Feb 19 '19
here's what I found about the Scanner class:
Java 7
public final class Scanner extends Object implements Iterator<String>, CloseableA simple text scanner which can parse primitive types and strings using regular expressions.
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
For example, this code allows a user to read a number from System.in:
Scanner sc = new Scanner(System.in); int i = sc.nextInt();As another example, this code allows long types to be assigned from entries in a file myNumbers:
Scanner sc = new Scanner(new File("myNumbers")); while (sc.hasNextLong()) { long aLong = sc.nextLong(); }The scanner can also use delimiters other than whitespace. This example reads several items in from a string:
String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*"); System.out.println(s.nextInt()); System.out.println(s.nextInt()); System.out.println(s.next()); System.out.println(s.next()); s.close();prints the following output:
1 2 red blueThe same output can be generated with this code, which uses a regular expression to parse all four tokens at once:
String input = "1 fish 2 fish red fish blue fish"; Scanner s = new Scanner(input); s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"); MatchResult result = s.match(); for (int i=1; i<=result.groupCount(); i++) System.out.println(result.group(i)); s.close();The default whitespace delimiter used by a scanner is as recognized by Character.isWhitespace. The reset() method will reset the value of the scanner's delimiter to the default whitespace delimiter regardless of whether it was previously changed.
A scanning operation may block waiting for input.
The next() and hasNext() methods and their primitive-type companion methods (such as nextInt() and hasNextInt()) first skip any input that matches the delimiter pattern, and then attempt to return the next token. Both hasNext and next methods may block waiting for further input. Whether a hasNext method blocks has no connection to whether or not its associated next method will block.
The findInLine(java.lang.String), findWithinHorizon(java.lang.String, int), and skip(java.util.regex.Pattern) methods operate independently of the delimiter pattern. These methods will attempt to match the specified pattern with no regard to delimiters in the input and thus can be used in special circumstances where delimiters are not relevant. These methods may block waiting for more input.
When a scanner throws an InputMismatchException, the scanner will not pass the token that caused the exception, so that it may be retrieved or skipped via some other method.
Depending upon the type of delimiting pattern, empty tokens may be returned. For example, the pattern "\s+" will return no empty tokens since it matches multiple instances of the delimiter. The delimiting pattern "\s" could return empty tokens since it only passes one space at a time.
A scanner can read text from any object which implements the Readable interface. If an invocation of the underlying readable's Readable.read(java.nio.CharBuffer) method throws an IOException then the scanner assumes that the end of the input has been reached. The most recent IOException thrown by the underlying readable can be retrieved via the ioException() method.
When a Scanner is closed, it will close its input source if the source implements the Closeable interface.
A Scanner is not safe for multithreaded use without external synchronization.
Unless otherwise mentioned, passing a null parameter into any method of a Scanner will cause a NullPointerException to be thrown.
A scanner will default to interpreting numbers as decimal unless a different radix has been set by using the useRadix(int) method. The reset() method will reset the value of the scanner's radix to 10 regardless of whether it was previously changed.
Localized numbers An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the Locale.getDefault() method; it may be changed via the useLocale(java.util.Locale) method. The reset() method will reset the value of the scanner's locale to the initial locale regardless of whether it was previously changed.
The localized formats are defined in terms of the following parameters, which for a particular locale are taken from that locale's DecimalFormat object, df, and its and DecimalFormatSymbols object, dfs.
LocalGroupSeparator The character used to separate thousands groups, i.e., dfs.getGroupingSeparator() LocalDecimalSeparator The character used for the decimal point, i.e., dfs.getDecimalSeparator() LocalPositivePrefix The string that appears before a positive number (may be empty), i.e., df.getPositivePrefix() LocalPositiveSuffix The string that appears after a positive number (may be empty), i.e., df.getPositiveSuffix() LocalNegativePrefix The string that appears before a negative number (may be empty), i.e., df.getNegativePrefix() LocalNegativeSuffix The string that appears after a negative number (may be empty), i.e., df.getNegativeSuffix() LocalNaN The string that represents not-a-number for floating-point values, i.e., dfs.getNaN() LocalInfinity The string that represents infinity for floating-point values, i.e., dfs.getInfinity()
Number syntax The strings that can be parsed as numbers by an instance of this class are specified in terms of the following regular-expression grammar, where Rmax is the highest digit in the radix being used (for example, Rmax is 9 in base 10).
NonASCIIDigit :: = A non-ASCII character c for which Character.isDigit(c) returns true Non0Digit :: = [1-Rmax] | NonASCIIDigit Digit :: = [0-Rmax] | NonASCIIDigit GroupedNumeral ::
= ( Non0Digit Digit? Digit?
( LocalGroupSeparator Digit Digit Digit )+ )
Numeral :: = ( ( Digit+ ) | GroupedNumeral )
Integer :: = ( [-+]? ( Numeral ) )
| LocalPositivePrefix Numeral LocalPositiveSuffix
| LocalNegativePrefix Numeral LocalNegativeSuffix DecimalNumeral :: = Numeral
| Numeral LocalDecimalSeparator Digit*
| LocalDecimalSeparator Digit+ Exponent :: = ( [eE] [+-]? Digit+ )
Decimal :: = ( [-+]? DecimalNumeral Exponent? )
| LocalPositivePrefix DecimalNumeral LocalPositiveSuffix Exponent?
| LocalNegativePrefix DecimalNumeral LocalNegativeSuffix Exponent? HexFloat :: = [-+]? 0[xX][0-9a-fA-F]*.[0-9a-fA-F]+ ([pP][-+]?[0-9]+)? NonNumber :: = NaN | LocalNan | Infinity | LocalInfinity SignedNonNumber :: = ( [-+]? NonNumber )
| LocalPositivePrefix NonNumber LocalPositiveSuffix
| LocalNegativePrefix NonNumber LocalNegativeSuffix
Float :: = Decimal
| HexFloat
| SignedNonNumber
Whitespace is not significant in the above regular expressions.
I am a bot still in development. For questions or suggestions, you can message /u/ADhoom
0
u/Murray_Bookchin Feb 19 '19
Wow
1
u/DocFetcher btproof Feb 19 '19
/u/ADhoom: Hmm, this is interesting lol, I will look into structuring the output correctly.
0
Feb 19 '19
[deleted]
2
u/desrtfx Feb 19 '19
Should work - strange that it didn't. Paging /u/ADhoom
3
u/ADhoom Feb 19 '19
Whoops, the pc the script was running from had a windows update while I was asleep :(
1
u/desrtfx Feb 19 '19
Ouch :)
Guess that we probably should move the script to a Raspberry Pi or so.
4
u/ADhoom Feb 19 '19
I'm planning on that happening tonight.
1
u/desrtfx Feb 19 '19
Could support you with an OrangePi, but that'd have to wait until the weekend because it's at home idling around. I'm in my work flat 200km away.
3
u/ADhoom Feb 19 '19
Oh I have one set up just need to get the code out on github and get the code on my pi. Thanks for the offer though!
2
u/desrtfx Feb 19 '19
Okay, good to hear. Was worried that you need to host somewhere where you'd need to pay. Wouldn't want that in any case.
My Raspberry Pi devices are all occupied with Repetier Server Pro driving my 3d printers.
2
0
Feb 19 '19
[deleted]
1
u/DocFetcher btproof Feb 19 '19
I was not able to find any information about Optional in the oracle documentation.
I am a bot still in development. For questions or suggestions, you can message /u/ADhoom
6
u/ADhoom Feb 19 '19
!DocFetcher java8 Integer