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
007public final class MathSharedStore {
008  private static MathShared mathShared;
009
010  private MathSharedStore() {}
011
012  /**
013   * Get the MathShared object.
014   *
015   * @return The MathShared object.
016   */
017  public static synchronized MathShared getMathShared() {
018    if (mathShared == null) {
019      mathShared =
020          new MathShared() {
021            @Override
022            public void reportError(String error, StackTraceElement[] stackTrace) {}
023
024            @Override
025            public void reportUsage(MathUsageId id, int count) {}
026          };
027    }
028    return mathShared;
029  }
030
031  /**
032   * Set the MathShared object.
033   *
034   * @param shared The MathShared object.
035   */
036  public static synchronized void setMathShared(MathShared shared) {
037    mathShared = shared;
038  }
039
040  /**
041   * Report an error.
042   *
043   * @param error the error to set
044   * @param stackTrace array of stacktrace elements
045   */
046  public static void reportError(String error, StackTraceElement[] stackTrace) {
047    getMathShared().reportError(error, stackTrace);
048  }
049
050  /**
051   * Report usage.
052   *
053   * @param id the usage id
054   * @param count the usage count
055   */
056  public static void reportUsage(MathUsageId id, int count) {
057    getMathShared().reportUsage(id, count);
058  }
059}