oshi.hardware.common.AbstractPowerSource Maven / Gradle / Ivy
/**
* Oshi (https://github.com/dblock/oshi)
*
* Copyright (c) 2010 - 2016 The Oshi Project Team
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Maintainers:
* dblock[at]dblock[dot]org
* widdis[at]gmail[dot]com
* enrico.bianchi[at]gmail[dot]com
*
* Contributors:
* https://github.com/dblock/oshi/graphs/contributors
*/
package oshi.hardware.common;
import javax.json.Json;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObject;
import oshi.hardware.PowerSource;
import oshi.json.NullAwareJsonObjectBuilder;
/**
* A Power Source
*
* @author widdis[at]gmail[dot]com
*/
public abstract class AbstractPowerSource implements PowerSource {
private static final long serialVersionUID = 1L;
protected String name;
protected double remainingCapacity;
protected double timeRemaining;
private JsonBuilderFactory jsonFactory = Json.createBuilderFactory(null);
public AbstractPowerSource(String newName, double newRemainingCapacity, double newTimeRemaining) {
this.name = newName;
this.remainingCapacity = newRemainingCapacity;
this.timeRemaining = newTimeRemaining;
}
/**
* {@inheritDoc}
*/
@Override
public String getName() {
return this.name;
}
/**
* {@inheritDoc}
*/
@Override
public double getRemainingCapacity() {
return this.remainingCapacity;
}
/**
* {@inheritDoc}
*/
@Override
public double getTimeRemaining() {
return this.timeRemaining;
}
/**
* {@inheritDoc}
*/
@Override
public JsonObject toJSON() {
return NullAwareJsonObjectBuilder.wrap(jsonFactory.createObjectBuilder()).add("name", getName())
.add("remainingCapacity", getRemainingCapacity()).add("timeRemaining", getTimeRemaining()).build();
}
}