001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math;
006
007import edu.wpi.first.util.WPIUtilJNI;
008
009public final class MathSharedStore {
010  private static MathShared mathShared;
011
012  private MathSharedStore() {}
013
014  /**
015   * Get the MathShared object.
016   *
017   * @return The MathShared object.
018   */
019  public static synchronized MathShared getMathShared() {
020    if (mathShared == null) {
021      mathShared =
022          new MathShared() {
023            @Override
024            public void reportError(String error, StackTraceElement[] stackTrace) {}
025
026            @Override
027            public void reportUsage(MathUsageId id, int count) {}
028
029            @Override
030            public double getTimestamp() {
031              return WPIUtilJNI.now() * 1.0e-6;
032            }
033          };
034    }
035    return mathShared;
036  }
037
038  /**
039   * Set the MathShared object.
040   *
041   * @param shared The MathShared object.
042   */
043  public static synchronized void setMathShared(MathShared shared) {
044    mathShared = shared;
045  }
046
047  /**
048   * Report an error.
049   *
050   * @param error the error to set
051   * @param stackTrace array of stacktrace elements
052   */
053  public static void reportError(String error, StackTraceElement[] stackTrace) {
054    getMathShared().reportError(error, stackTrace);
055  }
056
057  /**
058   * Report usage.
059   *
060   * @param id the usage id
061   * @param count the usage count
062   */
063  public static void reportUsage(MathUsageId id, int count) {
064    getMathShared().reportUsage(id, count);
065  }
066
067  /**
068   * Get the time.
069   *
070   * @return The time in seconds.
071   */
072  public static double getTimestamp() {
073    return getMathShared().getTimestamp();
074  }
075}