The Common Java Cookbook

Total Page:16

File Type:pdf, Size:1020Kb

The Common Java Cookbook June 2009 July 2009 Edition 0.9 Edition 0.19 The Common Java Cookbook Tim O’Brien discursive.com/books/cjcook A Discursive Open Book Copyright and License ....................................................................................................................................xx 1. Creative Commons BY-NC-ND 3.0 US License ...................................................................................xx Foreword: 0.19 ............................................................................................................................................xxiv Preface .........................................................................................................................................................xxv 1. What's Inside ....................................................................................................................................xxv 2. Conventions Used in This Book ......................................................................................................xxviii 3. What You'll Need ............................................................................................................................xxix 4. Book Examples ................................................................................................................................xxix 5. The Apache Commons Community ...................................................................................................xxix 6. The Apache Software License ............................................................................................................xxx 7. We'd Like to Hear from You .............................................................................................................xxxi 1. Supplements to the Java 2 Platform ................................................................................................................1 1.1. Introduction .......................................................................................................................................1 1.1. Depending on Commons Lang ............................................................................................................1 1.1.1. Problem ..................................................................................................................................1 1.1.2. Solution ..................................................................................................................................1 1.1.3. Discussion ..............................................................................................................................2 1.4. Automating the Generation of toString( ) Content ................................................................................2 1.4.1. Problem ..................................................................................................................................2 1.4.2. Solution ..................................................................................................................................2 1.4.3. Discussion ..............................................................................................................................2 1.5. Customizing Generated toString( ) Content ..........................................................................................4 1.5.1. Problem ..................................................................................................................................4 1.5.2. Solution ..................................................................................................................................4 1.5.3. Discussion ..............................................................................................................................5 1.6. Automating hashCode( ) and equals( ) .................................................................................................6 1.6.1. Problem ..................................................................................................................................6 1.6.2. Solution ..................................................................................................................................6 1.6.3. Discussion ..............................................................................................................................7 1.7. Automating compareTo( ) ...................................................................................................................8 1.7.1. Problem ..................................................................................................................................8 1.7.2. Solution ..................................................................................................................................8 1.7.3. Discussion ..............................................................................................................................8 1.7.4. See Also .................................................................................................................................9 1.8. Printing an Array ..............................................................................................................................10 1.8.1. Problem ................................................................................................................................10 1.8.2. Solution ................................................................................................................................10 1.8.3. Discussion ............................................................................................................................10 1.9. Cloning and Reversing Arrays ..........................................................................................................10 1.9.1. Problem ................................................................................................................................10 1.9.2. Solution ................................................................................................................................11 1.9.3. Discussion ............................................................................................................................11 1.10. Transforming Between Object Arrays and Primitive Arrays ..............................................................12 1.10.1. Problem ..............................................................................................................................12 1.10.2. Solution ..............................................................................................................................12 1.10.3. Discussion ..........................................................................................................................13 1.10.4. See Also .............................................................................................................................14 1.11. Finding Items in an Array ...............................................................................................................14 ii Common Java Cookbook 1.11.1. Problem ..............................................................................................................................14 1.11.2. Solution ..............................................................................................................................14 1.11.3. Discussion ..........................................................................................................................15 1.11.4. See Also .............................................................................................................................16 1.12. Creating a Map from a Multidimensional Array ...............................................................................16 1.12.1. Problem ..............................................................................................................................16 1.12.2. Solution ..............................................................................................................................16 1.12.3. Discussion ..........................................................................................................................16 1.12.4. See Also .............................................................................................................................16 1.13. Formatting Dates ............................................................................................................................17 1.13.1. Problem ..............................................................................................................................17 1.13.2. Solution ..............................................................................................................................17 1.13.3. Discussion ..........................................................................................................................17 1.13.4. See Also .............................................................................................................................18 1.14. Rounding Date Objects ...................................................................................................................18 1.14.1. Problem ..............................................................................................................................18 1.14.2. Solution ..............................................................................................................................19
Recommended publications
  • Commonjavajars - a Package with Useful Libraries for Java Guis
    CommonJavaJars - A package with useful libraries for Java GUIs To reduce the package size of other R packages with Java GUIs and to reduce jar file conflicts, this package provides a few commonly used Java libraries. You should be able to load them by calling the rJava .jpackage function (a good place is most likely the .onLoad function of your package): .jpackage("CommonJavaJars", jars=c("forms-1.2.0.jar", "iText-2.1.4.jar")) We provide the following Java libraries: Apache Commons Logging under the Apache License, Version 2.0, January 2004, http://commons. apache.org/logging/, Copyright 2001-2007 The Apache Software Foundation Apache jog4j under Apache License 2.0, http://logging.apache.org/log4j/, Copyright 2007 The Apache Software Foundation Apache Commons Lang under Apache License 2.0, http://commons.apache.org/lang/, Copyright 2001-2011 The Apache Software Foundation Apache POI under Apache License 2.0, http://poi.apache.org/, Copyright 2001-2007 The Apache Software Foundation Apache Commons Collections under the Apache License, Version 2.0, January 2004, http://commons. apache.org/collections/, Copyright 2001-2008 The Apache Software Foundation Apache Commons Validator under the Apache License, Version 2.0, January 2004, http://commons. apache.org/validator/, Copyright 2001-2010 The Apache Software Foundation JLaTeXMath under GPL >= 2.0, http://forge.scilab.org/index.php/p/jlatexmath/, Copyright 2004-2007, 2009 Calixte, Coolsaet, Cleemput, Vermeulen and Universiteit Gent iText 2.1.4 under LGPL, http://itextpdf.com/, Copyright
    [Show full text]
  • Bulletin of the Center for Children's Books
    I LL INI S UNIVERSITY OF ILLINOIS AT URBANA-CHAMPAIGN PRODUCTION NOTE University of Illinois at Urbana-Champaign Library Large-scale Digitization Project, 2007. Bulletin of the Center for Children's Books THE UNIVERSITY OF CHICAGO * GRADUATE LIBRARY SCHOOL Volume XVI April, 1963 Number 8 New Titles for Children and Young People M Agle, Nan (Hayden). The Lords Baltimore; by Nan Hayden Agle and Frances 6-9 Atchinson Bacon; illus. by Leonard Vosburgh. Holt, 1962. 134p. Trade ed. $3.50; Library ed. $3.27 net. A history of the six Lords Baltimore, beginning with the English background of George Calvert, created the first Lord Baltimore in 1617. The story of the Chesa- peake Bay grant is of interest because of the record of religious tolerance; the first Lord Baltimore had seen persecution in England and had become converted to his mother's faith, Catholicism. The historical material is authoritative, but the book covers so much history that the text is heavy with detail, fact, and anecdote. An extensive bibliography is appended. M Aliki. My Hands. Crowell, 1962. 34p. illus. (Let's Read-and-Find-Out 1 Books). Trade ed. $2.50; Library ed. $2.35 net. Bright and lively illustrations but a rather slight text for science information. The book points out that each finger in a hand is different, that the human hand has an opposable thumb, that hands are used for many tasks, and that parts of the hand are used in different ways. The information is at such a simple level, and is about such a familiar subject, that much of the text seems of little use.
    [Show full text]
  • The Pentaho Big Data Guide This Document Supports Pentaho Business Analytics Suite 4.8 GA and Pentaho Data Integration 4.4 GA, Documentation Revision October 31, 2012
    The Pentaho Big Data Guide This document supports Pentaho Business Analytics Suite 4.8 GA and Pentaho Data Integration 4.4 GA, documentation revision October 31, 2012. This document is copyright © 2012 Pentaho Corporation. No part may be reprinted without written permission from Pentaho Corporation. All trademarks are the property of their respective owners. Help and Support Resources If you have questions that are not covered in this guide, or if you would like to report errors in the documentation, please contact your Pentaho technical support representative. Support-related questions should be submitted through the Pentaho Customer Support Portal at http://support.pentaho.com. For information about how to purchase support or enable an additional named support contact, please contact your sales representative, or send an email to [email protected]. For information about instructor-led training on the topics covered in this guide, visit http://www.pentaho.com/training. Limits of Liability and Disclaimer of Warranty The author(s) of this document have used their best efforts in preparing the content and the programs contained in it. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The author and publisher make no warranty of any kind, express or implied, with regard to these programs or the documentation contained in this book. The author(s) and Pentaho shall not be liable in the event of incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of the programs, associated instructions, and/or claims. Trademarks Pentaho (TM) and the Pentaho logo are registered trademarks of Pentaho Corporation.
    [Show full text]
  • Open Source Used in Cisco Unity Connection 11.5 SU 1
    Open Source Used In Cisco Unity Connection 11.5 SU 1 Cisco Systems, Inc. www.cisco.com Cisco has more than 200 offices worldwide. Addresses, phone numbers, and fax numbers are listed on the Cisco website at www.cisco.com/go/offices. Text Part Number: 78EE117C99-132949842 Open Source Used In Cisco Unity Connection 11.5 SU 1 1 This document contains licenses and notices for open source software used in this product. With respect to the free/open source software listed in this document, if you have any questions or wish to receive a copy of any source code to which you may be entitled under the applicable free/open source license(s) (such as the GNU Lesser/General Public License), please contact us at [email protected]. In your requests please include the following reference number 78EE117C99-132949842 Contents 1.1 ace 5.3.5 1.1.1 Available under license 1.2 Apache Commons Beanutils 1.6 1.2.1 Notifications 1.2.2 Available under license 1.3 Apache Derby 10.8.1.2 1.3.1 Available under license 1.4 Apache Mina 2.0.0-RC1 1.4.1 Available under license 1.5 Apache Standards Taglibs 1.1.2 1.5.1 Available under license 1.6 Apache STRUTS 1.2.4. 1.6.1 Available under license 1.7 Apache Struts 1.2.9 1.7.1 Available under license 1.8 Apache Xerces 2.6.2. 1.8.1 Notifications 1.8.2 Available under license 1.9 axis2 1.3 1.9.1 Available under license 1.10 axis2/cddl 1.3 1.10.1 Available under license 1.11 axis2/cpl 1.3 1.11.1 Available under license 1.12 BeanUtils(duplicate) 1.6.1 1.12.1 Notifications Open Source Used In Cisco Unity Connection
    [Show full text]
  • Our August Club Night
    Our August club night The house band Breakthru' opened up the evening as usual, we also saw them play last Wednesday at a nearby Club in Molesey where they had a chance to play a few non Shadows hits and explore some different sounds. I was first up to get it over and done with, not too good for me as I did not have much pratice and am only just getting full feeling back into my fingers. The Players Steve J – Apache, Wonderful Land Tony Knight – Foot Tapper, Cavatina (Theme from The Deer Hunter) Mike Norris – Theme from Shane, Mustang Bob Withrington – Rounding the Cape, Return to the Alamo John Cade – Shindig, Mountains of the Moon Alan Tarrant – Atlantis, Theme for Young Lovers Keith Humphries (visiting from South Africe) - The Savage, Peace Pipe John Bell – Cosy, Shadoogie (with Mark Winter on Drums) J. J. (visiting from USA) – Carolina on my Mind, Start the day Early Eugene McGuigan - Peace Pipe, Wonderful Land Robin Surridge with Jim on Rhythm – Lost City, Its a Mans World Stuart Osborne – Man of Mystery, Frightened City Gareth Morgan – Spring is nearly Here, Frightened City The Rock and Roll Section This featured Mark Winter on Drums, Alan Tarrant on Lead/Rhythm, Stuart Osborne on Lead/Vocals, Jim on Rhythm, Bob Withrington on Bass and Bob Dore on Keyboards – They played a selection of tunes including No Way to Go, Great Balls of Fire and Its Alright Mama. Barry Gibson took over Lead with Keith West on Vocals for Wicked Game, Folson Prison Blues and Little Sister.
    [Show full text]
  • Tracking Known Security Vulnerabilities in Third-Party Components
    Tracking known security vulnerabilities in third-party components Master’s Thesis Mircea Cadariu Tracking known security vulnerabilities in third-party components THESIS submitted in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE in COMPUTER SCIENCE by Mircea Cadariu born in Brasov, Romania Software Engineering Research Group Software Improvement Group Department of Software Technology Rembrandt Tower, 15th floor Faculty EEMCS, Delft University of Technology Amstelplein 1 - 1096HA Delft, the Netherlands Amsterdam, the Netherlands www.ewi.tudelft.nl www.sig.eu c 2014 Mircea Cadariu. All rights reserved. Tracking known security vulnerabilities in third-party components Author: Mircea Cadariu Student id: 4252373 Email: [email protected] Abstract Known security vulnerabilities are introduced in software systems as a result of de- pending on third-party components. These documented software weaknesses are hiding in plain sight and represent the lowest hanging fruit for attackers. Despite the risk they introduce for software systems, it has been shown that developers consistently download vulnerable components from public repositories. We show that these downloads indeed find their way in many industrial and open-source software systems. In order to improve the status quo, we introduce the Vulnerability Alert Service, a tool-based process to track known vulnerabilities in software projects throughout the development process. Its usefulness has been empirically validated in the context of the external software product quality monitoring service offered by the Software Improvement Group, a software consultancy company based in Amsterdam, the Netherlands. Thesis Committee: Chair: Prof. Dr. A. van Deursen, Faculty EEMCS, TU Delft University supervisor: Prof. Dr. A.
    [Show full text]
  • Unravel Data Systems Version 4.5
    UNRAVEL DATA SYSTEMS VERSION 4.5 Component name Component version name License names jQuery 1.8.2 MIT License Apache Tomcat 5.5.23 Apache License 2.0 Tachyon Project POM 0.8.2 Apache License 2.0 Apache Directory LDAP API Model 1.0.0-M20 Apache License 2.0 apache/incubator-heron 0.16.5.1 Apache License 2.0 Maven Plugin API 3.0.4 Apache License 2.0 ApacheDS Authentication Interceptor 2.0.0-M15 Apache License 2.0 Apache Directory LDAP API Extras ACI 1.0.0-M20 Apache License 2.0 Apache HttpComponents Core 4.3.3 Apache License 2.0 Spark Project Tags 2.0.0-preview Apache License 2.0 Curator Testing 3.3.0 Apache License 2.0 Apache HttpComponents Core 4.4.5 Apache License 2.0 Apache Commons Daemon 1.0.15 Apache License 2.0 classworlds 2.4 Apache License 2.0 abego TreeLayout Core 1.0.1 BSD 3-clause "New" or "Revised" License jackson-core 2.8.6 Apache License 2.0 Lucene Join 6.6.1 Apache License 2.0 Apache Commons CLI 1.3-cloudera-pre-r1439998 Apache License 2.0 hive-apache 0.5 Apache License 2.0 scala-parser-combinators 1.0.4 BSD 3-clause "New" or "Revised" License com.springsource.javax.xml.bind 2.1.7 Common Development and Distribution License 1.0 SnakeYAML 1.15 Apache License 2.0 JUnit 4.12 Common Public License 1.0 ApacheDS Protocol Kerberos 2.0.0-M12 Apache License 2.0 Apache Groovy 2.4.6 Apache License 2.0 JGraphT - Core 1.2.0 (GNU Lesser General Public License v2.1 or later AND Eclipse Public License 1.0) chill-java 0.5.0 Apache License 2.0 Apache Commons Logging 1.2 Apache License 2.0 OpenCensus 0.12.3 Apache License 2.0 ApacheDS Protocol
    [Show full text]
  • Hank Marvin Album HANK Set for Release 2Nd June 2014 Submitted By: Bennett Public Relations Thursday, 10 April 2014
    Hank Marvin album HANK set for release 2nd June 2014 Submitted by: Bennett Public Relations Thursday, 10 April 2014 Hank Marvin, the legendary guitarist and modern day icon, who has inspired generations and garnered critical acclaim throughout his career for his work with The Shadows and as a solo artist, releases a long-awaited new studio album on 2 June 2014. Simply titled HANK, the album will be released on the DMG TV label. Featuring 14 tracks, HANK includes fresh interpretations of some of Marvin’s favourite summer-themed music, along with one new composition. It’s the first new release since 2007’s UK Top 10 Guitar Man, for the man whose legendary achievements were restated yet again in The Times in February 2014, when he was listed as Number 2, amongst the world’s greatest guitar players and The Shadows amongst the greatest groups! It’s been 60 years since the man who introduced the Fender Stratocaster to the UK, picked up his first musical instrument. Marvin’s performances as a solo frontman and with The Shadows on their records and backing Cliff Richard have resulted in millions of worldwide record sales. The Shadows’ monumental chart debut with Apache in 1960 started an incredible run of 13 UK Top 10 hits for the group in just 4 years, during which time their unmistakeable style became a household sound around the world. Hank and The Shadows ruled the charts during the early 1960s and as a solo artist from the late 1970s to the present day Hank Marvin has sold in excess of 6 million albums.
    [Show full text]
  • Inequalities in Open Source Software Development: Analysis of Contributor’S Commits in Apache Software Foundation Projects
    RESEARCH ARTICLE Inequalities in Open Source Software Development: Analysis of Contributor’s Commits in Apache Software Foundation Projects Tadeusz Chełkowski1☯, Peter Gloor2☯*, Dariusz Jemielniak3☯ 1 Kozminski University, Warsaw, Poland, 2 Massachusetts Institute of Technology, Center for Cognitive Intelligence, Cambridge, Massachusetts, United States of America, 3 Kozminski University, New Research on Digital Societies (NeRDS) group, Warsaw, Poland ☯ These authors contributed equally to this work. * [email protected] a11111 Abstract While researchers are becoming increasingly interested in studying OSS phenomenon, there is still a small number of studies analyzing larger samples of projects investigating the structure of activities among OSS developers. The significant amount of information that OPEN ACCESS has been gathered in the publicly available open-source software repositories and mailing- list archives offers an opportunity to analyze projects structures and participant involve- Citation: Chełkowski T, Gloor P, Jemielniak D (2016) Inequalities in Open Source Software Development: ment. In this article, using on commits data from 263 Apache projects repositories (nearly Analysis of Contributor’s Commits in Apache all), we show that although OSS development is often described as collaborative, but it in Software Foundation Projects. PLoS ONE 11(4): fact predominantly relies on radically solitary input and individual, non-collaborative contri- e0152976. doi:10.1371/journal.pone.0152976 butions. We also show, in the first published study of this magnitude, that the engagement Editor: Christophe Antoniewski, CNRS UMR7622 & of contributors is based on a power-law distribution. University Paris 6 Pierre-et-Marie-Curie, FRANCE Received: December 15, 2015 Accepted: March 22, 2016 Published: April 20, 2016 Copyright: © 2016 Chełkowski et al.
    [Show full text]
  • Neon Core Infrastructure Services
    NeOn-project.org NeOn: Lifecycle Support for Networked Ontologies Integrated Project (IST-2005-027595) Priority: IST-2004-2.4.7 – “Semantic-based knowledge and content systems” D6.4.2 NeOn core infrastructure services Deliverable Co-ordinator: Walter Waterfeld Deliverable Co-ordinating Institution: Software AG (SAG) Other Authors: Diana Maynard, University of Sheffield (USFD), Ian Roberts, University of Sheffield (USFD), Michael Gesmann, Software AG (SAG) Document Identifier: NEON/2010/D6.4.2/v1.0 Date due: October 31st, 2009 Class Deliverable: NEON EU-IST-2005-027595 Submission date: January 31st , 2010 Project start date: March 1, 2006 Version: v1.0 Project duration: 4 years State: Final Distribution: Public 2006–2010 © Copyright lies with the respective authors and their institutions. Page 2 of 25 NeOn Integrated Project EU-IST-027595 NeOn Consortium This document is a part of the NeOn research project funded by the IST Programme of the Commission of the European Communities by the grant number IST-2005-027595. The following partners are involved in the project: Open University (OU) – Coordinator Universität Karlsruhe – TH (UKARL) Knowledge Media Institute – KMi Institut für Angewandte Informatik und Formale Berrill Building, Walton Hall Beschreibungsverfahren – AIFB Milton Keynes, MK7 6AA Englerstrasse 11 United Kingdom D-76128 Karlsruhe, Germany Contact person: Enrico Motta Contact person: Andreas Harth E-mail address: [email protected] E-mail address: [email protected] Universidad Politécnica de Madrid (UPM) Software AG (SAG) Campus de Montegancedo Uhlandstrasse 12 28660 Boadilla del Monte 64297 Darmstadt Spain Germany Contact person: Asunción Gómez Pérez Contact person: Walter Waterfeld E-mail address: [email protected] E-mail address: [email protected] Intelligent Software Components S.A.
    [Show full text]
  • Open Source Software Licenses, Notices, and Information
    Intergraph InPursuit® WebRMS 03.06.1909 Open Source Software Licenses, Notices, and Information This information is provided for Intergraph InPursuit® WebRMS, a software program of Intergraph® Corporation D/B/A Hexagon Safety & Infrastructure® (“Hexagon”). Source Code Access Intergraph InPursuit WebRMS may include components licensed pursuant to open source software licenses with an obligation to offer the recipient source code. Please see below the list of such components and the information needed to access the source code repository for each. In the event the source code is inaccessible using the information below, please email [email protected]. Component, version Link to download repository Hibernate ORM https://github.com/hibernate/hibernate-orm/releases/tag/3.6.10.Final 3.6.10.Final javassist 3.12.0.GA https://github.com/jboss-javassist/javassist/releases/tag/rel_3_12_0_ga wsdl4j 1.6.1 https://sourceforge.net/projects/wsdl4j/files/WSDL4J/1.6.1/ aspectj 1.8.4 http://git.eclipse.org/c/aspectj/org.aspectj.git/tag/?h=V1_8_4 displaytag 1.2.9 https://github.com/hexagonSI-RMS/displaytag-hexagon Open Source Software Components Intergraph InPursuit WebRMS may include the open source software components identified below. This document provides the notices and information regarding any such open source software for informational purposes only. Please see the product license agreement for Intergraph InPursuit WebRMS to determine the terms and conditions that apply to the open source software. Hexagon reserves all other rights. Component, version URL Copyright License link ActiveMQ KahaDB, version http://activemq.apache.org/kahadb.html © 2005-2012 Apache Software Foundation License 1 5.5.1 ActiveMQ, version 5.5.1 http://activemq.apache.org/ © 2005-2012 Apache Software Foundation License 1 Activiti, version 5.14.0 https://www.activiti.org/ © 2010-2016 Alfresco Software, Ltd.
    [Show full text]
  • HCP-CS Third-Party Software V1.1
    HCP-CS Third-Party Software V 1.1 Open Source Software Packages Contact Information: HCP-CS Third-Party Software Project Manager Hitachi Vantara Corporation 2535 Augustine Drive Santa Clara, California 95054 Name of Product/Product Version License Component systemd-pam 239 LGPLv2+ and MIT and GPLv2+ javapackages-filesystem 5.3.0 BSD dbus 1.12.10 (GPLv2+ or AFL) and GPLv2+ python-setuptools-wheel 40.4.3 MIT and (BSD or ASL 2.0) parted 3.2 GPLv3+ fontpackages-filesystem 1.44 Public Domain device-mapper-event 1.02.150 GPLv2 dejavu-fonts-common 2.35 Bitstream Vera and Public Domain lvm2 2.02.181 GPLv2 tzdata 2018e Public Domain ntpdate 4.2.8p12 MIT and BSD and BSD with advertising publicsuffix-list-dafsa 2E+07 MPLv2.0 Name of Product/Product Version License Component subversion-libs 1.10.2 ASL 2.0 ncurses-base 6.1 MIT javapackages-tools 5.3.0 BSD libX11-common 1.6.6 MIT apache-commons-pool 1.6 ASL 2.0 dnf-data 4.0.4 GPLv2+ and GPLv2 and GPL junit 4.12 EPL-1.0 fedora-release 29 MIT log4j12 1.2.17 ASL 2.0 setup 2.12.1 Public Domain cglib 3.2.4 ASL 2.0 and BSD basesystem 11 Public Domain slf4j 1.7.25 MIT and ASL 2.0 libselinux 2.8 Public Domain tomcat-lib 9.0.10 ASL 2.0 Name of Product/Product Version License Component LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ glibc-all-langpacks 2.28 and GPLv2+ with exceptions and BSD and Inner-Net and ISC and Public Domain and GFDL antlr-tool 2.7.7 ANTLR-PD LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ glibc 2.28 and GPLv2+ with exceptions and BSD and Inner-Net and ISC and Public Domain and GFDL apache-commons-daemon
    [Show full text]