SlideShare a Scribd company logo
1 of 33
Download to read offline
1
Take a Trip Into the Forest - A Java Primer on
Maps, Trees, and Collections
• Certified Lotus Instructor since R3
• Co-founded TLCC in 1987
• IBM Champion
• Prior to that 12 years at IBM in the PC group
• Also…
– Certified Public Accountant
– Certified Information Systems Auditor (CISA)
– Certified Flight Instructor
2
3
• Private classes at
your location or
virtual
•XPages Development
•Support Existing Apps
•Administration
• Let us help you
become an expert
XPages developer!
• Delivered via Notes
• XPages
• Development
• Admin
• User
Self-
Paced
Courses
Mentorin
g
Instructor-
Led
Classes
Application
Developmen
t and
Consulting
Free
Demo
Courses!
• Let us help with your development needs
– Bootstrap
– Java
• Convert Notes Apps to mobile and the web!
• Modernize old Domino web applications
• Interface with backend data systems
• Skills transfer
4
• Why Use Java Objects in Xpages?
• Introduction to Managed Beans
• Scoped Variables in SSJS
• Introduction to Maps
• The DataObject Implementation
• A Reporting Example
• Questions???
5
• Performance (see my recorded webinar)
• Reporting
– Easily combine data from different sources
• Portability
– Back end
– Front end
• Code Maintenance
• Lots of code/knowledge out there
6
• The XPages runtime manages the creation of your
“managed bean”
– Request, View, Session, or Application scope
• Refer to methods on your XPages or from other Java
code
• How to:
– Create an entry in the Faces-Config file
– Create your Java code
• Getters and Setters
• No argument constructor
• Don’t have to use Managed Beans!
7
SampleBean.java
SampleBeanDemo.xsp
• sessionScope.testName
– read/write to a variable that is session scope
• Can store anything (string, Boolean, date, array, etc)
– Just don’t store Domino objects
• Why do we care???
– Scoped variables are stored as HashMaps
– Another way to access is:
• sessionScope.get(“testName”)
• sessionScope.put(“testName” , “A value”)
• Same as a Java Hash Map
– Let’s Learn more about these HashMaps!
8
• Collections is a Framework/root interface
– Architecture for representing collections
• Has Interfaces, Implementations, Algorithms
• Interfaces
– Abstract Data Type
– Defines a base used by all the classes that implement
• An interface in Java is similar to a class, but the body of
an interface can include only abstract methods and final fields
(constants). A class implements an interface by providing code for each
method declared by the interface.
• Implementations
– A class that uses an interface (we use this!)
9
10
11
12
Java documentation on HashMap
• Set, SortedSet
– No duplicate elements
• HashSet, TreeSet, LinkedHashSet
• List
– Allows duplicates
– Ordered
• ArrayList, LinkedList
• Map, SortedMap
– Key/Value pairs
• HashMap, LinkedHashMap, TreeMap
13
14
• Goal
– Store configuration information
– Managed Bean with Application Scope
• Best choice is a HashMap
– Why? Back to the previous chart!
– Access values with a key
15
• Creation
private HashMap<String,String> configData = new HashMap<String,
String>();
• Set a value
configData.put(key ,value);
• Get a value (and test to see if key is there)
public String getConfig(String key) {
String rtnString = "";
if (this.configData.containsKey(key)){
rtnString = this.configData.get(key);
}
return rtnString;
}
16
1. Notes view/form to hold configuration data
2. Create new Java Class
3. Add Managed Bean to faces-config
– Set scope as needed
4. Implement Serializable in the Java class
5. Create “private” variable for HashMap
6. Create constructor to initialize data
– Walk the view to load up the keys/values
7. Generate Getter/Setter
8. Use on XPage or in other Java code
17
ConfigBean.java
ConfigBeanDemo.xsp
• Get all the keys as a Set
– statesHashMap.keySet()
• Get all the values as a Set
– statesHashMap.values()
• Get the key and value as a Set
– statesHashMap.entrySet()
• Get the key with getKey() and the value with getValue()
18
for (Entry<String, String> state :statesHashMap.entrySet()){
myString = state.getValue() + "|" + state.getKey() ;
debugMsg(myString);
}
• A HashMap does not keep the insertion order (random)
• Need to keeps insertion order?  LinkedHashMap
• Good when loading data from a Notes view (that is
ordered already)
– Keeps same (insertion) order
• Otherwise basically the same as HashMap
19
• A list of objects (like an Array)
– Hold any data type/object
– Can search the values
– Can access an element in a certain position
• Perfect for feeding to:
– Values in a combo box, list box, etc.
– Repeats
– Data Tables
• To add at end:
– rtnList.add(stateLine);
20
• Stop doing @DbColumns
– Slow!
• Load values from a view, store in memory
– FAST!
• Use Expression Language
– configBean.statesHashMap
• Use same ConfigBean as before (application scope)
– Method in Java is getStatesHashMap()
– Returns a List
21
ConfigBean.java
ConfigBeanDemo.xsp
• Do you Recycle?
– View looping
– NotesDateTime?
– columnValues with a Date creates NotesDateTime objects
• Instead use the Domino API
– Simpler code patterns
– Never have to worry about recycle
– Try/Catch block not required
– Support for logging
– Lots of cool new stuff
• Available on OpenNTF – Link to version 3
– Get help via Slack/Stack Overflow
22
23
private void initBean(Database curDb, String viewName) {
try {
View setupVw = curDb.getView(viewName);
String key = "";
String value = "";
ViewEntry tempEntry;
if (setupVw != null) {
ViewEntryCollection vwEntryCol = setupVw.getAllEntries();
ViewEntry entryDoc = vwEntryCol.getFirstEntry();
while (entryDoc != null){
Vector<?> colValues = entryDoc.getColumnValues();
key = (String) colValues.elementAt(0);
value = (String) colValues.elementAt(1);
this.configData.put(key , value);
tempEntry = vwEntryCol.getNextEntry(entryDoc);
entryDoc.recycle();
entryDoc = tempEntry;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
24
private void initBean(Database curDb, String viewName) {
View setupVw = curDb.getView(viewName);
String key = "";
String value = "";
if (setupVw != null) {
for (ViewEntry entryDoc : setupVw.getAllEntries()){
Vector<?> colValues = entryDoc.getColumnValues();
key = (String) colValues.elementAt(0);
value = (String) colValues.elementAt(1);
this.configData.put(key , value);
}
}
}
No Recycle!
Uses a for loop
No Try/Catch block
ConfigBean2.java
DomAPIDemo.xsp
• Use Case
– Get a list of values always sorted by the value
• “Natural” sort order
– No duplicates
• TreeSet!
• Good for looping through a view, getting a value
from a column
– Add to TreeSet and then you always have a
sorted, unique list
25
TreeSetBean.java
TreeSetBeanDemo.xsp
• Suppose you don’t want the “natural” order???
– Use a custom sort when defining the TreeSet
– Comparator function
– Will always sort using this new sort definition
26
public List<String> getArizonaTownsReversed() {
TreeSet<String> sorted = new TreeSet<String>(new Comparator<String>() {
public int compare(String o1, String o2) {
return o2.compareTo(o1);
}
});
sorted.addAll(ArizonaTowns);
return new ArrayList<String>(sorted);
}
TreeSetBean.java
TreeSetBeanDemo.xsp
• Use a TreeMap
– Key,Value pair
• In this case, a state is the key, a list of towns
(TreeSet) is the value
– Sorted on the Key value, natural order
27
• Way to implement an interface that works well with
the Expression Language
– Any data type
– Must implement certain methods
28
DataObjectBean.java
DataObjectBeanDemo.xsp
• Goal is to store information in the bean to allow fast
filtering and sorting
• Base storage is a LinkedHashMap
– Key is the city name
– Values are an ArrayList
• The ArrayList holds a Person object
–First and last name, city, state, email, etc.
–Universal doc id to retrieve Notes document
29
30
Houston
LinkedHashMap<String,ArrayList
<Person>> customers
Key is City Name
Lorie Mason
Brad Hunt
Jessie Lang
Mark Travis
firstName
lastName
City
State
eMail
Notes ID
DocUNID
Person ObjectDallas
Austin
ArrayList<Person>
The customers HashMap
stores all the people from a
selected state
ReportBean.java
ReportBeanDemo.xsp
• Methods of the Bean are used to:
– Return data as an ArrayList to a Repeat
• Sorted (last name, city, email)
• Filter on a city or show all
– Switch to a different state
– Get the cities for the selected state (unique, ordered)
– Store information like:
• City filter
• Desired sorting
• Ascending or Descending sorting
31
• TLCC’s Java Classes (two)
http://www.tlcc.com/admin/tlccsite.nsf/coursedetails.xsp?ccode=ND9XJVKPG
• My Session on Xpages Performance (recorded)
– October, 2015
http://www.tlcc.com/admin/tlccsite.nsf/pages/recorded-xpages-
webinars?opendocument
• List of Collections with a summary of features
– http://www.janeve.me/articles/which-java-collection-to-use
• The Sun Java documentation (version 6, aka 1.6)
• StackOverflow
• Google!!!
32
33
 Email: howardg@tlcc.com
 Twitter: @TLCCLtd
 Web: www.tlcc.com
Special Offer!!!
Save 20% on any TLCC course or package until 9/30
To take advantage of this offer or to download the demonstration databases
www.tlcc.com/mwlug

More Related Content

What's hot

NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
BigBlueHat
 
Introduction to Theme Preprocess Functions
Introduction to Theme Preprocess FunctionsIntroduction to Theme Preprocess Functions
Introduction to Theme Preprocess Functions
c4rl
 
Cloud foundry practice
Cloud foundry practiceCloud foundry practice
Cloud foundry practice
Sean Lee
 
Web Queries: From a Web of Data to a Semantic Web
Web Queries: From a Web of Data to a Semantic WebWeb Queries: From a Web of Data to a Semantic Web
Web Queries: From a Web of Data to a Semantic Web
Tim Furche
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
Hal Stern
 
Drupal is not your Website
Drupal is not your Website Drupal is not your Website
Drupal is not your Website
Phase2
 
Spring data
Spring dataSpring data
Spring data
Sean Lee
 

What's hot (20)

NoSQL into E-Commerce: lessons learned
NoSQL into E-Commerce: lessons learnedNoSQL into E-Commerce: lessons learned
NoSQL into E-Commerce: lessons learned
 
NoSQL: Why, When, and How
NoSQL: Why, When, and HowNoSQL: Why, When, and How
NoSQL: Why, When, and How
 
Electronic Grading of Paper Assessments
Electronic Grading of Paper AssessmentsElectronic Grading of Paper Assessments
Electronic Grading of Paper Assessments
 
PyCon 2011 Scaling Disqus
PyCon 2011 Scaling DisqusPyCon 2011 Scaling Disqus
PyCon 2011 Scaling Disqus
 
What's New in DITA 1.3
What's New in DITA 1.3What's New in DITA 1.3
What's New in DITA 1.3
 
ppt
pptppt
ppt
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combination
 
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
Theme preprocess functions: An Introduction (DrupalCamp NYC 10 2011)
 
NoSQL & JSON
NoSQL & JSONNoSQL & JSON
NoSQL & JSON
 
Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012Advanced Site Studio Class, June 18, 2012
Advanced Site Studio Class, June 18, 2012
 
Neo4j Training Cypher
Neo4j Training CypherNeo4j Training Cypher
Neo4j Training Cypher
 
Introduction to Theme Preprocess Functions
Introduction to Theme Preprocess FunctionsIntroduction to Theme Preprocess Functions
Introduction to Theme Preprocess Functions
 
Cloud foundry practice
Cloud foundry practiceCloud foundry practice
Cloud foundry practice
 
Web Queries: From a Web of Data to a Semantic Web
Web Queries: From a Web of Data to a Semantic WebWeb Queries: From a Web of Data to a Semantic Web
Web Queries: From a Web of Data to a Semantic Web
 
Indexes: The neglected performance all rounder
Indexes: The neglected performance all rounderIndexes: The neglected performance all rounder
Indexes: The neglected performance all rounder
 
Rewriting the Drupal Theme layer
Rewriting the Drupal Theme layerRewriting the Drupal Theme layer
Rewriting the Drupal Theme layer
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
Drupal is not your Website
Drupal is not your Website Drupal is not your Website
Drupal is not your Website
 
Essbase Statistics DW: How to Automatically Administrate Essbase Using ODI
Essbase Statistics DW: How to Automatically Administrate Essbase Using ODIEssbase Statistics DW: How to Automatically Administrate Essbase Using ODI
Essbase Statistics DW: How to Automatically Administrate Essbase Using ODI
 
Spring data
Spring dataSpring data
Spring data
 

Similar to MWLUG Session- AD112 - Take a Trip Into the Forest - A Java Primer on Maps, Trees, and Collections

Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic Syntax
Adil Jafri
 

Similar to MWLUG Session- AD112 - Take a Trip Into the Forest - A Java Primer on Maps, Trees, and Collections (20)

Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic Syntax
 
Skillwise - Enhancing dotnet app
Skillwise - Enhancing dotnet appSkillwise - Enhancing dotnet app
Skillwise - Enhancing dotnet app
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Java SE 8 - New Features
Java SE 8 - New FeaturesJava SE 8 - New Features
Java SE 8 - New Features
 
Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2Collections Framework Beginners Guide 2
Collections Framework Beginners Guide 2
 
Collections Framework Begineers guide 2
Collections Framework Begineers guide 2Collections Framework Begineers guide 2
Collections Framework Begineers guide 2
 
Java OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 4) - CollectionJava OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 4) - Collection
 
Data structure and algorithm.
Data structure and algorithm. Data structure and algorithm.
Data structure and algorithm.
 
Scaling Web Applications with Cassandra Presentation.ppt
Scaling Web Applications with Cassandra Presentation.pptScaling Web Applications with Cassandra Presentation.ppt
Scaling Web Applications with Cassandra Presentation.ppt
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Java
Java Java
Java
 
Jdbc Java Programming
Jdbc Java ProgrammingJdbc Java Programming
Jdbc Java Programming
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
Java 103
Java 103Java 103
Java 103
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
A brief tour of modern Java
A brief tour of modern JavaA brief tour of modern Java
A brief tour of modern Java
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 

More from Howard Greenberg

August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchAugust Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
Howard Greenberg
 
OpenNTF Webinar, May 19, 2020
OpenNTF Webinar, May 19, 2020OpenNTF Webinar, May 19, 2020
OpenNTF Webinar, May 19, 2020
Howard Greenberg
 

More from Howard Greenberg (20)

January OpenNTF Webinar - Backup your Domino Server - New Options in V12
January OpenNTF Webinar - Backup your Domino Server - New Options in V12January OpenNTF Webinar - Backup your Domino Server - New Options in V12
January OpenNTF Webinar - Backup your Domino Server - New Options in V12
 
BRPA November Meeting
BRPA November MeetingBRPA November Meeting
BRPA November Meeting
 
October OpenNTF Webinar - What we like about Domino/Notes 12, recommended new...
October OpenNTF Webinar - What we like about Domino/Notes 12, recommended new...October OpenNTF Webinar - What we like about Domino/Notes 12, recommended new...
October OpenNTF Webinar - What we like about Domino/Notes 12, recommended new...
 
September-2021 OpenNTF Webinar: Domino Online Meeting Integration (DOMI)
September-2021 OpenNTF Webinar: Domino Online Meeting Integration (DOMI)September-2021 OpenNTF Webinar: Domino Online Meeting Integration (DOMI)
September-2021 OpenNTF Webinar: Domino Online Meeting Integration (DOMI)
 
August OpenNTF Webinar - Git and GitHub Explained
August OpenNTF Webinar - Git and GitHub ExplainedAugust OpenNTF Webinar - Git and GitHub Explained
August OpenNTF Webinar - Git and GitHub Explained
 
July OpenNTF Webinar - HCL Presents Keep, a new API for Domino
July OpenNTF Webinar - HCL Presents Keep, a new API for DominoJuly OpenNTF Webinar - HCL Presents Keep, a new API for Domino
July OpenNTF Webinar - HCL Presents Keep, a new API for Domino
 
June OpenNTF Webinar - Domino V12 Certification Manager
June OpenNTF Webinar - Domino V12 Certification ManagerJune OpenNTF Webinar - Domino V12 Certification Manager
June OpenNTF Webinar - Domino V12 Certification Manager
 
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best PracticesApril, 2021 OpenNTF Webinar - Domino Administration Best Practices
April, 2021 OpenNTF Webinar - Domino Administration Best Practices
 
OpenNTF Webinar, March, 2021
OpenNTF Webinar, March, 2021OpenNTF Webinar, March, 2021
OpenNTF Webinar, March, 2021
 
February OpenNTF Webinar: Introduction to Ansible for Newbies
February OpenNTF Webinar: Introduction to Ansible for NewbiesFebruary OpenNTF Webinar: Introduction to Ansible for Newbies
February OpenNTF Webinar: Introduction to Ansible for Newbies
 
January OpenNTF Webinar: 4D - Domino Docker Deep Dive
January OpenNTF Webinar: 4D - Domino Docker Deep DiveJanuary OpenNTF Webinar: 4D - Domino Docker Deep Dive
January OpenNTF Webinar: 4D - Domino Docker Deep Dive
 
December OpenNTF Webinar: The Volt MX LotusScript Toolkit
December OpenNTF Webinar: The Volt MX LotusScript ToolkitDecember OpenNTF Webinar: The Volt MX LotusScript Toolkit
December OpenNTF Webinar: The Volt MX LotusScript Toolkit
 
OpNovember Water Cooler Talk: The Mystery of Domino on Docker - Part 1
OpNovember Water Cooler Talk: The Mystery of Domino on Docker - Part 1OpNovember Water Cooler Talk: The Mystery of Domino on Docker - Part 1
OpNovember Water Cooler Talk: The Mystery of Domino on Docker - Part 1
 
OpenNTF Webinar, October 2020
OpenNTF Webinar, October 2020OpenNTF Webinar, October 2020
OpenNTF Webinar, October 2020
 
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchAugust Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
 
July 2020 OpenNTF Webinar - Hear the Latest from the User Groups!
July 2020 OpenNTF Webinar - Hear the Latest from the User Groups!July 2020 OpenNTF Webinar - Hear the Latest from the User Groups!
July 2020 OpenNTF Webinar - Hear the Latest from the User Groups!
 
Open ntf 2020-jun
Open ntf 2020-junOpen ntf 2020-jun
Open ntf 2020-jun
 
OpenNTF Webinar, May 19, 2020
OpenNTF Webinar, May 19, 2020OpenNTF Webinar, May 19, 2020
OpenNTF Webinar, May 19, 2020
 
Dev112 let's calendar that
Dev112   let's calendar thatDev112   let's calendar that
Dev112 let's calendar that
 
Bp101-Can Domino Be Hacked
Bp101-Can Domino Be HackedBp101-Can Domino Be Hacked
Bp101-Can Domino Be Hacked
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

MWLUG Session- AD112 - Take a Trip Into the Forest - A Java Primer on Maps, Trees, and Collections

  • 1. 1 Take a Trip Into the Forest - A Java Primer on Maps, Trees, and Collections
  • 2. • Certified Lotus Instructor since R3 • Co-founded TLCC in 1987 • IBM Champion • Prior to that 12 years at IBM in the PC group • Also… – Certified Public Accountant – Certified Information Systems Auditor (CISA) – Certified Flight Instructor 2
  • 3. 3 • Private classes at your location or virtual •XPages Development •Support Existing Apps •Administration • Let us help you become an expert XPages developer! • Delivered via Notes • XPages • Development • Admin • User Self- Paced Courses Mentorin g Instructor- Led Classes Application Developmen t and Consulting Free Demo Courses!
  • 4. • Let us help with your development needs – Bootstrap – Java • Convert Notes Apps to mobile and the web! • Modernize old Domino web applications • Interface with backend data systems • Skills transfer 4
  • 5. • Why Use Java Objects in Xpages? • Introduction to Managed Beans • Scoped Variables in SSJS • Introduction to Maps • The DataObject Implementation • A Reporting Example • Questions??? 5
  • 6. • Performance (see my recorded webinar) • Reporting – Easily combine data from different sources • Portability – Back end – Front end • Code Maintenance • Lots of code/knowledge out there 6
  • 7. • The XPages runtime manages the creation of your “managed bean” – Request, View, Session, or Application scope • Refer to methods on your XPages or from other Java code • How to: – Create an entry in the Faces-Config file – Create your Java code • Getters and Setters • No argument constructor • Don’t have to use Managed Beans! 7 SampleBean.java SampleBeanDemo.xsp
  • 8. • sessionScope.testName – read/write to a variable that is session scope • Can store anything (string, Boolean, date, array, etc) – Just don’t store Domino objects • Why do we care??? – Scoped variables are stored as HashMaps – Another way to access is: • sessionScope.get(“testName”) • sessionScope.put(“testName” , “A value”) • Same as a Java Hash Map – Let’s Learn more about these HashMaps! 8
  • 9. • Collections is a Framework/root interface – Architecture for representing collections • Has Interfaces, Implementations, Algorithms • Interfaces – Abstract Data Type – Defines a base used by all the classes that implement • An interface in Java is similar to a class, but the body of an interface can include only abstract methods and final fields (constants). A class implements an interface by providing code for each method declared by the interface. • Implementations – A class that uses an interface (we use this!) 9
  • 10. 10
  • 11. 11
  • 13. • Set, SortedSet – No duplicate elements • HashSet, TreeSet, LinkedHashSet • List – Allows duplicates – Ordered • ArrayList, LinkedList • Map, SortedMap – Key/Value pairs • HashMap, LinkedHashMap, TreeMap 13
  • 14. 14
  • 15. • Goal – Store configuration information – Managed Bean with Application Scope • Best choice is a HashMap – Why? Back to the previous chart! – Access values with a key 15
  • 16. • Creation private HashMap<String,String> configData = new HashMap<String, String>(); • Set a value configData.put(key ,value); • Get a value (and test to see if key is there) public String getConfig(String key) { String rtnString = ""; if (this.configData.containsKey(key)){ rtnString = this.configData.get(key); } return rtnString; } 16
  • 17. 1. Notes view/form to hold configuration data 2. Create new Java Class 3. Add Managed Bean to faces-config – Set scope as needed 4. Implement Serializable in the Java class 5. Create “private” variable for HashMap 6. Create constructor to initialize data – Walk the view to load up the keys/values 7. Generate Getter/Setter 8. Use on XPage or in other Java code 17 ConfigBean.java ConfigBeanDemo.xsp
  • 18. • Get all the keys as a Set – statesHashMap.keySet() • Get all the values as a Set – statesHashMap.values() • Get the key and value as a Set – statesHashMap.entrySet() • Get the key with getKey() and the value with getValue() 18 for (Entry<String, String> state :statesHashMap.entrySet()){ myString = state.getValue() + "|" + state.getKey() ; debugMsg(myString); }
  • 19. • A HashMap does not keep the insertion order (random) • Need to keeps insertion order?  LinkedHashMap • Good when loading data from a Notes view (that is ordered already) – Keeps same (insertion) order • Otherwise basically the same as HashMap 19
  • 20. • A list of objects (like an Array) – Hold any data type/object – Can search the values – Can access an element in a certain position • Perfect for feeding to: – Values in a combo box, list box, etc. – Repeats – Data Tables • To add at end: – rtnList.add(stateLine); 20
  • 21. • Stop doing @DbColumns – Slow! • Load values from a view, store in memory – FAST! • Use Expression Language – configBean.statesHashMap • Use same ConfigBean as before (application scope) – Method in Java is getStatesHashMap() – Returns a List 21 ConfigBean.java ConfigBeanDemo.xsp
  • 22. • Do you Recycle? – View looping – NotesDateTime? – columnValues with a Date creates NotesDateTime objects • Instead use the Domino API – Simpler code patterns – Never have to worry about recycle – Try/Catch block not required – Support for logging – Lots of cool new stuff • Available on OpenNTF – Link to version 3 – Get help via Slack/Stack Overflow 22
  • 23. 23 private void initBean(Database curDb, String viewName) { try { View setupVw = curDb.getView(viewName); String key = ""; String value = ""; ViewEntry tempEntry; if (setupVw != null) { ViewEntryCollection vwEntryCol = setupVw.getAllEntries(); ViewEntry entryDoc = vwEntryCol.getFirstEntry(); while (entryDoc != null){ Vector<?> colValues = entryDoc.getColumnValues(); key = (String) colValues.elementAt(0); value = (String) colValues.elementAt(1); this.configData.put(key , value); tempEntry = vwEntryCol.getNextEntry(entryDoc); entryDoc.recycle(); entryDoc = tempEntry; } } } catch (Exception e) { e.printStackTrace(); } }
  • 24. 24 private void initBean(Database curDb, String viewName) { View setupVw = curDb.getView(viewName); String key = ""; String value = ""; if (setupVw != null) { for (ViewEntry entryDoc : setupVw.getAllEntries()){ Vector<?> colValues = entryDoc.getColumnValues(); key = (String) colValues.elementAt(0); value = (String) colValues.elementAt(1); this.configData.put(key , value); } } } No Recycle! Uses a for loop No Try/Catch block ConfigBean2.java DomAPIDemo.xsp
  • 25. • Use Case – Get a list of values always sorted by the value • “Natural” sort order – No duplicates • TreeSet! • Good for looping through a view, getting a value from a column – Add to TreeSet and then you always have a sorted, unique list 25 TreeSetBean.java TreeSetBeanDemo.xsp
  • 26. • Suppose you don’t want the “natural” order??? – Use a custom sort when defining the TreeSet – Comparator function – Will always sort using this new sort definition 26 public List<String> getArizonaTownsReversed() { TreeSet<String> sorted = new TreeSet<String>(new Comparator<String>() { public int compare(String o1, String o2) { return o2.compareTo(o1); } }); sorted.addAll(ArizonaTowns); return new ArrayList<String>(sorted); } TreeSetBean.java TreeSetBeanDemo.xsp
  • 27. • Use a TreeMap – Key,Value pair • In this case, a state is the key, a list of towns (TreeSet) is the value – Sorted on the Key value, natural order 27
  • 28. • Way to implement an interface that works well with the Expression Language – Any data type – Must implement certain methods 28 DataObjectBean.java DataObjectBeanDemo.xsp
  • 29. • Goal is to store information in the bean to allow fast filtering and sorting • Base storage is a LinkedHashMap – Key is the city name – Values are an ArrayList • The ArrayList holds a Person object –First and last name, city, state, email, etc. –Universal doc id to retrieve Notes document 29
  • 30. 30 Houston LinkedHashMap<String,ArrayList <Person>> customers Key is City Name Lorie Mason Brad Hunt Jessie Lang Mark Travis firstName lastName City State eMail Notes ID DocUNID Person ObjectDallas Austin ArrayList<Person> The customers HashMap stores all the people from a selected state ReportBean.java ReportBeanDemo.xsp
  • 31. • Methods of the Bean are used to: – Return data as an ArrayList to a Repeat • Sorted (last name, city, email) • Filter on a city or show all – Switch to a different state – Get the cities for the selected state (unique, ordered) – Store information like: • City filter • Desired sorting • Ascending or Descending sorting 31
  • 32. • TLCC’s Java Classes (two) http://www.tlcc.com/admin/tlccsite.nsf/coursedetails.xsp?ccode=ND9XJVKPG • My Session on Xpages Performance (recorded) – October, 2015 http://www.tlcc.com/admin/tlccsite.nsf/pages/recorded-xpages- webinars?opendocument • List of Collections with a summary of features – http://www.janeve.me/articles/which-java-collection-to-use • The Sun Java documentation (version 6, aka 1.6) • StackOverflow • Google!!! 32
  • 33. 33  Email: howardg@tlcc.com  Twitter: @TLCCLtd  Web: www.tlcc.com Special Offer!!! Save 20% on any TLCC course or package until 9/30 To take advantage of this offer or to download the demonstration databases www.tlcc.com/mwlug