Improved recycling of HashMaps
This commit is contained in:
parent
c2f12d146e
commit
c90a22cc7b
10 changed files with 67 additions and 50 deletions
|
@ -135,24 +135,16 @@ public class BodyTabController implements Initializable {
|
|||
try {
|
||||
switch (dashboardState.getContentType()) {
|
||||
case MediaType.TEXT_PLAIN:
|
||||
rawInputArea.setText(dashboardState.getBody());
|
||||
rawInputTypeBox.getSelectionModel().select("PLAIN TEXT");
|
||||
bodyTabPane.getSelectionModel().select(rawTab);
|
||||
setRawTab(dashboardState, "PLAIN TEXT");
|
||||
break;
|
||||
case MediaType.APPLICATION_JSON:
|
||||
rawInputArea.setText(dashboardState.getBody());
|
||||
rawInputTypeBox.getSelectionModel().select("JSON");
|
||||
bodyTabPane.getSelectionModel().select(rawTab);
|
||||
setRawTab(dashboardState, "JSON");
|
||||
break;
|
||||
case MediaType.APPLICATION_XML:
|
||||
rawInputArea.setText(dashboardState.getBody());
|
||||
rawInputTypeBox.getSelectionModel().select("XML");
|
||||
bodyTabPane.getSelectionModel().select(rawTab);
|
||||
setRawTab(dashboardState, "XML");
|
||||
break;
|
||||
case MediaType.TEXT_HTML:
|
||||
rawInputArea.setText(dashboardState.getBody());
|
||||
rawInputTypeBox.getSelectionModel().select("HTML");
|
||||
bodyTabPane.getSelectionModel().select(rawTab);
|
||||
setRawTab(dashboardState, "HTML");
|
||||
break;
|
||||
case MediaType.MULTIPART_FORM_DATA:
|
||||
// For file tuples
|
||||
|
@ -178,4 +170,10 @@ public class BodyTabController implements Initializable {
|
|||
Services.loggingService.logInfo("Dashboard loaded with blank request body.", LocalDateTime.now());
|
||||
}
|
||||
}
|
||||
|
||||
private void setRawTab(DashboardState dashboardState, String contentType) {
|
||||
rawInputArea.setText(dashboardState.getBody());
|
||||
rawInputTypeBox.getSelectionModel().select(contentType);
|
||||
bodyTabPane.getSelectionModel().select(rawTab);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ public class DashboardController implements Initializable {
|
|||
private GETRequest getRequest;
|
||||
private DataDispatchRequest dataRequest;
|
||||
private DELETERequest deleteRequest;
|
||||
private HashMap<String, String> params;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle rb) {
|
||||
|
@ -190,7 +191,7 @@ public class DashboardController implements Initializable {
|
|||
getRequest = new GETRequest();
|
||||
|
||||
getRequest.setTarget(addressField.getText());
|
||||
getRequest.setHeaders(headerTabController.getHeaders());
|
||||
getRequest.setHeaders(headerTabController.getSelectedHeaders());
|
||||
|
||||
requestManager = Services.pool.get();
|
||||
requestManager.setRequest(getRequest);
|
||||
|
@ -207,7 +208,7 @@ public class DashboardController implements Initializable {
|
|||
|
||||
dataRequest.setRequestType(httpMethodBox.getValue());
|
||||
dataRequest.setTarget(addressField.getText());
|
||||
dataRequest.setHeaders(headerTabController.getHeaders());
|
||||
dataRequest.setHeaders(headerTabController.getSelectedHeaders());
|
||||
|
||||
if (bodyTabController.rawTab.isSelected()) {
|
||||
String contentType;
|
||||
|
@ -253,7 +254,7 @@ public class DashboardController implements Initializable {
|
|||
deleteRequest = new DELETERequest();
|
||||
|
||||
deleteRequest.setTarget(addressField.getText());
|
||||
deleteRequest.setHeaders(headerTabController.getHeaders());
|
||||
deleteRequest.setHeaders(headerTabController.getSelectedHeaders());
|
||||
|
||||
requestManager = Services.pool.delete();
|
||||
requestManager.setRequest(deleteRequest);
|
||||
|
@ -430,8 +431,10 @@ public class DashboardController implements Initializable {
|
|||
}
|
||||
|
||||
private HashMap<String, String> getParams() {
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
if (params == null)
|
||||
params = new HashMap<>();
|
||||
|
||||
params.clear();
|
||||
for (StringKeyValueFieldController controller : paramsControllers)
|
||||
if (controller.isChecked())
|
||||
params.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
|
@ -500,7 +503,7 @@ public class DashboardController implements Initializable {
|
|||
case "PUT":
|
||||
case "PATCH":
|
||||
dashboardState = new DashboardState(bodyTabController.getBasicRequest(httpMethodBox.getValue()));
|
||||
dashboardState.setHeaders(headerTabController.getHeaders());
|
||||
dashboardState.setHeaders(headerTabController.getSelectedHeaders());
|
||||
break;
|
||||
default:
|
||||
// For GET, DELETE requests
|
||||
|
@ -513,7 +516,7 @@ public class DashboardController implements Initializable {
|
|||
Services.loggingService.logInfo("Dashboard state was saved with an invalid URL.", LocalDateTime.now());
|
||||
}
|
||||
dashboardState.setHttpMethod(httpMethodBox.getValue());
|
||||
dashboardState.setHeaders(headerTabController.getHeaders());
|
||||
dashboardState.setHeaders(headerTabController.getSelectedHeaders());
|
||||
dashboardState.setParams(getParams());
|
||||
|
||||
return dashboardState;
|
||||
|
|
|
@ -44,6 +44,9 @@ public class FormDataTabController implements Initializable {
|
|||
private List<FileKeyValueFieldController> fileControllers;
|
||||
private IntegerProperty fileControllersCount, stringControllersCount;
|
||||
|
||||
private HashMap<String, String> stringMap;
|
||||
private HashMap<String, String> fileMap;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
stringControllers = new ArrayList<>();
|
||||
|
@ -56,24 +59,22 @@ public class FormDataTabController implements Initializable {
|
|||
addStringField();
|
||||
}
|
||||
|
||||
private void addFileField() {
|
||||
addFileField("", "", null);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addFileField(ActionEvent event) {
|
||||
addFileField("", "", event);
|
||||
}
|
||||
|
||||
private void addFileField() {
|
||||
addFileField("", "", null);
|
||||
}
|
||||
|
||||
public void addFileField(String key, String value) {
|
||||
addFileField(key, value, null);
|
||||
}
|
||||
|
||||
private void addFileField(String key, String value, ActionEvent event) {
|
||||
/*
|
||||
Re-uses previous field if it is empty,
|
||||
else loads a new one.
|
||||
*/
|
||||
//Re-uses previous field if it is empty else loads a new one.
|
||||
if (fileControllers.size() > 0 && event == null) {
|
||||
FileKeyValueFieldController previousController = fileControllers.get(fileControllers.size() - 1);
|
||||
|
||||
|
@ -106,15 +107,15 @@ public class FormDataTabController implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
private void addStringField() {
|
||||
addStringField("", "", null);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void addStringField(ActionEvent event) {
|
||||
addStringField("", "", event);
|
||||
}
|
||||
|
||||
private void addStringField() {
|
||||
addStringField("", "", null);
|
||||
}
|
||||
|
||||
public void addStringField(String key, String value) {
|
||||
addStringField(key, value, null);
|
||||
}
|
||||
|
@ -156,20 +157,26 @@ public class FormDataTabController implements Initializable {
|
|||
}
|
||||
|
||||
public HashMap<String, String> getStringTuples() {
|
||||
HashMap<String, String> tuples = new HashMap<>();
|
||||
if (stringMap == null)
|
||||
stringMap = new HashMap<>();
|
||||
|
||||
stringMap.clear();
|
||||
for (StringKeyValueFieldController controller : stringControllers) {
|
||||
if (controller.isChecked())
|
||||
tuples.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
stringMap.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
}
|
||||
return tuples;
|
||||
return stringMap;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getFileTuples() {
|
||||
HashMap<String, String> tuples = new HashMap<>();
|
||||
if (fileMap == null)
|
||||
fileMap = new HashMap<>();
|
||||
|
||||
fileMap.clear();
|
||||
for (FileKeyValueFieldController controller : fileControllers) {
|
||||
if (controller.isChecked())
|
||||
tuples.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
fileMap.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
}
|
||||
return tuples;
|
||||
return fileMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ public class HeaderTabController implements Initializable {
|
|||
private List<StringKeyValueFieldController> controllers;
|
||||
private IntegerProperty controllersCount;
|
||||
|
||||
private HashMap<String, String> headers;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
controllers = new ArrayList<>();
|
||||
|
@ -100,9 +102,14 @@ public class HeaderTabController implements Initializable {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the selected headers.
|
||||
*/
|
||||
public HashMap<String, String> getSelectedHeaders() {
|
||||
if (headers == null)
|
||||
headers = new HashMap<>();
|
||||
|
||||
public HashMap<String, String> getHeaders() {
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
headers.clear();
|
||||
for (StringKeyValueFieldController controller : controllers) {
|
||||
if (controller.isChecked())
|
||||
headers.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
|
|
|
@ -42,6 +42,7 @@ public class URLTabController implements Initializable {
|
|||
|
||||
private List<StringKeyValueFieldController> controllers;
|
||||
private IntegerProperty controllersCount;
|
||||
private HashMap<String, String> tuples;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
|
@ -101,11 +102,14 @@ public class URLTabController implements Initializable {
|
|||
}
|
||||
|
||||
public HashMap<String, String> getStringTuples() {
|
||||
HashMap<String, String> headers = new HashMap<>();
|
||||
if (tuples == null)
|
||||
tuples = new HashMap<>();
|
||||
|
||||
tuples.clear();
|
||||
for (StringKeyValueFieldController controller : controllers) {
|
||||
if (controller.isChecked())
|
||||
headers.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
tuples.put(controller.getHeader().getKey(), controller.getHeader().getValue());
|
||||
}
|
||||
return headers;
|
||||
return tuples;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,12 +58,13 @@ class Visualizer extends ScrollPane {
|
|||
|
||||
if (root.isArray()) {
|
||||
Iterator<JsonNode> iterator = root.elements();
|
||||
int i = 0;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
currentNode = iterator.next();
|
||||
|
||||
if (currentNode.isValueNode()) {
|
||||
valueLabel = new Label(currentNode.toString());
|
||||
valueLabel = new Label(i++ + ": " + currentNode.toString());
|
||||
valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
|
||||
valueLabel.setWrapText(true);
|
||||
valueTooltip = new Tooltip(currentNode.toString());
|
||||
|
@ -74,7 +75,7 @@ class Visualizer extends ScrollPane {
|
|||
} else if (currentNode.isObject()) {
|
||||
TreeItem<HBox> newRoot = new TreeItem<>();
|
||||
items.add(newRoot);
|
||||
populate(newRoot, "[Anonymous Object]", currentNode);
|
||||
populate(newRoot, i++ + ": [Anonymous Object]", currentNode);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -61,8 +61,8 @@ public class HistoryManager {
|
|||
/**
|
||||
* Creates and initializes the database with necessary tables if not already done.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws SQLException
|
||||
* @throws IOException - If unable to establish a connection to the database.
|
||||
* @throws SQLException - If invalid statement is executed on the database.
|
||||
*/
|
||||
private void initDatabase() throws IOException, SQLException {
|
||||
// Read all queries from Queries.json
|
||||
|
|
|
@ -31,5 +31,5 @@ public class Settings {
|
|||
public static int connectionReadTimeOut = 30000;
|
||||
|
||||
public static String theme = "Adreana";
|
||||
public static int showHistoryRange = 3;
|
||||
public static int showHistoryRange = 7;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package com.rohitawate.everest.util.settings;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rohitawate.everest.util.EverestUtilities;
|
||||
import com.rohitawate.everest.util.Services;
|
||||
|
||||
|
@ -44,8 +43,7 @@ public class SettingsLoader implements Runnable {
|
|||
|
||||
System.out.println("Settings file found. Loading settings... ");
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
nodes = mapper.readTree(settingsFile);
|
||||
nodes = EverestUtilities.mapper.readTree(settingsFile);
|
||||
|
||||
Settings.responseAreaFont = setStringSetting(Settings.responseAreaFont, "responseAreaFont");
|
||||
Settings.responseAreaFontSize = setIntegerSetting(Settings.responseAreaFontSize, "responseAreaFontSize");
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
|
||||
public class ThemeManager {
|
||||
private static List<Parent> parentNodes = new ArrayList<>();
|
||||
private static File themeFile = new File("Everest/themes/" + Settings.theme + ".css");
|
||||
|
||||
/**
|
||||
* Refreshes the theme of all the registered parents by replacing
|
||||
|
@ -35,7 +36,6 @@ public class ThemeManager {
|
|||
*/
|
||||
public static void refreshTheme() {
|
||||
if (!Settings.theme.equals("Adreana")) {
|
||||
File themeFile = new File("Everest/themes/" + Settings.theme + ".css");
|
||||
if (themeFile.exists()) {
|
||||
String themePath = themeFile.toURI().toString();
|
||||
|
||||
|
@ -53,7 +53,6 @@ public class ThemeManager {
|
|||
|
||||
public static void setTheme(Parent parent) {
|
||||
if (!Settings.theme.equals("Adreana")) {
|
||||
File themeFile = new File("Everest/themes/" + Settings.theme + ".css");
|
||||
if (themeFile.exists()) {
|
||||
parent.getStylesheets().add(themeFile.toURI().toString());
|
||||
parentNodes.add(parent);
|
||||
|
|
Loading…
Reference in a new issue