Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/3569
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/69/3569/1
Java cleanup, use generic containers where possible
Change-Id: Icd830004de3e121f5b96393e7d7b447775833419
---
M bridges/test/java_uno/equals/TestEquals.java
M extensions/qa/integration/extensions/MethodHandler.java
M forms/qa/integration/forms/TableCellTextBinding.java
M nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
M odk/examples/DevelopersGuide/Text/TextDocuments.java
M scripting/workben/ifc/scripting/_XScriptInvocation.java
M scripting/workben/ifc/scripting/_XScriptNameResolver.java
M scripting/workben/mod/_scripting/TestDataLoader.java
8 files changed, 179 insertions(+), 189 deletions(-)
diff --git a/bridges/test/java_uno/equals/TestEquals.java
b/bridges/test/java_uno/equals/TestEquals.java
index bc79835..515c8e4 100644
--- a/bridges/test/java_uno/equals/TestEquals.java
+++ b/bridges/test/java_uno/equals/TestEquals.java
@@ -115,7 +115,7 @@
}
}
- private final HashMap map = new HashMap();
+ private final HashMap<String,Object> map = new HashMap<String,Object>();
}
private final class Done implements XDone {
@@ -160,7 +160,7 @@
UnoRuntime.queryInterface(
XDerived.class, test2Aa);
- Hashtable params = new Hashtable();
+ Hashtable<String,String> params = new
Hashtable<String,String>();
params.put("UNO_TYPES", unoTypes);
params.put("UNO_SERVICES", unoServices);
XComponentContext context = Bootstrap.
diff --git a/extensions/qa/integration/extensions/MethodHandler.java
b/extensions/qa/integration/extensions/MethodHandler.java
index 8508dca..b6259e9 100644
--- a/extensions/qa/integration/extensions/MethodHandler.java
+++ b/extensions/qa/integration/extensions/MethodHandler.java
@@ -31,13 +31,13 @@
private XIntrospectionAccess m_introspectionAccess;
private XIdlClass m_idlClass;
private XIdlMethod[] m_methods;
- private java.util.HashMap m_methodsHash;
+ private java.util.HashMap<String,XIdlMethod> m_methodsHash;
/** Creates a new instance of MethodHandler */
public MethodHandler( XComponentContext _context )
{
m_context = _context;
- m_methodsHash = new java.util.HashMap();
+ m_methodsHash = new java.util.HashMap<String,XIdlMethod>();
try
{
@@ -169,7 +169,7 @@
m_introspectionAccess = null;
m_methods = null;
- m_methodsHash = new java.util.HashMap();
+ m_methodsHash = new java.util.HashMap<String,XIdlMethod>();
m_introspectionAccess = m_introspection.inspect( _component );
if ( m_introspectionAccess == null )
@@ -217,7 +217,7 @@
*/
private XIdlMethod impl_getMethod( String _methodName ) throws UnknownPropertyException
{
- XIdlMethod method = (XIdlMethod)m_methodsHash.get( _methodName );
+ XIdlMethod method = m_methodsHash.get( _methodName );
if ( method == null )
throw new com.sun.star.beans.UnknownPropertyException();
diff --git a/forms/qa/integration/forms/TableCellTextBinding.java
b/forms/qa/integration/forms/TableCellTextBinding.java
index 40a5d69..8a1d1fb 100644
--- a/forms/qa/integration/forms/TableCellTextBinding.java
+++ b/forms/qa/integration/forms/TableCellTextBinding.java
@@ -48,7 +48,7 @@
private String m_newCellText;
private String m_lastKnownCellText;
private boolean m_haveNewCellText;
- private java.util.List m_listeners;
+ private java.util.List<com.sun.star.util.XModifyListener> m_listeners;
/** Creates a new instance of TableCellTextBinding */
public TableCellTextBinding( XCell cell )
@@ -56,7 +56,7 @@
m_cellText = UnoRuntime.queryInterface( XTextRange.class, cell );
m_newCellText = new String();
- m_listeners = new java.util.LinkedList();
+ m_listeners = new java.util.LinkedList<com.sun.star.util.XModifyListener>();
start();
}
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
index 7ca0e29..80d1f97 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/GlobalString.java
@@ -1,149 +1,148 @@
-/**
- * Description: operations for the a text string.
- *
- * @ Author Create/Modi Note
- * Xiaofeng Xie Feb 22, 2001
- * Xiaofeng Xie May 12, 2004
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * Please acknowledge the author(s) if you use this code in any way.
- *
- * @version 1.0
- * @Since MAOS1.0
- */
-
-package net.adaptivebox.global;
-
-import java.io.*;
-import java.util.*;
-
-public class GlobalString {
- public static final String NEGLECT_TAG = "#$@";
- public static final String EQUAL_TAG = "=";
-
-/**
- * Tokenize a String with given key.
- * @param input the String to be tokenized.
- * @param tokenKey the delimiters.
- * @return a String array that include the elements of input string that
- * divided by the tokenKey.
- */
- public static String[] tokenize(String input , String tokenKey) {
- Vector v = new Vector();
- StringTokenizer t = new StringTokenizer(input, tokenKey);
- String cmd[];
- while (t.hasMoreTokens())
- v.addElement(t.nextToken());
- cmd = new String[v.size()];
- for (int i = 0; i < cmd.length; i++)
- cmd[i] = (String) v.elementAt(i);
- return cmd;
- }
-
- public static String[] getMeaningfulLines(String srcStr) throws Exception {
- return getMeaningfulLines(srcStr, NEGLECT_TAG);
- }
-
- public static String getMeaningfulLine(BufferedReader outReader) throws Exception {
- return getMeaningfulLine(outReader, NEGLECT_TAG);
- }
-
- public static int getCharLoc(char data, String str) {
- for(int i=0; i<str.length(); i++) {
- if(str.charAt(i)==data) return i;
- }
- return -1;
- }
- public static String trim(String origStr, String discardStr) {
- String str = origStr;
- do {
- if(str.length()==0) return str;
- if(getCharLoc(str.charAt(0), discardStr)!=-1) str = str.substring(1);
- else if(getCharLoc(str.charAt(str.length()-1), discardStr)!=-1) str = str.substring(0,
str.length()-1);
- else {return str;}
- } while(true);
- }
-
- public static boolean getFirstCharExist(String str, String chars) throws Exception {
- int neglectFirstCharLength = chars.length();
- for(int i=0; i<neglectFirstCharLength; i++) {
- if(str.startsWith(chars.substring(i, i+1))) {
- return true;
- }
- }
- return false;
- }
-
- public static String getMeaningfulLine(BufferedReader outReader, String neglectFirstChars)
throws Exception {
- String str;
- boolean isNeglect = true;
- int i = 0;
- do {
- str = outReader.readLine();
- if (str==null) {
- return null;
- }
- str = trim(str, " \t");
- if(str.length()>0) {
- isNeglect = getFirstCharExist(str, neglectFirstChars);
- }
- } while (isNeglect);
- return str;
- }
-
- public static String[] getMeaningfulLines(String srcStr, String neglectFirstChars) throws
Exception {
- StringReader outStringReader = new StringReader(srcStr);
- BufferedReader outReader = new BufferedReader(outStringReader);
- Vector origData = new Vector();
- String str = null;
- while(true) {
- str = getMeaningfulLine(outReader, neglectFirstChars);
- if (str==null) {
- break;
- }
- origData.add(str);
- }
- return convert1DVectorToStringArray(origData);
- }
-
- /**
- * convert vector to 1D String array
- */
- public static String[] convert1DVectorToStringArray(Vector toToConvert) {
- if (toToConvert==null) return null;
- String[] objs = new String[toToConvert.size()];
- for (int i=0; i<toToConvert.size(); i++) {
- objs[i] =getObjString(toToConvert.elementAt(i));
- }
- return(objs);
- }
-
- public static String getObjString(Object nObj) {
- if(nObj instanceof String) return (String)nObj;
- return nObj.toString();
- }
-
- static public int toInteger(Object oVal) throws Exception {
- if(oVal==null) throw new Exception("Null string");
- return new Integer(oVal.toString()).intValue();
- }
-
- static public double toDouble(Object oVal) throws Exception {
- if(oVal==null) throw new Exception("Null string");
- return new Double(oVal.toString()).doubleValue();
- }
-
- public static Object toObject(String key) throws Exception{
- Class cls = Class.forName(key);
- return cls.newInstance();
- }
+/**
+ * Description: operations for the a text string.
+ *
+ * @ Author Create/Modi Note
+ * Xiaofeng Xie Feb 22, 2001
+ * Xiaofeng Xie May 12, 2004
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Please acknowledge the author(s) if you use this code in any way.
+ *
+ * @version 1.0
+ * @Since MAOS1.0
+ */
+
+package net.adaptivebox.global;
+
+import java.io.*;
+import java.util.*;
+
+public class GlobalString {
+ public static final String NEGLECT_TAG = "#$@";
+ public static final String EQUAL_TAG = "=";
+
+/**
+ * Tokenize a String with given key.
+ * @param input the String to be tokenized.
+ * @param tokenKey the delimiters.
+ * @return a String array that include the elements of input string that
+ * divided by the tokenKey.
+ */
+ public static String[] tokenize(String input , String tokenKey) {
+ Vector v = new Vector();
+ StringTokenizer t = new StringTokenizer(input, tokenKey);
+ String cmd[];
+ while (t.hasMoreTokens())
+ v.addElement(t.nextToken());
+ cmd = new String[v.size()];
+ for (int i = 0; i < cmd.length; i++)
+ cmd[i] = (String) v.elementAt(i);
+ return cmd;
+ }
+
+ public static String[] getMeaningfulLines(String srcStr) throws Exception {
+ return getMeaningfulLines(srcStr, NEGLECT_TAG);
+ }
+
+ public static String getMeaningfulLine(BufferedReader outReader) throws Exception {
+ return getMeaningfulLine(outReader, NEGLECT_TAG);
+ }
+
+ public static int getCharLoc(char data, String str) {
+ for(int i=0; i<str.length(); i++) {
+ if(str.charAt(i)==data) return i;
+ }
+ return -1;
+ }
+ public static String trim(String origStr, String discardStr) {
+ String str = origStr;
+ do {
+ if(str.length()==0) return str;
+ if(getCharLoc(str.charAt(0), discardStr)!=-1) str = str.substring(1);
+ else if(getCharLoc(str.charAt(str.length()-1), discardStr)!=-1) str = str.substring(0,
str.length()-1);
+ else {return str;}
+ } while(true);
+ }
+
+ public static boolean getFirstCharExist(String str, String chars) throws Exception {
+ int neglectFirstCharLength = chars.length();
+ for(int i=0; i<neglectFirstCharLength; i++) {
+ if(str.startsWith(chars.substring(i, i+1))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static String getMeaningfulLine(BufferedReader outReader, String neglectFirstChars)
throws Exception {
+ String str;
+ boolean isNeglect = true;
+ int i = 0;
+ do {
+ str = outReader.readLine();
+ if (str==null) {
+ return null;
+ }
+ str = trim(str, " \t");
+ if(str.length()>0) {
+ isNeglect = getFirstCharExist(str, neglectFirstChars);
+ }
+ } while (isNeglect);
+ return str;
+ }
+
+ public static String[] getMeaningfulLines(String srcStr, String neglectFirstChars) throws
Exception {
+ StringReader outStringReader = new StringReader(srcStr);
+ BufferedReader outReader = new BufferedReader(outStringReader);
+ ArrayList<String> origData = new ArrayList<String>();
+ while(true) {
+ String str = getMeaningfulLine(outReader, neglectFirstChars);
+ if (str==null) {
+ break;
+ }
+ origData.add(str);
+ }
+ return convert1DVectorToStringArray(origData);
+ }
+
+ /**
+ * convert vector to 1D String array
+ */
+ public static String[] convert1DVectorToStringArray(ArrayList<String> toToConvert) {
+ if (toToConvert==null) return null;
+ String[] objs = new String[toToConvert.size()];
+ for (int i=0; i<toToConvert.size(); i++) {
+ objs[i] = getObjString(toToConvert.get(i));
+ }
+ return(objs);
+ }
+
+ public static String getObjString(Object nObj) {
+ if(nObj instanceof String) return (String)nObj;
+ return nObj.toString();
+ }
+
+ static public int toInteger(Object oVal) throws Exception {
+ if(oVal==null) throw new Exception("Null string");
+ return new Integer(oVal.toString()).intValue();
+ }
+
+ static public double toDouble(Object oVal) throws Exception {
+ if(oVal==null) throw new Exception("Null string");
+ return new Double(oVal.toString()).doubleValue();
+ }
+
+ public static Object toObject(String key) throws Exception{
+ Class cls = Class.forName(key);
+ return cls.newInstance();
+ }
}
\ No newline at end of file
diff --git a/odk/examples/DevelopersGuide/Text/TextDocuments.java
b/odk/examples/DevelopersGuide/Text/TextDocuments.java
index 4914251..0762a47 100644
--- a/odk/examples/DevelopersGuide/Text/TextDocuments.java
+++ b/odk/examples/DevelopersGuide/Text/TextDocuments.java
@@ -32,47 +32,49 @@
*
*************************************************************************/
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Random;
+
import com.sun.star.awt.Point;
import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XEnumerationAccess;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XIndexReplace;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.container.XNamed;
-import com.sun.star.container.XIndexAccess;
-import com.sun.star.container.XIndexReplace;
-import com.sun.star.container.XEnumeration;
-import com.sun.star.container.XEnumerationAccess;
-
+import com.sun.star.drawing.XDrawPageSupplier;
import com.sun.star.drawing.XShape;
import com.sun.star.drawing.XShapes;
-import com.sun.star.drawing.XDrawPageSupplier;
-
-import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XComponentLoader;
-import com.sun.star.frame.XModel;
import com.sun.star.frame.XController;
-
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo;
-
import com.sun.star.style.NumberingType;
import com.sun.star.style.XStyle;
import com.sun.star.style.XStyleFamiliesSupplier;
-
import com.sun.star.text.ControlCharacter;
-import com.sun.star.text.ReferenceFieldSource;
import com.sun.star.text.ReferenceFieldPart;
+import com.sun.star.text.ReferenceFieldSource;
import com.sun.star.text.TextColumn;
import com.sun.star.text.TextContentAnchorType;
-import com.sun.star.text.XAutoTextGroup;
import com.sun.star.text.XAutoTextEntry;
+import com.sun.star.text.XAutoTextGroup;
+import com.sun.star.text.XBookmarksSupplier;
import com.sun.star.text.XDependentTextField;
import com.sun.star.text.XDocumentIndex;
import com.sun.star.text.XFootnote;
import com.sun.star.text.XFootnotesSupplier;
+import com.sun.star.text.XPageCursor;
import com.sun.star.text.XParagraphCursor;
import com.sun.star.text.XReferenceMarksSupplier;
import com.sun.star.text.XRelativeTextContentInsert;
@@ -84,29 +86,19 @@
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextField;
+import com.sun.star.text.XTextFieldsSupplier;
import com.sun.star.text.XTextFrame;
import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextTable;
import com.sun.star.text.XTextTableCursor;
import com.sun.star.text.XTextTablesSupplier;
-import com.sun.star.text.XTextFieldsSupplier;
-import com.sun.star.text.XBookmarksSupplier;
-import com.sun.star.text.XTextViewCursorSupplier;
import com.sun.star.text.XTextViewCursor;
-import com.sun.star.text.XPageCursor;
-
+import com.sun.star.text.XTextViewCursorSupplier;
import com.sun.star.text.XWordCursor;
-
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XRefreshable;
-
-import com.sun.star.frame.XStorable;
import com.sun.star.view.XPrintable;
-
-import java.lang.Math;
-import java.util.Random;
-import java.util.Hashtable;
/*
* TextDocuments.java
@@ -170,7 +162,7 @@
*/
protected void templateExample() throws java.lang.Exception {
// create a small hashtable that simulates a rowset
- Hashtable recipient = new Hashtable();
+ HashMap<String,String> recipient = new HashMap<String,String>();
recipient.put("Company", "Manatee Books");
recipient.put("Contact", "Rod Martin");
recipient.put("ZIP", "34567");
@@ -195,10 +187,9 @@
XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields();
// iterate over hashtable and insert values into field masters
- java.util.Enumeration keys = recipient.keys();
- while(keys.hasMoreElements()) {
+ for(Iterator<String> iter = recipient.keySet().iterator(); iter.hasNext(); ) {
// get column name
- String key = (String)keys.nextElement();
+ String key = iter.next();
// access corresponding field master
Object fieldMaster = xNamedFieldMasters.getByName(
diff --git a/scripting/workben/ifc/scripting/_XScriptInvocation.java
b/scripting/workben/ifc/scripting/_XScriptInvocation.java
index a9b9b72..38863de 100644
--- a/scripting/workben/ifc/scripting/_XScriptInvocation.java
+++ b/scripting/workben/ifc/scripting/_XScriptInvocation.java
@@ -88,7 +88,7 @@
if (!context.equals("null"))
ctx = loadDocument(context);
- HashMap map = new HashMap();
+ HashMap<String,Object> map = new HashMap<String,Object>();
map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId));
map.put("SCRIPTING_DOC_URI", "hahaha");
if (ctx != null)
diff --git a/scripting/workben/ifc/scripting/_XScriptNameResolver.java
b/scripting/workben/ifc/scripting/_XScriptNameResolver.java
index 95601ca..fcee480 100644
--- a/scripting/workben/ifc/scripting/_XScriptNameResolver.java
+++ b/scripting/workben/ifc/scripting/_XScriptNameResolver.java
@@ -81,7 +81,7 @@
log.println(description + ": " + logicalname);
- HashMap map = new HashMap();
+ HashMap<String,Object> map = new HashMap<String,Object>();
map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId));
map.put("SCRIPTING_DOC_URI", util.utils.getFullTestURL(location));
diff --git a/scripting/workben/mod/_scripting/TestDataLoader.java
b/scripting/workben/mod/_scripting/TestDataLoader.java
index 530b8f2..c76d435 100644
--- a/scripting/workben/mod/_scripting/TestDataLoader.java
+++ b/scripting/workben/mod/_scripting/TestDataLoader.java
@@ -84,7 +84,7 @@
private static Parameters getParameters(StringTokenizer st) {
String separator = "=";
- HashMap map = new HashMap(5);
+ HashMap<String,Object> map = new HashMap<String,Object>(5);
while (st.hasMoreTokens()) {
String pair = st.nextToken();
--
To view, visit https://gerrit.libreoffice.org/3569
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icd830004de3e121f5b96393e7d7b447775833419
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Noel Grandin <noelgrandin@gmail.com>
Context
- [PATCH] Java cleanup, use generic containers where possible · Noel Grandin (via Code Review)
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.