Skip to content

Commit

Permalink
MONDRIAN: Convert code to use JDK1.5 features: generics, boxing/unbox…
Browse files Browse the repository at this point in the history
…ing, for-each loops, replace StringBuffer with StringBuilder wherever possible.

	Also update copyright notices.

[git-p4: depot-paths = "//open/mondrian/": change = 8249]
  • Loading branch information
julianhyde committed Dec 2, 2006
1 parent 05af0c6 commit 7edf268
Show file tree
Hide file tree
Showing 198 changed files with 4,505 additions and 4,408 deletions.
2 changes: 1 addition & 1 deletion src/main/mondrian/calc/DummyExp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public DummyExp(Type type) {
this.type = type;
}

public Object clone() {
public DummyExp clone() {
throw new UnsupportedOperationException();
}

Expand Down
23 changes: 9 additions & 14 deletions src/main/mondrian/calc/impl/AbstractCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ public void accept(CalcWriter calcWriter) {
String name = getName();
pw.print(name);
final Calc[] calcs = getCalcs();
final List argumentList = getArguments();
final List<Object> argumentList = getArguments();
if (calcs.length > 0 || !argumentList.isEmpty()) {
pw.print("(");
int k = 0;
for (int i = 0; i < calcs.length; i++) {
Calc calc = calcs[i];
for (Calc calc : calcs) {
if (k++ > 0) {
pw.print(", ");
}
calc.accept(calcWriter);
}
for (int i = 0; i < argumentList.size(); i++) {
Object o = (Object) argumentList.get(i);
for (Object o : argumentList) {
if (k++ > 0) {
pw.print(", ");
}
Expand Down Expand Up @@ -105,8 +103,7 @@ public boolean dependsOn(Dimension dimension) {
* Returns true if one of the calcs depends on the given dimension.
*/
public static boolean anyDepends(Calc[] calcs, Dimension dimension) {
for (int i = 0; i < calcs.length; i++) {
Calc calc = calcs[i];
for (Calc calc : calcs) {
if (calc != null && calc.dependsOn(dimension)) {
return true;
}
Expand Down Expand Up @@ -151,8 +148,7 @@ public static boolean anyDependsButFirst(
public static boolean butDepends(
Calc[] calcs, Dimension dimension) {
boolean result = true;
for (int i = 0; i < calcs.length; i++) {
Calc calc = calcs[i];
for (Calc calc : calcs) {
if (calc != null) {
if (calc.dependsOn(dimension)) {
return true;
Expand All @@ -169,8 +165,8 @@ public static boolean butDepends(
* Returns any other arguments to this calc.
* The default implementation returns the empty list.
*/
public List getArguments() {
return Collections.EMPTY_LIST;
public List<Object> getArguments() {
return Collections.emptyList();
}

/**
Expand All @@ -195,8 +191,7 @@ public static Evaluator simplifyEvaluator(Calc calc, Evaluator evaluator) {
int changeCount = 0;
Evaluator ev = evaluator;
final Dimension[] dimensions = evaluator.getCube().getDimensions();
for (int i = 0; i < dimensions.length; i++) {
Dimension dimension = dimensions[i];
for (Dimension dimension : dimensions) {
final Member member = ev.getContext(dimension);
if (member.isAll()) {
continue;
Expand All @@ -205,7 +200,7 @@ public static Evaluator simplifyEvaluator(Calc calc, Evaluator evaluator) {
continue;
}
final Member unconstrainedMember =
member.getHierarchy().getDefaultMember();
member.getHierarchy().getDefaultMember();
if (member == unconstrainedMember) {
// This is a hierarchy without an 'all' member, and the context
// is already the default member.
Expand Down
5 changes: 3 additions & 2 deletions src/main/mondrian/calc/impl/AbstractExpCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public class AbstractExpCompiler implements ExpCompiler {
private final Evaluator evaluator;
private final Validator validator;
private final Map parameterSlots = new HashMap();
private final Map<Parameter, ParameterSlotImpl> parameterSlots =
new HashMap<Parameter, ParameterSlotImpl>();
private ResultStyle[] resultStyles = {ResultStyle.ANY};
private static final ResultStyle[] MUTABLE_LIST_ONLY = {ResultStyle.MUTABLE_LIST};

Expand Down Expand Up @@ -223,7 +224,7 @@ public Calc compileScalar(Exp exp, boolean convert) {
}

public ParameterSlot registerParameter(Parameter parameter) {
ParameterSlot slot = (ParameterSlot) parameterSlots.get(parameter);
ParameterSlot slot = parameterSlots.get(parameter);
if (slot != null) {
return slot;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/calc/impl/AbstractIntegerCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected AbstractIntegerCalc(Exp exp, Calc[] calcs) {
}

public Object evaluate(Evaluator evaluator) {
return new Integer(evaluateInteger(evaluator));
return evaluateInteger(evaluator);
}

public Calc[] getCalcs() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/calc/impl/ConstantCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Calc[] getCalcs() {
* Creates an expression which evaluates to an integer.
*/
public static ConstantCalc constantInteger(int i) {
return new ConstantCalc(new NumericType(), new Integer(i));
return new ConstantCalc(new NumericType(), i);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/calc/impl/GenericCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public double evaluateDouble(Evaluator evaluator) {
}

public boolean evaluateBoolean(Evaluator evaluator) {
return ((Boolean) evaluate(evaluator)).booleanValue();
return (Boolean) evaluate(evaluator);
}

public void evaluateVoid(Evaluator evaluator) {
Expand Down
5 changes: 1 addition & 4 deletions src/main/mondrian/calc/impl/MemberValueCalc.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import mondrian.olap.type.ScalarType;
import mondrian.calc.*;

import java.util.ArrayList;

/**
* Expression which evaluates a few member expressions,
* sets the dimensional context to the result of those expressions,
Expand Down Expand Up @@ -71,8 +69,7 @@ public boolean dependsOn(Dimension dimension) {
if (super.dependsOn(dimension)) {
return true;
}
for (int i = 0; i < memberCalcs.length; i++) {
MemberCalc memberCalc = memberCalcs[i];
for (MemberCalc memberCalc : memberCalcs) {
// If the expression
if (memberCalc.getType().usesDimension(dimension, true)) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/main/mondrian/gui/SchemaExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 1999-2002 Kana Software, Inc.
// Copyright (C) 2001-2005 Julian Hyde and others
// Copyright (C) 2001-2006 Julian Hyde and others
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -324,7 +324,7 @@ protected void addDimension(ActionEvent evt)
dimension.name = "New Dimension " + cube.dimensions.length;
dimension.hierarchies = new MondrianDef.Hierarchy[1];
dimension.hierarchies[0] = new MondrianDef.Hierarchy();
dimension.hierarchies[0].hasAll = new Boolean(false);
dimension.hierarchies[0].hasAll = false;
dimension.hierarchies[0].levels = new MondrianDef.Level[0];
dimension.hierarchies[0].memberReaderParameters = new MondrianDef.MemberReaderParameter[0];
dimension.hierarchies[0].relation = new MondrianDef.Join();
Expand Down Expand Up @@ -352,7 +352,7 @@ protected void addLevel(ActionEvent evt)
MondrianDef.Hierarchy hierarchy = (MondrianDef.Hierarchy) path;

MondrianDef.Level level = new MondrianDef.Level();
level.uniqueMembers = new Boolean(false);
level.uniqueMembers = false;
level.name = "New Level " + hierarchy.levels.length;
level.properties = new MondrianDef.Property[0];
level.nameExp = new MondrianDef.NameExpression();
Expand Down
4 changes: 2 additions & 2 deletions src/main/mondrian/gui/SchemaPropertyCellEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Component getTableCellEditorComponent(JTable table, Object value, boolean
stringEditor.setText((String)value);
} else if (value instanceof Boolean) {
activeEditor = booleanEditor;
booleanEditor.setSelected(((Boolean)value).booleanValue());
booleanEditor.setSelected((Boolean) value);
} else if (value instanceof Integer) {
activeEditor = integerEditor;
integerEditor.setText((String)value);
Expand Down Expand Up @@ -142,7 +142,7 @@ public Object getCellEditorValue() {
if (activeEditor == stringEditor) {
return stringEditor.getText();
} else if (activeEditor == booleanEditor) {
return new Boolean(booleanEditor.isSelected());
return booleanEditor.isSelected();
} else if (activeEditor == tableEditor) {
return ((PropertyTableModel) tableEditor.getModel()).getValue();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/mondrian/gui/SchemaPropertyCellRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
stringRenderer.setText((String)value);
return stringRenderer;
} else if (value instanceof Boolean) {
booleanRenderer.setSelected(((Boolean)value).booleanValue());
booleanRenderer.setSelected((Boolean) value);
return booleanRenderer;
} else if (value instanceof Integer) {
integerRenderer.setText((String)value);
integerRenderer.setText(value.toString());
return integerRenderer;
} else if (value == null) {
return null;
Expand Down
17 changes: 8 additions & 9 deletions src/main/mondrian/i18n/LocalizingDynamicSchemaProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2005-2005 Julian Hyde
// Copyright (C) 2005-2006 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
Expand Down Expand Up @@ -46,10 +46,10 @@ public LocalizingDynamicSchemaProcessor() {
private static final int INVALID_LOCALE = 1;
private static final int FULL_LOCALE = 3;
private static final int LANG_LOCALE = 2;
private static final Set countries = Collections.unmodifiableSet(
new HashSet(Arrays.asList(Locale.getISOCountries())));
private static final Set languages = Collections.unmodifiableSet(
new HashSet(Arrays.asList(Locale.getISOLanguages())));
private static final Set<String> countries = Collections.unmodifiableSet(
new HashSet<String>(Arrays.asList(Locale.getISOCountries())));
private static final Set<String> languages = Collections.unmodifiableSet(
new HashSet<String>(Arrays.asList(Locale.getISOLanguages())));
private int localeType = INVALID_LOCALE;

void populate(String propFile) {
Expand Down Expand Up @@ -140,7 +140,7 @@ public String processSchema(

loadProperties();

StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
BufferedReader in = new BufferedReader(
new InputStreamReader(
schemaUrl.openStream()));
Expand Down Expand Up @@ -184,8 +184,7 @@ private String doRegExReplacements(String schema) {
private String extractKey(String group) {
// removes leading '%{' and tailing '%' from the matched string
// to obtain the required key
String key = group.substring(2, group.length() - 1);
return key;
return group.substring(2, group.length() - 1);
}

/**
Expand Down Expand Up @@ -217,7 +216,7 @@ public void setLocale(String locale) {
localeType = FULL_LOCALE;
}
} else {
if (locale!=null && locale.length()==2){
if (locale.length()==2){
//make sure that the language field is valid since that is all that was provided
if (languages.contains(locale.substring(0, 2))) {
localeType = LANG_LOCALE;
Expand Down
10 changes: 5 additions & 5 deletions src/main/mondrian/jolap/MondrianRankingMemberFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2002-2005 Julian Hyde
// Copyright (C) 2002-2006 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
Expand Down Expand Up @@ -46,15 +46,15 @@ Exp convert(Exp exp) throws OLAPException {
Exp _convert(Exp exp) throws OLAPException {
if (type == RankingTypeEnum.BOTTOM) {
if (bottomPercent) {
return new UnresolvedFunCall("BottomPercent", new Exp[] {exp, Literal.create(new Integer(bottom))});
return new UnresolvedFunCall("BottomPercent", new Exp[] {exp, Literal.create(bottom)});
} else {
return new UnresolvedFunCall("Bottom", new Exp[] {exp, Literal.create(new Integer(bottom))});
return new UnresolvedFunCall("Bottom", new Exp[] {exp, Literal.create(bottom)});
}
} else if (type == RankingTypeEnum.TOP) {
if (topPercent) {
return new UnresolvedFunCall("TopPercent", new Exp[] {exp, Literal.create(new Integer(top))});
return new UnresolvedFunCall("TopPercent", new Exp[] {exp, Literal.create(top)});
} else {
return new UnresolvedFunCall("Top", new Exp[] {exp, Literal.create(new Integer(top))});
return new UnresolvedFunCall("Top", new Exp[] {exp, Literal.create(top)});
}
} else if (type == RankingTypeEnum.TOP_BOTTOM) {
throw new UnsupportedOperationException();
Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/mdx/DimensionExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Type getType() {
return DimensionType.forDimension(dimension);
}

public Object clone() {
public DimensionExpr clone() {
return new DimensionExpr(dimension);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/mdx/HierarchyExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Type getType() {
return HierarchyType.forHierarchy(hierarchy);
}

public Object clone() {
public HierarchyExpr clone() {
return new HierarchyExpr(hierarchy);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/mdx/LevelExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Type getType() {
return LevelType.forLevel(level);
}

public Object clone() {
public LevelExpr clone() {
return new LevelExpr(level);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/mdx/MemberExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Type getType() {
return MemberType.forMember(member);
}

public Object clone() {
public MemberExpr clone() {
return new MemberExpr(member);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/mondrian/mdx/NamedSetExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import mondrian.calc.impl.AbstractListCalc;

import java.util.List;
import java.util.ArrayList;

/**
* Usage of a {@link mondrian.olap.NamedSet} in an MDX expression.
Expand Down Expand Up @@ -51,7 +50,7 @@ public String toString() {
return namedSet.getUniqueName();
}

public Object clone() {
public NamedSetExpr clone() {
return new NamedSetExpr(namedSet);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/mondrian/mdx/ParameterExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Object accept(MdxVisitor visitor) {
return visitor.visit(this);
}

public Object clone() {
public ParameterExpr clone() {
return new ParameterExpr(parameter);
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/mondrian/mdx/QueryPrintWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
*/
package mondrian.mdx;

import mondrian.olap.Parameter;

import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;

/**
* PrintWriter used for unparsing queries. Remembers which parameters have
* been printed. The first time, they print themselves as "Parameter";
* subsequent times as "ParamRef".
*/
public class QueryPrintWriter extends PrintWriter {
final HashSet parameters = new HashSet();
final Set<Parameter> parameters = new HashSet<Parameter>();

public QueryPrintWriter(Writer writer) {
super(writer);
Expand Down
5 changes: 2 additions & 3 deletions src/main/mondrian/mdx/ResolvedFunCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String toString() {
return Util.unparse(this);
}

public Object clone() {
public ResolvedFunCall clone() {
return new ResolvedFunCall(funDef, ExpBase.cloneArray(args), returnType);
}

Expand Down Expand Up @@ -153,8 +153,7 @@ public Calc accept(ExpCompiler compiler) {
public Object accept(MdxVisitor visitor) {
final Object o = visitor.visit(this);
// visit the call's arguments
for (int i = 0; i < args.length; i++) {
Exp arg = args[i];
for (Exp arg : args) {
arg.accept(visitor);
}
return o;
Expand Down
Loading

0 comments on commit 7edf268

Please sign in to comment.