Class BatteryService

java.lang.Object
io.github.eggy03.ferrumx.windows.service.battery.BatteryService
All Implemented Interfaces:
CommonServiceInterface<Battery>

public class BatteryService extends Object implements CommonServiceInterface<Battery>
Service class for fetching battery information from the system.

This class executes the CimQuery.BATTERY_QUERY PowerShell command and maps the resulting JSON into a list of Battery objects.

Thread safety

Methods of class are not thread safe.

Usage examples


 // Convenience API (creates its own short-lived session)
 BatteryService batteryService = new BatteryService();
 List<Battery> batteries = batteryService.get();

 // API with re-usable session (caller manages session lifecycle)
 try (PowerShell session = PowerShell.openSession()) {
     List<Battery> batteries = batteryService.get(session);
 }
 
Since:
2.0.0
Author:
Egg-03
  • Constructor Details

    • BatteryService

      public BatteryService()
  • Method Details

    • get

      @NotNull public @NotNull List<Battery> get()
      Retrieves a list of batteries present on the system.

      Each invocation creates and uses a short-lived PowerShell session internally.

      Specified by:
      get in interface CommonServiceInterface<Battery>
      Returns:
      a list of Battery objects representing the system's batteries. If no batteries are present, returns an empty list.
      Throws:
      com.google.gson.JsonSyntaxException - if there is an error executing the PowerShell command or parsing the output.
    • get

      @NotNull public @NotNull List<Battery> get(com.profesorfalken.jpowershell.PowerShell powerShell)
      Retrieves a list of batteries present on the system using the caller's PowerShell session.
      Specified by:
      get in interface CommonServiceInterface<Battery>
      Parameters:
      powerShell - an existing PowerShell session managed by the caller
      Returns:
      a list of Battery objects representing the system's batteries. If no batteries are present, returns an empty list.
      Throws:
      com.google.gson.JsonSyntaxException - if there is an error executing the PowerShell command or parsing the output.