-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Algorithm generation doc + version 1.1
- Loading branch information
Showing
6 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
issnbot-lib/src/main/java/org/issn/issnbot/doc/AlgorithmDocumentationGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.issn.issnbot.doc; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.issn.issnbot.WikidataSerial; | ||
|
||
public class AlgorithmDocumentationGenerator { | ||
|
||
public static void main(String[] args) throws IOException { | ||
File outputFile = new File(args[0]); | ||
StringBuffer sb = new StringBuffer(); | ||
sb.append("# ISSNBot update algorithm"+"\n"); | ||
sb.append("_note : this file is automatically generated from the documentation in `WikidataSerial.java`._"+"\n"); | ||
sb.append("\n"); | ||
sb.append("This is the algorithms ISSNBot uses to update Wikidata. They are applied in the order listed here."+"\n"); | ||
sb.append("\n"); | ||
|
||
Method[] methods = WikidataSerial.class.getMethods(); | ||
List<Description> descriptions = new ArrayList<>(); | ||
for (Method m : methods) { | ||
Description d = m.getAnnotation(Description.class); | ||
if(d != null) { | ||
descriptions.add(d); | ||
} | ||
} | ||
|
||
// sort based on order | ||
Collections.sort(descriptions, (d1, d2) -> d1.order() - d2.order()); | ||
|
||
for (Description description : descriptions) { | ||
sb.append("## "+description.title()+"\n"); | ||
sb.append("\n"); | ||
sb.append(description.definition()+"\n"); | ||
sb.append("\n"); | ||
} | ||
|
||
FileUtils.write(outputFile, sb.toString(), "UTF-8"); | ||
} | ||
|
||
} |
6 changes: 5 additions & 1 deletion
6
issnbot-lib/src/main/java/org/issn/issnbot/doc/Description.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package org.issn.issnbot.doc; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(FIELD) | ||
@Target({ FIELD, METHOD }) | ||
public @interface Description { | ||
public String definition(); | ||
public String title() default ""; | ||
public int order() default 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters