Skip to content

Commit

Permalink
Merge pull request #7941 from pabender/development
Browse files Browse the repository at this point in the history
linting; test cleanup
  • Loading branch information
pabender committed Jan 14, 2020
2 parents 3fd9113 + b08ee44 commit 58e8e1e
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 165 deletions.
2 changes: 1 addition & 1 deletion java/src/jmri/InstanceInitializer.java
Expand Up @@ -39,7 +39,7 @@ public interface InstanceInitializer {
* supported by this InstanceInitalizer
*/
@Nonnull
public <T> Object getDefault(@Nonnull Class<T> type) throws IllegalArgumentException;
public <T> Object getDefault(@Nonnull Class<T> type);

/**
* Get the set of classes for which this InstanceInitializer can provide
Expand Down
Expand Up @@ -16,7 +16,7 @@ public class AbstractInstanceInitializer implements InstanceInitializer {
*/
@Override
@Nonnull
public <T> Object getDefault(@Nonnull Class<T> type) throws IllegalArgumentException {
public <T> Object getDefault(@Nonnull Class<T> type) {
throw new IllegalArgumentException();
}

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmris/json/JsonServerPreferences.java
Expand Up @@ -210,7 +210,7 @@ private static class JsonServerPreferencesXml extends XmlFile {
public static class Initializer extends AbstractInstanceInitializer {

@Override
public <T> Object getDefault(Class<T> type) throws IllegalArgumentException {
public <T> Object getDefault(Class<T> type) {
if (type.equals(JsonServerPreferences.class)) {
String fileName = FileUtil.getUserFilesPath() + "networkServices" + File.separator + "JsonServerPreferences.xml"; // NOI18N
if ((new File(fileName)).exists()) {
Expand Down
6 changes: 2 additions & 4 deletions java/src/jmri/jmrit/catalog/CatalogPanel.java
Expand Up @@ -197,10 +197,8 @@ public void createNewBranch(String systemName, String userName, String path) {
jmri.util.ThreadingUtil.runOnGUI(() -> addTree(tree));
} else {
final CatalogTree t = manager.newCatalogTree(systemName, userName);
jmri.util.ThreadingUtil.runOnGUI(() -> {
t.insertNodes(path);
addTree(t);
});
t.insertNodes(path);
jmri.util.ThreadingUtil.runOnGUI(() -> addTree(t));
}
}

Expand Down
10 changes: 5 additions & 5 deletions java/src/jmri/jmrit/catalog/CatalogTreeModel.java
Expand Up @@ -32,8 +32,8 @@ public CatalogTreeModel() {

// we manually create the first node, rather than use
// the routine, so we can name it.
CatalogTreeModel.this.insertResourceNodes("resources", resourceRoot, dRoot);
FileUtil.createDirectory(FileUtil.getUserFilesPath() + "resources");
CatalogTreeModel.this.insertResourceNodes(resourceRoot, resourceRoot, dRoot);
FileUtil.createDirectory(FileUtil.getUserResourcePath());
CatalogTreeModel.this.insertFileNodes("files", fileRoot, dRoot);

}
Expand Down Expand Up @@ -112,7 +112,7 @@ void insertFileNodes(String name, String path, DefaultMutableTreeNode parent) {
// work on the kids
String[] sp = fp.list();
for (String sp1 : sp) {
//if (log.isDebugEnabled()) log.debug("Descend into file: "+sp[i]);
log.debug("Descend into file: {}",sp1);
insertFileNodes(sp1, path + "/" + sp1, newElement);
}
}
Expand All @@ -124,8 +124,8 @@ void insertFileNodes(String name, String path, DefaultMutableTreeNode parent) {
* Starting point in the .jar file for the "icons" part of the tree
*/
static final String resourceRoot = "resources";
static final String fileRoot = FileUtil.getUserFilesPath() + "resources";
static final String fileRoot = FileUtil.getUserResourcePath();

private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CatalogTreeModel.class);
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CatalogTreeModel.class);

}
8 changes: 4 additions & 4 deletions java/src/jmri/jmrit/catalog/DefaultCatalogTreeManager.java
Expand Up @@ -71,7 +71,7 @@ public CatalogTree getBySystemName(@Nonnull String key) {
CatalogTree tree = _tsys.get(key);
if (tree != null) {
CatalogTreeNode root = tree.getRoot();
log.debug("root= {}, has {} children", root.toString(), root.getChildCount());
log.debug("root= {}, has {} children", root,root.getChildCount());
}
}
return _tsys.get(key);
Expand All @@ -87,7 +87,7 @@ public CatalogTree getByUserName(@Nonnull String key) {
*/
@Override
public CatalogTree newCatalogTree(@Nonnull String systemName, String userName) {
log.debug("new CatalogTree: systemName= {}, userName= {}", systemName, (userName != null ? userName : "null"));
log.debug("new CatalogTree: systemName= {}, userName= {}", systemName, userName);
if (systemName.length() == 0) {
log.error("Empty systemName!");
return null;
Expand Down Expand Up @@ -239,14 +239,14 @@ public boolean doPrompt() {
}
}

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

@ServiceProvider(service = InstanceInitializer.class)
public static class Initializer extends AbstractInstanceInitializer {

@Override
@Nonnull
public <T> Object getDefault(Class<T> type) throws IllegalArgumentException {
public <T> Object getDefault(Class<T> type) {
if (type.equals(CatalogTreeManager.class)) {
return new DefaultCatalogTreeManager();
}
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/catalog/ImageIndexEditor.java
Expand Up @@ -325,7 +325,7 @@ private int countIcons(CatalogTreeNode node) {
public static class Initializer extends AbstractInstanceInitializer {

@Override
public <T> Object getDefault(Class<T> type) throws IllegalArgumentException {
public <T> Object getDefault(Class<T> type) {
if (type.equals(ImageIndexEditor.class)) {
ImageIndexEditor instance = new ImageIndexEditor(Bundle.getMessage("editIndexFrame"));
instance.init();
Expand Down
90 changes: 48 additions & 42 deletions java/src/jmri/jmrit/decoderdefn/DecoderIndexFile.java
Expand Up @@ -50,6 +50,12 @@
*/
public class DecoderIndexFile extends XmlFile {

public static final String MANUFACTURER = "manufacturer";
public static final String MFG_ID = "mfgID";
public static final String DECODER_INDEX = "decoderIndex";
public static final String VERSION = "version";
public static final String LOW_VERSION_ID = "lowVersionID";
public static final String HIGH_VERSION_ID = "highVersionID";
// fill in abstract members
protected List<DecoderFile> decoderList = new ArrayList<>();

Expand Down Expand Up @@ -142,7 +148,7 @@ public JComboBox<String> matchingComboBox(String mfg, String family, String deco
* @param l list of decoders
* @return a combo box populated with the list
*/
static public JComboBox<String> jComboBoxFromList(List<DecoderFile> l) {
public static JComboBox<String> jComboBoxFromList(List<DecoderFile> l) {
return new JComboBox<>(jComboBoxModelFromList(l));
}

Expand All @@ -153,7 +159,7 @@ static public JComboBox<String> jComboBoxFromList(List<DecoderFile> l) {
* @param l list of decoders
* @return a combo box model populated with the list
*/
static public javax.swing.ComboBoxModel<String> jComboBoxModelFromList(List<DecoderFile> l) {
public static javax.swing.ComboBoxModel<String> jComboBoxModelFromList(List<DecoderFile> l) {
javax.swing.DefaultComboBoxModel<String> b = new javax.swing.DefaultComboBoxModel<>();
for (int i = 0; i < l.size(); i++) {
DecoderFile r = l.get(i);
Expand Down Expand Up @@ -231,7 +237,7 @@ public boolean checkEntry(int i, String mfgName, String family, String mfgID,
/**
* Replace the managed instance with a new instance.
*/
public synchronized static void resetInstance() {
public static synchronized void resetInstance() {
InstanceManager.getDefault().clear(DecoderIndexFile.class);
}

Expand Down Expand Up @@ -265,9 +271,9 @@ static boolean updateIndexIfNeeded() throws org.jdom2.JDOMException, java.io.IOE
}
log.debug("checking for master file at {}", masterFile);
Element masterRoot = masterXmlFile.rootFromURL(masterFile);
if (masterRoot.getChild("decoderIndex") != null) {
if (masterRoot.getChild("decoderIndex").getAttribute("version") != null) {
masterVersion = masterRoot.getChild("decoderIndex").getAttribute("version").getValue();
if (masterRoot.getChild(DECODER_INDEX) != null) {
if (masterRoot.getChild(DECODER_INDEX).getAttribute(VERSION) != null) {
masterVersion = masterRoot.getChild(DECODER_INDEX).getAttribute(VERSION).getValue();
}
log.debug("master version found, is {}", masterVersion);
} else {
Expand All @@ -281,9 +287,9 @@ static boolean updateIndexIfNeeded() throws org.jdom2.JDOMException, java.io.IOE
DecoderIndexFile userXmlFile = new DecoderIndexFile();
log.debug("checking for user file at {}", defaultDecoderIndexFilename());
Element userRoot = userXmlFile.rootFromName(defaultDecoderIndexFilename());
if (userRoot.getChild("decoderIndex") != null) {
if (userRoot.getChild("decoderIndex").getAttribute("version") != null) {
userVersion = userRoot.getChild("decoderIndex").getAttribute("version").getValue();
if (userRoot.getChild(DECODER_INDEX) != null) {
if (userRoot.getChild(DECODER_INDEX).getAttribute(VERSION) != null) {
userVersion = userRoot.getChild(DECODER_INDEX).getAttribute(VERSION).getValue();
}
log.debug("user version found, is {}", userVersion);
}
Expand All @@ -302,7 +308,7 @@ static boolean updateIndexIfNeeded() throws org.jdom2.JDOMException, java.io.IOE
/**
* Force creation of a new user index without incrementing version
*/
static public void forceCreationOfNewIndex() {
public static void forceCreationOfNewIndex() {
forceCreationOfNewIndex(false);
}

Expand All @@ -311,11 +317,11 @@ static public void forceCreationOfNewIndex() {
*
* @param increment true to increment the version of the decoder index
*/
static public void forceCreationOfNewIndex(boolean increment) {
public static void forceCreationOfNewIndex(boolean increment) {
log.info("update decoder index");
// make sure we're using only the default manufacturer info
// to keep from propagating wrong, old stuff
File oldfile = new File(FileUtil.getUserFilesPath() + "decoderIndex.xml");
File oldfile = new File(FileUtil.getUserFilesPath() + DECODER_INDEX_FILE_NAME);
if (oldfile.exists()) {
log.debug("remove existing user decoderIndex.xml file");
if (!oldfile.delete()) // delete file, check for success
Expand Down Expand Up @@ -356,10 +362,10 @@ static public void forceCreationOfNewIndex(boolean increment) {
}
}
} else {
log.error("Could not access decoder definition directory {}", XmlFile.xmlDir() + DecoderFile.fileLocation);
log.error("Could not access decoder definition directory {}{}", XmlFile.xmlDir(),DecoderFile.fileLocation);
}
// copy the decoder entries to the final array
String sbox[] = al.toArray(new String[al.size()]);
String[] sbox = al.toArray(new String[al.size()]);

//the resulting array is now sorted on file-name to make it easier
// for humans to read
Expand All @@ -378,7 +384,7 @@ static public void forceCreationOfNewIndex(boolean increment) {

// write it out
try {
index.writeFile("decoderIndex.xml", InstanceManager.getDefault(DecoderIndexFile.class), sbox);
index.writeFile(DECODER_INDEX_FILE_NAME, InstanceManager.getDefault(DecoderIndexFile.class), sbox);
} catch (java.io.IOException ex) {
log.error("Error writing new decoder index file: {}", ex.getMessage());
}
Expand All @@ -394,23 +400,23 @@ static public void forceCreationOfNewIndex(boolean increment) {
*/
void readFile(String name) throws org.jdom2.JDOMException, java.io.IOException {
if (log.isDebugEnabled()) {
log.debug("readFile " + name);
log.debug("readFile {}",name);
}

// read file, find root
Element root = rootFromName(name);

// decode type, invoke proper processing routine if a decoder file
if (root.getChild("decoderIndex") != null) {
if (root.getChild("decoderIndex").getAttribute("version") != null) {
fileVersion = Integer.parseInt(root.getChild("decoderIndex")
.getAttribute("version")
if (root.getChild(DECODER_INDEX) != null) {
if (root.getChild(DECODER_INDEX).getAttribute(VERSION) != null) {
fileVersion = Integer.parseInt(root.getChild(DECODER_INDEX)
.getAttribute(VERSION)
.getValue()
);
}
log.debug("found fileVersion of {}", fileVersion);
readMfgSection();
readFamilySection(root.getChild("decoderIndex"));
readFamilySection(root.getChild(DECODER_INDEX));
} else {
log.error("Unrecognized decoderIndex file contents in file: {}", name);
}
Expand All @@ -436,16 +442,16 @@ void readMfgSection() throws org.jdom2.JDOMException, java.io.IOException {
lastAdd = a.getValue();
}

List<Element> l = mfgList.getChildren("manufacturer");
List<Element> l = mfgList.getChildren(MANUFACTURER);
if (log.isDebugEnabled()) {
log.debug("readMfgSection sees " + l.size() + " children");
log.debug("readMfgSection sees {} children",l.size());
}
for (int i = 0; i < l.size(); i++) {
// handle each entry
Element el = l.get(i);
String mfg = el.getAttribute("mfg").getValue();
mMfgNameList.add(mfg);
Attribute attr = el.getAttribute("mfgID");
Attribute attr = el.getAttribute(MFG_ID);
if (attr != null) {
_mfgIdFromNameHash.put(mfg, attr.getValue());
_mfgNameFromIdHash.put(attr.getValue(), mfg);
Expand Down Expand Up @@ -475,8 +481,8 @@ void readFamilySection(Element decoderIndex) {
void readFamily(Element family) {
Attribute attr;
String filename = family.getAttribute("file").getValue();
String parentLowVersID = ((attr = family.getAttribute("lowVersionID")) != null ? attr.getValue() : null);
String parentHighVersID = ((attr = family.getAttribute("highVersionID")) != null ? attr.getValue() : null);
String parentLowVersID = ((attr = family.getAttribute(LOW_VERSION_ID)) != null ? attr.getValue() : null);
String parentHighVersID = ((attr = family.getAttribute(HIGH_VERSION_ID)) != null ? attr.getValue() : null);
String ParentReplacementFamilyName = ((attr = family.getAttribute("replacementFamily")) != null ? attr.getValue() : null);
String familyName = ((attr = family.getAttribute("name")) != null ? attr.getValue() : null);
String mfg = ((attr = family.getAttribute("mfg")) != null ? attr.getValue() : null);
Expand All @@ -491,7 +497,7 @@ void readFamily(Element family) {
List<Element> l = family.getChildren("model");
log.trace("readFamily sees {} children", l.size());
Element modelElement;
if (l.size() <= 0) {
if (l.isEmpty()) {
log.error("Did not find at least one model in the {} family", familyName);
modelElement = null;
} else {
Expand All @@ -515,8 +521,8 @@ void readFamily(Element family) {
for (int i = 0; i < l.size(); i++) {
// handle each entry by creating a DecoderFile object containing all it knows
Element decoder = l.get(i);
String loVersID = ((attr = decoder.getAttribute("lowVersionID")) != null ? attr.getValue() : parentLowVersID);
String hiVersID = ((attr = decoder.getAttribute("highVersionID")) != null ? attr.getValue() : parentHighVersID);
String loVersID = ((attr = decoder.getAttribute(LOW_VERSION_ID)) != null ? attr.getValue() : parentLowVersID);
String hiVersID = ((attr = decoder.getAttribute(HIGH_VERSION_ID)) != null ? attr.getValue() : parentHighVersID);
String replacementModelName = ((attr = decoder.getAttribute("replacementModel")) != null ? attr.getValue() : null);
String replacementFamilyName = ((attr = decoder.getAttribute("replacementFamily")) != null ? attr.getValue() : ParentReplacementFamilyName);
int numFns = ((attr = decoder.getAttribute("numFns")) != null ? Integer.parseInt(attr.getValue()) : -1);
Expand All @@ -533,16 +539,16 @@ void readFamily(Element family) {
for (int j = 0; j < vcodes.size(); j++) {
// for each versionCV element
Element vcv = vcodes.get(j);
String vLoVersID = ((attr = vcv.getAttribute("lowVersionID")) != null ? attr.getValue() : loVersID);
String vHiVersID = ((attr = vcv.getAttribute("highVersionID")) != null ? attr.getValue() : hiVersID);
String vLoVersID = ((attr = vcv.getAttribute(LOW_VERSION_ID)) != null ? attr.getValue() : loVersID);
String vHiVersID = ((attr = vcv.getAttribute(HIGH_VERSION_ID)) != null ? attr.getValue() : hiVersID);
df.setVersionRange(vLoVersID, vHiVersID);
}
}
}

public void writeFile(String name, DecoderIndexFile oldIndex, String files[]) throws java.io.IOException {
public void writeFile(String name, DecoderIndexFile oldIndex, String[] files) throws java.io.IOException {
if (log.isDebugEnabled()) {
log.debug("writeFile " + name);
log.debug("writeFile {}",name);
}
// This is taken in large part from "Java and XML" page 368
File file = new File(FileUtil.getUserFilesPath() + name);
Expand All @@ -566,8 +572,8 @@ public void writeFile(String name, DecoderIndexFile oldIndex, String files[]) th

// add top-level elements
Element index;
root.addContent(index = new Element("decoderIndex"));
index.setAttribute("version", Integer.toString(fileVersion));
root.addContent(index = new Element(DECODER_INDEX));
index.setAttribute(VERSION, Integer.toString(fileVersion));
log.debug("version written to file as {}", fileVersion);

// add mfg list from existing DecoderIndexFile item
Expand All @@ -584,19 +590,19 @@ public void writeFile(String name, DecoderIndexFile oldIndex, String files[]) th
}

// We treat "NMRA" special...
Element mfg = new Element("manufacturer");
Element mfg = new Element(MANUFACTURER);
mfg.setAttribute("mfg", "NMRA");
mfg.setAttribute("mfgID", "999");
mfg.setAttribute(MFG_ID, "999");
mfgList.addContent(mfg);
// start working on the rest of the entries
List<String> keys = new ArrayList<>(oldIndex._mfgIdFromNameHash.keySet());
Collections.sort(keys);
for (Object item : keys) {
String mfgName = (String) item;
if (!mfgName.equals("NMRA")) {
mfg = new Element("manufacturer");
mfg = new Element(MANUFACTURER);
mfg.setAttribute("mfg", mfgName);
mfg.setAttribute("mfgID", oldIndex._mfgIdFromNameHash.get(mfgName));
mfg.setAttribute(MFG_ID, oldIndex._mfgIdFromNameHash.get(mfgName));
mfgList.addContent(mfg);
}
}
Expand Down Expand Up @@ -645,14 +651,14 @@ protected static String defaultDecoderIndexFilename() {
return DECODER_INDEX_FILE_NAME;
}

static final protected String DECODER_INDEX_FILE_NAME = "decoderIndex.xml";
private final static Logger log = LoggerFactory.getLogger(DecoderIndexFile.class);
protected static final String DECODER_INDEX_FILE_NAME = "decoderIndex.xml";
private static final Logger log = LoggerFactory.getLogger(DecoderIndexFile.class);

@ServiceProvider(service = InstanceInitializer.class)
public static class Initializer extends AbstractInstanceInitializer {

@Override
public <T> Object getDefault(Class<T> type) throws IllegalArgumentException {
public <T> Object getDefault(Class<T> type) {
if (type.equals(DecoderIndexFile.class)) {
// create and load
DecoderIndexFile instance = new DecoderIndexFile();
Expand Down

0 comments on commit 58e8e1e

Please sign in to comment.