# Class AuditLogObserver

java.lang.Object
com.university.bookstore.observer.AuditLogObserver

All Implemented Interfaces:
  `MaterialObserver`

public class AuditLogObserver extends Object implements MaterialObserver
Observer that maintains an audit log of all material events. Provides a complete history of system activities for compliance and debugging.

Since:
  2024-09-15
Version:
  3.0
Author:
  Navid Mohaghegh

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `AuditLogObserver.AuditLogEntry`
  Represents a single audit log entry.
  `static class`
  `AuditLogObserver.AuditLogStats`
  Statistics for the audit log.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AuditLogObserver()`
  Creates a new audit log observer with unlimited log size.
  `AuditLogObserver(int maxLogSize)`
  Creates a new audit log observer with the specified maximum log size.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clearAuditLog()`
  Clears the audit log.
  `List<AuditLogObserver.AuditLogEntry>`
  `getAuditLog()`
  Gets all audit log entries.
  `List<AuditLogObserver.AuditLogEntry>`
  `getAuditLogForEventType(String eventType)`
  Gets audit log entries for a specific event type.
  `List<AuditLogObserver.AuditLogEntry>`
  `getAuditLogForMaterial(String materialId)`
  Gets audit log entries for a specific material.
  `List<AuditLogObserver.AuditLogEntry>`
  `getAuditLogForTimeRange(long startTime, long endTime)`
  Gets audit log entries within a time range.
  `AuditLogObserver.AuditLogStats`
  `getAuditLogStats()`
  Gets audit log statistics.
  `int`
  `getLogSize()`
  Gets the number of audit log entries.
  `String`
  `getObserverName()`
  Gets the name of this observer for identification purposes.
  `void`
  `onEvent(MaterialEvent event)`
  Called when a material event occurs.
  `void`
  `printAuditLog()`
  Prints the audit log to the console.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface com.university.bookstore.observer.MaterialObserver

  `onAdded, onRemoved`

- ## Constructor Details

  - ### AuditLogObserver

    public AuditLogObserver()
    Creates a new audit log observer with unlimited log size.

  - ### AuditLogObserver

    public AuditLogObserver(int maxLogSize)
    Creates a new audit log observer with the specified maximum log size.
    Parameters:
      `maxLogSize` - the maximum number of log entries to keep

- ## Method Details

  - ### onEvent

    public void onEvent(MaterialEvent event)
    Description copied from interface: `MaterialObserver`
    Called when a material event occurs.
    Specified by:
      `onEvent` in interface `MaterialObserver`
    Parameters:
      `event` - the material event that occurred

  - ### getAuditLog

    public List<AuditLogObserver.AuditLogEntry> getAuditLog()
    Gets all audit log entries.
    Returns:
      list of audit log entries

  - ### getAuditLogForMaterial

    public List<AuditLogObserver.AuditLogEntry> getAuditLogForMaterial(String materialId)
    Gets audit log entries for a specific material.
    Parameters:
      `materialId` - the material ID to filter by
    Returns:
      list of audit log entries for the material

  - ### getAuditLogForEventType

    public List<AuditLogObserver.AuditLogEntry> getAuditLogForEventType(String eventType)
    Gets audit log entries for a specific event type.
    Parameters:
      `eventType` - the event type to filter by
    Returns:
      list of audit log entries for the event type

  - ### getAuditLogForTimeRange

    public List<AuditLogObserver.AuditLogEntry> getAuditLogForTimeRange(long startTime, long endTime)
    Gets audit log entries within a time range.
    Parameters:
      `startTime` - the start time in milliseconds
      `endTime` - the end time in milliseconds
    Returns:
      list of audit log entries within the time range

  - ### printAuditLog

    public void printAuditLog()
    Prints the audit log to the console.

  - ### getLogSize

    public int getLogSize()
    Gets the number of audit log entries.
    Returns:
      the log size

  - ### clearAuditLog

    public void clearAuditLog()
    Clears the audit log.

  - ### getAuditLogStats

    public AuditLogObserver.AuditLogStats getAuditLogStats()
    Gets audit log statistics.
    Returns:
      audit log statistics

  - ### getObserverName

    public String getObserverName()
    Description copied from interface: `MaterialObserver`
    Gets the name of this observer for identification purposes.
    Specified by:
      `getObserverName` in interface `MaterialObserver`
    Returns:
      the observer name

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`