Java cleanup, use generic containers where possible

Change-Id: Icd830004de3e121f5b96393e7d7b447775833419
Reviewed-on: https://gerrit.libreoffice.org/3569
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
This commit is contained in:
Noel Grandin 2013-04-23 09:30:47 +02:00 committed by Fridrich Strba
parent f62324cecd
commit 0c37eeebb0
8 changed files with 179 additions and 189 deletions

View File

@ -115,7 +115,7 @@ public final class TestEquals {
} }
} }
private final HashMap map = new HashMap(); private final HashMap<String,Object> map = new HashMap<String,Object>();
} }
private final class Done implements XDone { private final class Done implements XDone {
@ -160,7 +160,7 @@ public final class TestEquals {
UnoRuntime.queryInterface( UnoRuntime.queryInterface(
XDerived.class, test2Aa); XDerived.class, test2Aa);
Hashtable params = new Hashtable(); Hashtable<String,String> params = new Hashtable<String,String>();
params.put("UNO_TYPES", unoTypes); params.put("UNO_TYPES", unoTypes);
params.put("UNO_SERVICES", unoServices); params.put("UNO_SERVICES", unoServices);
XComponentContext context = Bootstrap. XComponentContext context = Bootstrap.

View File

@ -31,13 +31,13 @@ public class MethodHandler implements XPropertyHandler
private XIntrospectionAccess m_introspectionAccess; private XIntrospectionAccess m_introspectionAccess;
private XIdlClass m_idlClass; private XIdlClass m_idlClass;
private XIdlMethod[] m_methods; private XIdlMethod[] m_methods;
private java.util.HashMap m_methodsHash; private java.util.HashMap<String,XIdlMethod> m_methodsHash;
/** Creates a new instance of MethodHandler */ /** Creates a new instance of MethodHandler */
public MethodHandler( XComponentContext _context ) public MethodHandler( XComponentContext _context )
{ {
m_context = _context; m_context = _context;
m_methodsHash = new java.util.HashMap(); m_methodsHash = new java.util.HashMap<String,XIdlMethod>();
try try
{ {
@ -169,7 +169,7 @@ public class MethodHandler implements XPropertyHandler
m_introspectionAccess = null; m_introspectionAccess = null;
m_methods = null; m_methods = null;
m_methodsHash = new java.util.HashMap(); m_methodsHash = new java.util.HashMap<String,XIdlMethod>();
m_introspectionAccess = m_introspection.inspect( _component ); m_introspectionAccess = m_introspection.inspect( _component );
if ( m_introspectionAccess == null ) if ( m_introspectionAccess == null )
@ -217,7 +217,7 @@ public class MethodHandler implements XPropertyHandler
*/ */
private XIdlMethod impl_getMethod( String _methodName ) throws UnknownPropertyException private XIdlMethod impl_getMethod( String _methodName ) throws UnknownPropertyException
{ {
XIdlMethod method = (XIdlMethod)m_methodsHash.get( _methodName ); XIdlMethod method = m_methodsHash.get( _methodName );
if ( method == null ) if ( method == null )
throw new com.sun.star.beans.UnknownPropertyException(); throw new com.sun.star.beans.UnknownPropertyException();

View File

@ -48,7 +48,7 @@ public class TableCellTextBinding
private String m_newCellText; private String m_newCellText;
private String m_lastKnownCellText; private String m_lastKnownCellText;
private boolean m_haveNewCellText; 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 */ /** Creates a new instance of TableCellTextBinding */
public TableCellTextBinding( XCell cell ) public TableCellTextBinding( XCell cell )
@ -56,7 +56,7 @@ public class TableCellTextBinding
m_cellText = UnoRuntime.queryInterface( XTextRange.class, cell ); m_cellText = UnoRuntime.queryInterface( XTextRange.class, cell );
m_newCellText = new String(); m_newCellText = new String();
m_listeners = new java.util.LinkedList(); m_listeners = new java.util.LinkedList<com.sun.star.util.XModifyListener>();
start(); start();
} }

View File

@ -1,149 +1,148 @@
/** /**
* Description: operations for the a text string. * Description: operations for the a text string.
* *
* @ Author Create/Modi Note * @ Author Create/Modi Note
* Xiaofeng Xie Feb 22, 2001 * Xiaofeng Xie Feb 22, 2001
* Xiaofeng Xie May 12, 2004 * Xiaofeng Xie May 12, 2004
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * 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, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* Please acknowledge the author(s) if you use this code in any way. * Please acknowledge the author(s) if you use this code in any way.
* *
* @version 1.0 * @version 1.0
* @Since MAOS1.0 * @Since MAOS1.0
*/ */
package net.adaptivebox.global; package net.adaptivebox.global;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
public class GlobalString { public class GlobalString {
public static final String NEGLECT_TAG = "#$@"; public static final String NEGLECT_TAG = "#$@";
public static final String EQUAL_TAG = "="; public static final String EQUAL_TAG = "=";
/** /**
* Tokenize a String with given key. * Tokenize a String with given key.
* @param input the String to be tokenized. * @param input the String to be tokenized.
* @param tokenKey the delimiters. * @param tokenKey the delimiters.
* @return a String array that include the elements of input string that * @return a String array that include the elements of input string that
* divided by the tokenKey. * divided by the tokenKey.
*/ */
public static String[] tokenize(String input , String tokenKey) { public static String[] tokenize(String input , String tokenKey) {
Vector v = new Vector(); Vector v = new Vector();
StringTokenizer t = new StringTokenizer(input, tokenKey); StringTokenizer t = new StringTokenizer(input, tokenKey);
String cmd[]; String cmd[];
while (t.hasMoreTokens()) while (t.hasMoreTokens())
v.addElement(t.nextToken()); v.addElement(t.nextToken());
cmd = new String[v.size()]; cmd = new String[v.size()];
for (int i = 0; i < cmd.length; i++) for (int i = 0; i < cmd.length; i++)
cmd[i] = (String) v.elementAt(i); cmd[i] = (String) v.elementAt(i);
return cmd; return cmd;
} }
public static String[] getMeaningfulLines(String srcStr) throws Exception { public static String[] getMeaningfulLines(String srcStr) throws Exception {
return getMeaningfulLines(srcStr, NEGLECT_TAG); return getMeaningfulLines(srcStr, NEGLECT_TAG);
} }
public static String getMeaningfulLine(BufferedReader outReader) throws Exception { public static String getMeaningfulLine(BufferedReader outReader) throws Exception {
return getMeaningfulLine(outReader, NEGLECT_TAG); return getMeaningfulLine(outReader, NEGLECT_TAG);
} }
public static int getCharLoc(char data, String str) { public static int getCharLoc(char data, String str) {
for(int i=0; i<str.length(); i++) { for(int i=0; i<str.length(); i++) {
if(str.charAt(i)==data) return i; if(str.charAt(i)==data) return i;
} }
return -1; return -1;
} }
public static String trim(String origStr, String discardStr) { public static String trim(String origStr, String discardStr) {
String str = origStr; String str = origStr;
do { do {
if(str.length()==0) return str; if(str.length()==0) return str;
if(getCharLoc(str.charAt(0), discardStr)!=-1) str = str.substring(1); 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 if(getCharLoc(str.charAt(str.length()-1), discardStr)!=-1) str = str.substring(0, str.length()-1);
else {return str;} else {return str;}
} while(true); } while(true);
} }
public static boolean getFirstCharExist(String str, String chars) throws Exception { public static boolean getFirstCharExist(String str, String chars) throws Exception {
int neglectFirstCharLength = chars.length(); int neglectFirstCharLength = chars.length();
for(int i=0; i<neglectFirstCharLength; i++) { for(int i=0; i<neglectFirstCharLength; i++) {
if(str.startsWith(chars.substring(i, i+1))) { if(str.startsWith(chars.substring(i, i+1))) {
return true; return true;
} }
} }
return false; return false;
} }
public static String getMeaningfulLine(BufferedReader outReader, String neglectFirstChars) throws Exception { public static String getMeaningfulLine(BufferedReader outReader, String neglectFirstChars) throws Exception {
String str; String str;
boolean isNeglect = true; boolean isNeglect = true;
int i = 0; int i = 0;
do { do {
str = outReader.readLine(); str = outReader.readLine();
if (str==null) { if (str==null) {
return null; return null;
} }
str = trim(str, " \t"); str = trim(str, " \t");
if(str.length()>0) { if(str.length()>0) {
isNeglect = getFirstCharExist(str, neglectFirstChars); isNeglect = getFirstCharExist(str, neglectFirstChars);
} }
} while (isNeglect); } while (isNeglect);
return str; return str;
} }
public static String[] getMeaningfulLines(String srcStr, String neglectFirstChars) throws Exception { public static String[] getMeaningfulLines(String srcStr, String neglectFirstChars) throws Exception {
StringReader outStringReader = new StringReader(srcStr); StringReader outStringReader = new StringReader(srcStr);
BufferedReader outReader = new BufferedReader(outStringReader); BufferedReader outReader = new BufferedReader(outStringReader);
Vector origData = new Vector(); ArrayList<String> origData = new ArrayList<String>();
String str = null; while(true) {
while(true) { String str = getMeaningfulLine(outReader, neglectFirstChars);
str = getMeaningfulLine(outReader, neglectFirstChars); if (str==null) {
if (str==null) { break;
break; }
} origData.add(str);
origData.add(str); }
} return convert1DVectorToStringArray(origData);
return convert1DVectorToStringArray(origData); }
}
/**
/** * convert vector to 1D String array
* convert vector to 1D String array */
*/ public static String[] convert1DVectorToStringArray(ArrayList<String> toToConvert) {
public static String[] convert1DVectorToStringArray(Vector toToConvert) { if (toToConvert==null) return null;
if (toToConvert==null) return null; String[] objs = new String[toToConvert.size()];
String[] objs = new String[toToConvert.size()]; for (int i=0; i<toToConvert.size(); i++) {
for (int i=0; i<toToConvert.size(); i++) { objs[i] = getObjString(toToConvert.get(i));
objs[i] =getObjString(toToConvert.elementAt(i)); }
} return(objs);
return(objs); }
}
public static String getObjString(Object nObj) {
public static String getObjString(Object nObj) { if(nObj instanceof String) return (String)nObj;
if(nObj instanceof String) return (String)nObj; return nObj.toString();
return nObj.toString(); }
}
static public int toInteger(Object oVal) throws Exception {
static public int toInteger(Object oVal) throws Exception { if(oVal==null) throw new Exception("Null string");
if(oVal==null) throw new Exception("Null string"); return new Integer(oVal.toString()).intValue();
return new Integer(oVal.toString()).intValue(); }
}
static public double toDouble(Object oVal) throws Exception {
static public double toDouble(Object oVal) throws Exception { if(oVal==null) throw new Exception("Null string");
if(oVal==null) throw new Exception("Null string"); return new Double(oVal.toString()).doubleValue();
return new Double(oVal.toString()).doubleValue(); }
}
public static Object toObject(String key) throws Exception{
public static Object toObject(String key) throws Exception{ Class cls = Class.forName(key);
Class cls = Class.forName(key); return cls.newInstance();
return cls.newInstance(); }
}
} }

View File

@ -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.Point;
import com.sun.star.awt.Size; import com.sun.star.awt.Size;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet; 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.XNameAccess;
import com.sun.star.container.XNameContainer; import com.sun.star.container.XNameContainer;
import com.sun.star.container.XNamed; import com.sun.star.container.XNamed;
import com.sun.star.container.XIndexAccess; import com.sun.star.drawing.XDrawPageSupplier;
import com.sun.star.container.XIndexReplace;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.drawing.XShape; import com.sun.star.drawing.XShape;
import com.sun.star.drawing.XShapes; 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.XComponentLoader;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XController; 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.XComponent;
import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XServiceInfo;
import com.sun.star.style.NumberingType; import com.sun.star.style.NumberingType;
import com.sun.star.style.XStyle; import com.sun.star.style.XStyle;
import com.sun.star.style.XStyleFamiliesSupplier; import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.text.ControlCharacter; import com.sun.star.text.ControlCharacter;
import com.sun.star.text.ReferenceFieldSource;
import com.sun.star.text.ReferenceFieldPart; import com.sun.star.text.ReferenceFieldPart;
import com.sun.star.text.ReferenceFieldSource;
import com.sun.star.text.TextColumn; import com.sun.star.text.TextColumn;
import com.sun.star.text.TextContentAnchorType; import com.sun.star.text.TextContentAnchorType;
import com.sun.star.text.XAutoTextGroup;
import com.sun.star.text.XAutoTextEntry; 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.XDependentTextField;
import com.sun.star.text.XDocumentIndex; import com.sun.star.text.XDocumentIndex;
import com.sun.star.text.XFootnote; import com.sun.star.text.XFootnote;
import com.sun.star.text.XFootnotesSupplier; import com.sun.star.text.XFootnotesSupplier;
import com.sun.star.text.XPageCursor;
import com.sun.star.text.XParagraphCursor; import com.sun.star.text.XParagraphCursor;
import com.sun.star.text.XReferenceMarksSupplier; import com.sun.star.text.XReferenceMarksSupplier;
import com.sun.star.text.XRelativeTextContentInsert; import com.sun.star.text.XRelativeTextContentInsert;
@ -84,30 +86,20 @@ import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor; import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument; import com.sun.star.text.XTextDocument;
import com.sun.star.text.XTextField; import com.sun.star.text.XTextField;
import com.sun.star.text.XTextFieldsSupplier;
import com.sun.star.text.XTextFrame; import com.sun.star.text.XTextFrame;
import com.sun.star.text.XTextRange; import com.sun.star.text.XTextRange;
import com.sun.star.text.XTextTable; import com.sun.star.text.XTextTable;
import com.sun.star.text.XTextTableCursor; import com.sun.star.text.XTextTableCursor;
import com.sun.star.text.XTextTablesSupplier; 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.XTextViewCursor;
import com.sun.star.text.XPageCursor; import com.sun.star.text.XTextViewCursorSupplier;
import com.sun.star.text.XWordCursor; import com.sun.star.text.XWordCursor;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import com.sun.star.util.XRefreshable; import com.sun.star.util.XRefreshable;
import com.sun.star.frame.XStorable;
import com.sun.star.view.XPrintable; import com.sun.star.view.XPrintable;
import java.lang.Math;
import java.util.Random;
import java.util.Hashtable;
/* /*
* TextDocuments.java * TextDocuments.java
* *
@ -170,7 +162,7 @@ public class TextDocuments {
*/ */
protected void templateExample() throws java.lang.Exception { protected void templateExample() throws java.lang.Exception {
// create a small hashtable that simulates a rowset // 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("Company", "Manatee Books");
recipient.put("Contact", "Rod Martin"); recipient.put("Contact", "Rod Martin");
recipient.put("ZIP", "34567"); recipient.put("ZIP", "34567");
@ -195,10 +187,9 @@ public class TextDocuments {
XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields(); XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields();
// iterate over hashtable and insert values into field masters // iterate over hashtable and insert values into field masters
java.util.Enumeration keys = recipient.keys(); for(Iterator<String> iter = recipient.keySet().iterator(); iter.hasNext(); ) {
while(keys.hasMoreElements()) {
// get column name // get column name
String key = (String)keys.nextElement(); String key = iter.next();
// access corresponding field master // access corresponding field master
Object fieldMaster = xNamedFieldMasters.getByName( Object fieldMaster = xNamedFieldMasters.getByName(

View File

@ -88,7 +88,7 @@ public class _XScriptInvocation extends MultiMethodTest {
if (!context.equals("null")) if (!context.equals("null"))
ctx = loadDocument(context); 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_STORAGE_ID", new Integer(storageId));
map.put("SCRIPTING_DOC_URI", "hahaha"); map.put("SCRIPTING_DOC_URI", "hahaha");
if (ctx != null) if (ctx != null)

View File

@ -81,7 +81,7 @@ public class _XScriptNameResolver extends MultiMethodTest {
log.println(description + ": " + logicalname); 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_STORAGE_ID", new Integer(storageId));
map.put("SCRIPTING_DOC_URI", util.utils.getFullTestURL(location)); map.put("SCRIPTING_DOC_URI", util.utils.getFullTestURL(location));

View File

@ -84,7 +84,7 @@ public class TestDataLoader {
private static Parameters getParameters(StringTokenizer st) { private static Parameters getParameters(StringTokenizer st) {
String separator = "="; String separator = "=";
HashMap map = new HashMap(5); HashMap<String,Object> map = new HashMap<String,Object>(5);
while (st.hasMoreTokens()) { while (st.hasMoreTokens()) {
String pair = st.nextToken(); String pair = st.nextToken();