summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java11
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java23
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java16
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java24
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java20
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java13
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/parserutils/StackBasedConfigReader.java37
10 files changed, 125 insertions, 46 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
index 014c298..037b2b6 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IList.java
@@ -28,6 +28,14 @@ public interface IList<ContainedType> {
*/
boolean add(ContainedType item);
+ /**
+ * Add all of the elements in the provided list to this list
+ *
+ * @param items
+ * The list of items to add
+ * @return True if every item was succesfully added to the list, false
+ * otherwise
+ */
default boolean addAll(IList<ContainedType> items) {
return items.map(this::add).anyMatch((bl) -> bl == false);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
index 8522058..e69495a 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcdata/IMap.java
@@ -73,6 +73,17 @@ public interface IMap<KeyType, ValueType> {
*/
ValueType get(KeyType key);
+ /**
+ * Get a value from the map, and return a default value if the key
+ * doesn't exist
+ *
+ * @param key
+ * The key to attempt to retrieve
+ * @param defaultValue
+ * The value to return if the key doesn't exist
+ * @return The value associated with the key, or the default value if
+ * the key doesn't exist
+ */
default ValueType getOrDefault(KeyType key, ValueType defaultValue) {
try {
return get(key);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
index cafa80f..94571f5 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/ListUtils.java
@@ -219,10 +219,8 @@ public class ListUtils {
/*
* Run up to a certain number of passes
*/
- for (int numberOfIterations = 0;
- numberOfIterations < MAX_NTRIESPART
- && !rejectedElements.isEmpty();
- numberOfIterations++) {
+ for (int numberOfIterations = 0; numberOfIterations < MAX_NTRIESPART
+ && !rejectedElements.isEmpty(); numberOfIterations++) {
input.forEach(new GroupPartIteration<>(returnedList,
currentPartition, rejectedElements,
numberInCurrentPartition, numberPerPartition,
@@ -266,6 +264,23 @@ public class ListUtils {
return returnedList;
}
+ /**
+ * Pad the provided list out to the desired size
+ *
+ * @param <E>
+ * The type of elements in the list
+ * @param list
+ * The list to pad out
+ * @param counter
+ * The function to count elements with
+ * @param size
+ * The desired size of the list
+ * @param padSource
+ * The function to get elements to pad with
+ * @return The list, padded to the desired size
+ * @throws IllegalArgumentException
+ * if the list couldn't be padded to the desired size
+ */
public static <E> IList<E> padList(IList<E> list,
Function<E, Integer> counter, int size,
Supplier<E> padSource) {
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java
index 61c6702..a7f2183 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/SimpleInternalFrame.java
@@ -2,13 +2,28 @@ package bjc.utils.gui;
import javax.swing.JInternalFrame;
+/**
+ * A simple internal frame class
+ *
+ * @author ben
+ *
+ */
public class SimpleInternalFrame extends JInternalFrame {
private static final long serialVersionUID = -2966801321260716617L;
+ /**
+ * Create a new blank internal frame
+ */
public SimpleInternalFrame() {
super();
}
+ /**
+ * Create a new blank internal frame with a specific title
+ *
+ * @param title
+ * The title of the internal frame
+ */
public SimpleInternalFrame(String title) {
super(title);
}
@@ -22,5 +37,4 @@ public class SimpleInternalFrame extends JInternalFrame {
setMaximizable(true);
setIconifiable(true);
}
-
} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java
index e512d6b..6080462 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/TextAreaOutputStream.java
@@ -13,6 +13,12 @@ public class TextAreaOutputStream extends OutputStream {
private JTextArea textArea;
+ /**
+ * Create a new output stream attached to a textarea
+ *
+ * @param console
+ * The textarea to write to
+ */
public TextAreaOutputStream(JTextArea console) {
this.textArea = console;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java
index 2231760..c98eea3 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/DropdownListPanel.java
@@ -13,10 +13,27 @@ import bjc.utils.funcdata.IList;
import bjc.utils.gui.layout.AutosizeLayout;
import bjc.utils.gui.layout.HLayout;
+/**
+ * A panel that allows you to select choices from a dropdown list
+ *
+ * @author ben
+ *
+ */
public class DropdownListPanel extends JPanel {
private static final long serialVersionUID = 2719963952350133541L;
- @SuppressWarnings("unchecked")
+ /**
+ * Create a new dropdown list panel
+ *
+ * @param <T>
+ * The type of items in the dropdown list
+ * @param itemType
+ * The label of the type of items in the list
+ * @param listModel
+ * The model to put items into
+ * @param choices
+ * The items to choose from
+ */
public <T> DropdownListPanel(String itemType,
DefaultListModel<T> listModel, IList<T> choices) {
setLayout(new AutosizeLayout());
@@ -41,7 +58,8 @@ public class DropdownListPanel extends JPanel {
JButton removeItemButton = new JButton("Remove " + itemType);
addItemButton.addActionListener((ev) -> {
- listModel.addElement((T) addItemBox.getSelectedItem());
+ listModel.addElement(
+ addItemBox.getItemAt(addItemBox.getSelectedIndex()));
});
removeItemButton.addActionListener((ev) -> {
@@ -54,4 +72,4 @@ public class DropdownListPanel extends JPanel {
add(itemInputPanel);
}
-}
+} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java
index fd981ec..eb900aa 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleInputPanel.java
@@ -6,11 +6,24 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
+/**
+ * A simple component for text input
+ * @author ben
+ *
+ */
public class SimpleInputPanel extends JPanel {
private static final long serialVersionUID = -4734279623645236868L;
+ /**
+ * The text field containing the input value
+ */
public final JTextField inputValue;
+ /**
+ * Create a new input panel
+ * @param label The label for the field
+ * @param columns The number of columns of text input to take
+ */
public SimpleInputPanel(String label, int columns) {
setLayout(new BorderLayout());
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java
index 62aac0d..e034b48 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleListPanel.java
@@ -15,6 +15,12 @@ import javax.swing.ListSelectionModel;
import bjc.utils.gui.layout.AutosizeLayout;
import bjc.utils.gui.layout.HLayout;
+/**
+ * A simple list of strings
+ *
+ * @author ben
+ *
+ */
public class SimpleListPanel extends JPanel {
private static final long serialVersionUID = 2719963952350133541L;
@@ -33,6 +39,18 @@ public class SimpleListPanel extends JPanel {
addItemField.setText("");
}
+ /**
+ * Create a new list panel
+ *
+ * @param itemType
+ * The type of things in the list
+ * @param listModel
+ * The model to put items into
+ * @param itemVerifier
+ * The predicate to use to verify items
+ * @param onVerificationFailure
+ * The function to call when an item doesn't verify
+ */
public SimpleListPanel(String itemType,
DefaultListModel<String> listModel,
Predicate<String> itemVerifier,
@@ -78,4 +96,4 @@ public class SimpleListPanel extends JPanel {
add(itemInputPanel);
}
-}
+} \ No newline at end of file
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java
index 7bbf83e..7b138c5 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/gui/panels/SimpleSpinnerPanel.java
@@ -7,11 +7,24 @@ import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
+/**
+ * A simple spinner control
+ * @author ben
+ *
+ */
public class SimpleSpinnerPanel extends JPanel {
private static final long serialVersionUID = -4734279623645236868L;
+ /**
+ * The spinner being used
+ */
public final JSpinner inputValue;
+ /**
+ * Create a new spinner panel
+ * @param label The label for the spinner
+ * @param model The model to attach to the spinner
+ */
public SimpleSpinnerPanel(String label, SpinnerModel model) {
setLayout(new BorderLayout());
diff --git a/BJC-Utils2/src/main/java/bjc/utils/parserutils/StackBasedConfigReader.java b/BJC-Utils2/src/main/java/bjc/utils/parserutils/StackBasedConfigReader.java
deleted file mode 100644
index 2d15711..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/parserutils/StackBasedConfigReader.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package bjc.utils.parserutils;
-
-/**
- * This class parses a config file written in RPN and uses it to construct
- * data items
- *
- * @author ben
- *
- * TODO implement me
- */
-public class StackBasedConfigReader {
- public static interface IItem {
- public ItemType getType();
- }
-
- /**
- * Represents the types of item that can be found on stacks
- *
- * @author ben
- *
- */
- public static enum ItemType {
- /**
- * Represents an integral number
- */
- INTEGER,
- /**
- * Represents a string of characters
- */
- STRING,
- /**
- * Represents an arbitrary object
- */
- OBJECT
- }
-
-}