verbose
verbose
JCHJava Community | Help. Code. Learn.
Created by verbose on 11/21/2024 in #java-help
How do I handle an assignment like this folder structure wise?
No description
35 replies
JCHJava Community | Help. Code. Learn.
Created by verbose on 5/16/2024 in #java-help
Would this Validation System work?
I have this validation system I wanted to implement for absolutely no reason what so ever other than waste my time but essentially it just validates objects that are going to be created. Say you are creating an class called Tenant and this tenant is using the builder pattern. before the Tenant object is created it would validate it which would look something like this:
// TODO Check this Method for Validity (Refactor if Necessary)
private void isValidTenantBuild() {
Validator<TenantBuilder> validator = Validator.of(this);

// FIXME Add More Rules for Tenant If Necessary
var tenantValid = validator
.addRule(t -> t.id != null, "Tenant ID is Required.")
.addRule(t -> t.name != null, "Tenant Name is Required.")
.addRule(t -> t.email != null, "Tenant Email is Required.")
.addRule(t -> t.phone != null, "Tenant Phone is Required.")
.addRule(t -> t.address != null, "Tenant Address is Required.")
.addRule(t -> t.lease != null, "Tenant Lease is Required.")
.getErrors();
}
// TODO Check this Method for Validity (Refactor if Necessary)
private void isValidTenantBuild() {
Validator<TenantBuilder> validator = Validator.of(this);

// FIXME Add More Rules for Tenant If Necessary
var tenantValid = validator
.addRule(t -> t.id != null, "Tenant ID is Required.")
.addRule(t -> t.name != null, "Tenant Name is Required.")
.addRule(t -> t.email != null, "Tenant Email is Required.")
.addRule(t -> t.phone != null, "Tenant Phone is Required.")
.addRule(t -> t.address != null, "Tenant Address is Required.")
.addRule(t -> t.lease != null, "Tenant Lease is Required.")
.getErrors();
}
for the cove above its just a simple example of what you can do but it should work with different datatypes (primitive or reference) with their own set of rules.
12 replies
JCHJava Community | Help. Code. Learn.
Created by verbose on 12/3/2023 in #java-help
Communicating between multiple Controllers JavaFX FXML
No description
6 replies
JCHJava Community | Help. Code. Learn.
Created by verbose on 11/23/2023 in #java-help
Creating a REST API with oracledb
No description
22 replies
JCHJava Community | Help. Code. Learn.
Created by verbose on 10/16/2022 in #java-help
HashMap with Objects
I have created a HashMap that follows the pairing :
<String, Object>
<String, Object>
and it functions as a data holder for most of the String: Object pairs I intend to add into it. Purpose I am creating a program that allows user input on determining whether a certain word is the correct opposite (antonym which is inputted by the user). For example, I would request the user to input the opposite of absent ; The possibilities are as follows: 1.
Correct Absent : Present (or any related antonym) : Absent ✔️
Correct Absent : Present (or any related antonym) : Absent ✔️
or 2.
Incorrect Absent : Zebra : Absent ❌
Incorrect Absent : Zebra : Absent ❌
My code for creating the HashMap of <String, Object> pairs is as follows:
public static HashMap<String, Object> commonOpposites = new HashMap<>() {{
put("absent", List.of("present", "alert", "attentive")); put("accurate", "inaccurate");
}};
public static HashMap<String, Object> commonOpposites = new HashMap<>() {{
put("absent", List.of("present", "alert", "attentive")); put("accurate", "inaccurate");
}};
Question How would I access anything within the List reference? If I were to check if user input is in fact one of the elements within the List, would I use contains() within a if statement? I appreciate all the help and support for anyone who can look into this!
10 replies
JCHJava Community | Help. Code. Learn.
Created by verbose on 10/15/2022 in #java-help
Obtain Value from nested Hashtable Map
I am creating a program that initially uses nested Hashtables in the format:
public static Hashtable<Integer, Map<String, String>> commonOpposites = new Hashtable<>(){{...}};
public static Hashtable<Integer, Map<String, String>> commonOpposites = new Hashtable<>(){{...}};
Purpose The functionality of the nested hashtable is to hold values of 'common opposites' (antonyms for clarity). I have already structured most of the code to put values within the hashtable but I am having a difficult time figuring out how to obtain only values within the
key : {key = value}
key : {key = value}
format of the nested hashtable. Here is how I placed values into the table (I put them in pairs of 2 for ease of readability):
public static Hashtable<Integer, Map<String, String>> commonOpposites = new Hashtable<>(){{
put(1, Map.of("absent", "present")); put(2, Map.of("accurate", "inaccurate"));
put(3, Map.of("against", "for")); put(4, Map.of("all", "none"));
...
}};
public static Hashtable<Integer, Map<String, String>> commonOpposites = new Hashtable<>(){{
put(1, Map.of("absent", "present")); put(2, Map.of("accurate", "inaccurate"));
put(3, Map.of("against", "for")); put(4, Map.of("all", "none"));
...
}};
I am not even sure if this is the best way to write code like this, however, I have tried using for loops with Entry, tried using built in functions and looked at examples like:
Map map = new HashMap();
((Map)map.get( "keyname" )).get( "nestedkeyname" );
Map map = new HashMap();
((Map)map.get( "keyname" )).get( "nestedkeyname" );
I am not sure how I would access them, if someone could explain to me the complexities of something like this, it would mean a lot!
24 replies