Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java Utilities

    For anyone interested in using the Java API, I've set up a new repository with cleaner versions of some of the classes/methods I've built out to use the API. A fair amount of the classes are derived from the code used in the package jsonio (available from SSC), but do not include any of the Jackson JSON Annotations. The javadocs are available at http://wbuchanan.github.io/StataJavaUtilities/. There are JARs with the compiled classes, source, and javadocs available as well. If you wanted/needed to use any of the classes in your own work, once you download the file you can use the following to make the classes available with Maven from the command line:

    Code:
    // compiled classes/methods (classes / all)
    mvn install:install-file -DgroupId=org.paces.Stata -DartifactId=java -Dversion=0.0.1 -Dpackaging=jar -Dfile=StataJavaUtilities.jar 
    
    // javadocs (javadoc / all)
    mvn install:install-file -DgroupId=org.paces.Stata -DartifactId=java -Dversion=0.0.1 -Dpackaging=jar -Dfile=StataJavaUtilities-javadoc.jar 
    
    // Source code (src / all)
    mvn install:install-file -DgroupId=org.paces.Stata -DartifactId=java -Dversion=0.0.1 -Dpackaging=jar -Dfile=StataJavaUtilities-sources.jar
    There is also a simple ado in the repository that you could use to automate this (it should copy the JARs to the Stata CLASSPATH and install it in your local maven repository for you unless you're working on Windows since the command line works a bit differently). :

    Code:
    // Update/Install all of the JARs above and make them available in maven after downloading (should work for any *nix based system)
    javautils, upd(all) mav
    
    // Add just the compiled classes to Stata's CLASSPATH
    javautils, upd(classes) 
    
    // Print a hyperlink to the source code repository
    javautils, url
    The allowed arguments for the update parameter appear in parentheses in the first code block: all, classes, javadoc, or src. I tried to document things fairly thoroughly but if you have questions feel free to ask and hopefully this will make it a bit easier for you/others to use the Java API.

  • #2
    I also just tried to make it a bit easier to include things in your Java projects if you are using Maven. The JARs are now available at https://oss.sonatype.org/content/gro....0.1-SNAPSHOT/. The pom entry should look something like:

    Code:
    <dependencies>
        <dependency>
            <groupId>org.paces-consulting</groupId>
            <artifactId>stata-java</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    Depending on how you have Maven configured, you can access JARs for the compiled classes/methods, the source code, and/or the javadocs.

    Comment


    • #3
      Just finished squashing a bug in this source code that would have caused NullPointerExceptions to be thrown when using any of the DataSet* class constructors. The update has been pushed to the maven repository as well (with the same version number for now) but should be ready for use.

      Comment


      • #4
        There are a few new updates to this project including finishing the mapping of extended missing values for float and double types, and adding additional getter methods to the classes in the DataSets package. Everything is available via the Maven repository or from GitHub.

        Comment


        • #5
          There are some new updates to these Java classes that should make it a bit easier to work across Stata versions 13 and 14. The Meta class now includes a few different accessors to make it a bit easier to access the values of members of the Variables class (e.g., variable names, string variable booleans, etc...) and includes methods to handle casting the data accessed from Stata to different Java types:

          Code:
          Integer intDatum = StTypes.asInteger(variableIndex, observationIndex);
          The StTypes class defines a set of static methods with the same interface as the Data.getNum(int variable, [int|long] observation) accessor from the Java API, but converts the returned result to the appropriate type and returns the object type of the datum instead of the primative type (e.g., will return an Integer instead of an int). The developer is still responsible for ensuring that the method is called in cases where it makes sense, but there shouldn't be an issues with the type conversions beyond the expected changes in the precision of the data. Another improvement are methods that convert the Observation indices from the Observations class to the appropriate type given the version of Stata that is initializing the classes:

          Code:
          Meta m = new Meta();
          if (SFIToolkit.getCallerVersion() < 14.0D) {
              List<Integer> obsIndex = m.getObs13();
          ...
          } else {
              List<Long> obsIndex = m.getObs14();
          ...
          }
          There are also a few utility methods to handle casting the dataset array types from primative types (e.g., byte, int, long, double, ....) to object types (e.g., Byte, Integer, Long, Double, etc...), from object to primative types, and from two dimensional arrays to nested lists (e.g., a List<List<Double>> from a Double[][]).

          You can include the library in your code using:

          Code:
                  <dependency>
                      <groupId>org.paces-consulting</groupId>
                      <artifactId>stata-java</artifactId>
                      <version>0.0.3-SNAPSHOT</version>
                      <type>jar</type>
                      <scope>compile</scope>
                      <optional>false</optional>
                  </dependency>

          Comment

          Working...
          X