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 009/** Storage for MathShared object. */ 010public final class MathSharedStore { 011 private static MathShared mathShared; 012 013 private MathSharedStore() {} 014 015 /** 016 * Get the MathShared object. 017 * 018 * @return The MathShared object. 019 */ 020 public static synchronized MathShared getMathShared() { 021 if (mathShared == null) { 022 mathShared = 023 new MathShared() { 024 @Override 025 public void reportError(String error, StackTraceElement[] stackTrace) {} 026 027 @Override 028 public void reportUsage(MathUsageId id, int count) {} 029 030 @Override 031 public double getTimestamp() { 032 return WPIUtilJNI.now() * 1.0e-6; 033 } 034 }; 035 } 036 return mathShared; 037 } 038 039 /** 040 * Set the MathShared object. 041 * 042 * @param shared The MathShared object. 043 */ 044 public static synchronized void setMathShared(MathShared shared) { 045 mathShared = shared; 046 } 047 048 /** 049 * Report an error. 050 * 051 * @param error the error to set 052 * @param stackTrace array of stacktrace elements 053 */ 054 public static void reportError(String error, StackTraceElement[] stackTrace) { 055 getMathShared().reportError(error, stackTrace); 056 } 057 058 /** 059 * Report usage. 060 * 061 * @param id the usage id 062 * @param count the usage count 063 */ 064 public static void reportUsage(MathUsageId id, int count) { 065 getMathShared().reportUsage(id, count); 066 } 067 068 /** 069 * Get the time. 070 * 071 * @return The time in seconds. 072 */ 073 public static double getTimestamp() { 074 return getMathShared().getTimestamp(); 075 } 076}