Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/inspections #80

Merged
merged 10 commits into from
Apr 27, 2017
34 changes: 13 additions & 21 deletions src/main/java/net/atomique/ksar/Config.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.atomique.ksar;

import java.awt.Font;
Expand All @@ -15,20 +11,16 @@
import java.util.prefs.Preferences;
import javax.swing.UIManager;

/**
*
* @author Max
*/
public class Config {

private static Preferences myPref;
private static Config instance = new Config();

public static Config getInstance() {
static Config getInstance() {
return instance;
}

Config() {
private Config() {
myPref = Preferences.userNodeForPackage(Config.class);
if (myPref.getInt("local_configfile", -1) == -1) {
// new
Expand Down Expand Up @@ -98,17 +90,17 @@ public static void setLandf(String landf) {
Config.landf = landf;
}

public static File getLastReadDirectory() {
static File getLastReadDirectory() {
return lastReadDirectory;
}

public static void setLastReadDirectory(String lastReadDirectory) {
private static void setLastReadDirectory(String lastReadDirectory) {
if (lastReadDirectory != null) {
Config.lastReadDirectory = new File(lastReadDirectory);
}
}

public static void setLastReadDirectory(File lastReadDirectory) {
static void setLastReadDirectory(File lastReadDirectory) {
Config.lastReadDirectory = lastReadDirectory;
}

Expand Down Expand Up @@ -142,11 +134,11 @@ public static void addHost_history(String e) {
host_history.add(e);
}

public static int getNumber_host_history() {
private static int getNumber_host_history() {
return number_host_history;
}

public static void setNumber_host_history(int number_host_history) {
private static void setNumber_host_history(int number_host_history) {
Config.number_host_history = number_host_history;
}

Expand Down Expand Up @@ -178,9 +170,9 @@ public static void setPDFPageFormat(String PDFPageFormat) {
Config.PDFPageFormat = PDFPageFormat;
}



public static int store_configdir() {

private static int store_configdir() {
Properties systemprops = System.getProperties();
String userhome = (String) systemprops.get("user.home") + systemprops.get("file.separator");
String username = (String) systemprops.get("user.name");
Expand All @@ -192,7 +184,7 @@ public static int store_configdir() {
return 0;
}

BufferedWriter out = null;
BufferedWriter out;
try {
out = new BufferedWriter(new FileWriter(userhome + ".ksarcfg" + fileseparator + "Config.xml"));
out.write(buffer);
Expand All @@ -209,7 +201,7 @@ public static int getLocal_configfile() {
return local_configfile;
}

public static void setLocal_configfile(int local_configfile) {
private static void setLocal_configfile(int local_configfile) {
Config.local_configfile = local_configfile;
}

Expand All @@ -229,8 +221,8 @@ public static void setLinuxDateFormat(String LinuxDateFormat) {
private static String lastCommand;
private static int number_host_history;
private static int local_configfile;
private static ArrayList<String> host_history = new ArrayList<String>();
public static final Font DEFAULT_FONT = new Font("SansSerif", Font.BOLD, 18);
private static ArrayList<String> host_history = new ArrayList<>();
private static final Font DEFAULT_FONT = new Font("SansSerif", Font.BOLD, 18);

private static String LinuxDateFormat;
private static String PDFPageFormat;
Expand Down
61 changes: 23 additions & 38 deletions src/main/java/net/atomique/ksar/GlobalOptions.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.atomique.ksar;

import java.awt.Color;
Expand All @@ -10,12 +6,8 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import net.atomique.ksar.UI.Desktop;
import net.atomique.ksar.XML.CnxHistory;
Expand All @@ -25,41 +17,34 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author Max
*/
public class GlobalOptions {

private static final Logger log = LoggerFactory.getLogger(GlobalOptions.class);

private static GlobalOptions instance = new GlobalOptions();

public static GlobalOptions getInstance() {
static GlobalOptions getInstance() {
return instance;
}

public static boolean hasUI() {
if (UI != null) {
return true;
}
return false;
return (UI != null);
}

GlobalOptions() {
private GlobalOptions() {
String [] OSParserNames = {"AIX", "HPUX", "Linux", "SunOS"};
String filename = null;
InputStream is = null;
XMLConfig tmp = null;
String filename;
InputStream is;
XMLConfig tmp;
systemprops = System.getProperties();
username = (String) systemprops.get("user.name");
userhome = (String) systemprops.get("user.home") + systemprops.get("file.separator");
fileseparator = (String) systemprops.get("file.separator");
columnlist = new HashMap<String, ColumnConfig>();
OSlist = new HashMap<String, OSConfig>();
ParserMap = new HashMap<String, Class>();
HistoryList = new HashMap<String, CnxHistory>();
HostInfoList = new HashMap<String, HostInfo>();
columnlist = new HashMap<>();
OSlist = new HashMap<>();
ParserMap = new HashMap<>();
HistoryList = new HashMap<>();
HostInfoList = new HashMap<>();
is = this.getClass().getResourceAsStream("/Config.xml");
tmp = new XMLConfig(is);
for ( String OSName : OSParserNames ) {
Expand Down Expand Up @@ -105,11 +90,11 @@ public static String getUsername() {
return username;
}

public static HashMap<String, ColumnConfig> getColorlist() {
static HashMap<String, ColumnConfig> getColorlist() {
return columnlist;
}

public static HashMap<String, OSConfig> getOSlist() {
static HashMap<String, OSConfig> getOSlist() {
return OSlist;
}

Expand All @@ -129,39 +114,39 @@ public static Color getDataColor(String s) {
return null;
}

public static OSConfig getOSinfo(String s) {
static OSConfig getOSinfo(String s) {
return OSlist.get(s);
}

public static boolean isDodebug() {
return dodebug;
}

public static void setDodebug(boolean do_debug) {
static void setDodebug(boolean do_debug) {
GlobalOptions.dodebug = do_debug;
}

public static String getCLfilename() {
static String getCLfilename() {
return CLfilename;
}

public static void setCLfilename(String CL_filename) {
static void setCLfilename(String CL_filename) {
GlobalOptions.CLfilename = CL_filename;
}

public static String getFileseparator() {
return fileseparator;
}

public static Class getParser(String s) {
static Class getParser(String s) {
String tmp = s.replaceAll("-", "");
if (ParserMap.isEmpty()) {
return null;
}
return ParserMap.get(tmp);
}

public static HashMap<String, HostInfo> getHostInfoList() {
static HashMap<String, HostInfo> getHostInfoList() {
return HostInfoList;
}

Expand All @@ -177,18 +162,18 @@ public static void addHostInfo(HostInfo s) {
saveHistory();
}

public static HashMap<String, CnxHistory> getHistoryList() {
static HashMap<String, CnxHistory> getHistoryList() {
return HistoryList;
}

public static CnxHistory getHistory(String s) {
static CnxHistory getHistory(String s) {
if (HistoryList.isEmpty()) {
return null;
}
return HistoryList.get(s);
}

public static void addHistory(CnxHistory s) {
static void addHistory(CnxHistory s) {
CnxHistory tmp = HistoryList.get(s.getLink());
if ( tmp != null) {
Iterator<String> ite = s.getCommandList().iterator();
Expand All @@ -203,7 +188,7 @@ public static void addHistory(CnxHistory s) {



public static void saveHistory() {
static void saveHistory() {
File tmpfile = null;
BufferedWriter tmpfile_out = null;

Expand Down
8 changes: 0 additions & 8 deletions src/main/java/net/atomique/ksar/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.atomique.ksar;

import java.util.ResourceBundle;
Expand All @@ -13,10 +9,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author Max
*/
public class Main {

private static final org.slf4j.Logger log = LoggerFactory.getLogger(Main.class);
Expand Down
16 changes: 2 additions & 14 deletions src/main/java/net/atomique/ksar/OSParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ public String getInfo() {
return tmpstr.toString();
}

public String getOriginal_line() {
return original_line;
}

public void setOriginal_line(String original_line) {
this.original_line = original_line;
}

public String gethostName() {
return Hostname;
Expand Down Expand Up @@ -171,8 +164,7 @@ final public void updateUITitle() {

protected String lastStat = null;
protected Object currentStatObj = null;
//List graphlist = new ArrayList();


protected String ostype = null;
protected String Hostname = null;
protected String OSversion = null;
Expand All @@ -183,9 +175,5 @@ final public void updateUITitle() {
protected String NBDisk = null;
protected String NBCpu = null;
protected String ENT = null;
protected String Detect = null;
protected String original_line=null;
// for graph



}
2 changes: 1 addition & 1 deletion src/main/java/net/atomique/ksar/Parser/AIX.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class AIX extends OSParser {

public void parse_header(String s) {
String [] columns = s.split("\\s+");
setOstype(columns[0]);

setOstype(columns[0]);
setHostname(columns[1]);
setOSversion(columns[2]+ "." + columns[3]);
setMacAddress(columns[4]);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/net/atomique/ksar/Parser/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

import net.atomique.ksar.Config;
import net.atomique.ksar.OSParser;
Expand All @@ -23,11 +22,9 @@ public class Linux extends OSParser {

private static final Logger log = LoggerFactory.getLogger(Linux.class);
private String LinuxDateFormat;
private LocalTime prevParseTime;

private final Set<String> IgnoreLinesBeginningWith = new HashSet<String>(Arrays.asList(
new String[] {"Average:","##","Summary"}
));
private final HashSet<String> IgnoreLinesBeginningWith = new HashSet<>(Arrays.asList(
"Average:","##","Summary"));

public void parse_header(String s) {

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/atomique/ksar/Parser/SunOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class SunOS extends OSParser {
boolean under_average = false;

public void parse_header(String s) {

String[] columns = s.split("\\s+");

setOstype(columns[0]);
setHostname(columns[1]);
setOSversion(columns[2]);
Expand All @@ -39,8 +41,7 @@ public void parse_header(String s) {
tmpview.setVisible(true);

}



}

@Override
Expand Down
Loading