Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Typed some collections and replaced a bunch of while loops with Java5…
… foreach loops.

git-svn-id: https://svn.eu.apache.org/repos/asf/cayenne/main/trunk@729777 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
kmenard committed Dec 28, 2008
1 parent b0be8c5 commit 071c7d5
Show file tree
Hide file tree
Showing 54 changed files with 247 additions and 364 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
target
Expand Up @@ -491,8 +491,8 @@ public void addRecentFileListListener(RecentFileListListener listener) {
* Notifies all listeners that recent file list has changed
*/
public void fireRecentFileListChanged() {
for (int i = 0; i < recentFileListeners.size(); i++) {
recentFileListeners.get(i).recentFileListChanged();
for (RecentFileListListener recentFileListener : recentFileListeners) {
recentFileListener.recentFileListChanged();
}
}
}
Expand Up @@ -69,9 +69,8 @@ public synchronized void setPathFiles(Collection<File> files) {
pathFiles.clear();
classLoader = null;

Iterator it = files.iterator();
while (it.hasNext()) {
addFile((File) it.next());
for (File file : files) {
addFile(file);
}
}

Expand Down Expand Up @@ -113,13 +112,10 @@ static class FileClassLoader extends URLClassLoader {
super(new URL[0], parent);
}

FileClassLoader(ClassLoader parent, List files) {
FileClassLoader(ClassLoader parent, List<File> files) {
this(parent);

Iterator it = files.iterator();
while (it.hasNext()) {
File file = (File) it.next();

for (File file : files) {
// I guess here we have to quetly ignore invalid URLs...
try {
addURL(file.toURI().toURL());
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -218,8 +218,8 @@ public DefaultMutableTreeNode getStartNode() {
public ProjectPath registerNodes(TreeNode[] nodes) {
ProjectPath path = new ProjectPath();

for (int i = 0; i < nodes.length; i++) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) nodes[i];
for (TreeNode node : nodes) {
DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;

path = path.appendToPath(treeNode.getUserObject());

Expand Down
Expand Up @@ -572,10 +572,9 @@ public void dataMapRemoved(DataMapEvent e) {
});

// Clean up map from the nodes
Iterator nodes = new ArrayList(domain.getDataNodes()).iterator();
while (nodes.hasNext()) {
removeNode(new Object[] {
domain, nodes.next(), map
for (DataNode dataNode : new ArrayList<DataNode>(domain.getDataNodes())) {
removeNode(new Object[]{
domain, dataNode, map
});
}
}
Expand Down
Expand Up @@ -83,16 +83,16 @@ public final void performAction(ActionEvent e, boolean allowAsking) {
private void removeCallbackMethods(ActionEvent actionEvent) {
ProjectController mediator = getProjectController();
CallbackType callbackType = mediator.getCurrentCallbackType();

String[] callbackMethods = mediator.getCurrentCallbackMethods();
for (int i = 0; i < callbackMethods.length; i++) {
getCallbackMap().getCallbackDescriptor(callbackType.getType()).removeCallbackMethod(callbackMethods[i]);

for (String callbackMethod : callbackMethods) {
getCallbackMap().getCallbackDescriptor(callbackType.getType()).removeCallbackMethod(callbackMethod);
CallbackMethodEvent e = new CallbackMethodEvent(
actionEvent.getSource(),
null,
callbackMethods[i],
MapEvent.REMOVE);
actionEvent.getSource(),
null,
callbackMethod,
MapEvent.REMOVE);
mediator.fireCallbackMethodEvent(e);
}
}
Expand Down
Expand Up @@ -151,8 +151,8 @@ else if (mediator.getCurrentDataDomain() != null) {
else if (mediator.getCurrentPaths() != null) { //multiple deletion
if (dialog.shouldDelete("selected objects")) {
ProjectPath[] paths = mediator.getCurrentPaths();
for (int i = 0; i < paths.length; i++) {
removeLastPathComponent(paths[i]);
for (ProjectPath path : paths) {
removeLastPathComponent(path);
}
}
}
Expand Down Expand Up @@ -263,15 +263,14 @@ private void removeObjEntity(DataMap map, ObjEntity entity) {
// TODO: (Andrus, 09/09/2005) show warning dialog?

// clone to be able to remove within iterator...
Iterator it = new ArrayList(map.getQueries()).iterator();
while (it.hasNext()) {
AbstractQuery next = (AbstractQuery) it.next();
for (Query query : new ArrayList<Query>(map.getQueries())) {
AbstractQuery next = (AbstractQuery) query;
Object root = next.getRoot();

if (root == entity
|| (root instanceof String && root
.toString()
.equals(entity.getName()))) {
.toString()
.equals(entity.getName()))) {
removeQuery(map, next);
}
}
Expand Down
Expand Up @@ -99,13 +99,13 @@ protected void removeDbAttributes() {
ProjectController mediator = getProjectController();
DbEntity entity = mediator.getCurrentDbEntity();
DbAttribute[] attribs = mediator.getCurrentDbAttributes();
for (int i = 0; i < attribs.length; i++) {
entity.removeAttribute(attribs[i].getName());

for (DbAttribute attrib : attribs) {
entity.removeAttribute(attrib.getName());

AttributeEvent e = new AttributeEvent(
Application.getFrame(),
attribs[i],
attrib,
entity,
MapEvent.REMOVE);
mediator.fireDbAttributeEvent(e);
Expand All @@ -119,12 +119,12 @@ protected void removeObjAttributes() {
ObjEntity entity = mediator.getCurrentObjEntity();

ObjAttribute[] attribs = mediator.getCurrentObjAttributes();
for (int i = 0; i < attribs.length; i++) {
entity.removeAttribute(attribs[i].getName());

for (ObjAttribute attrib : attribs) {
entity.removeAttribute(attrib.getName());
AttributeEvent e = new AttributeEvent(
Application.getFrame(),
attribs[i],
attrib,
entity,
MapEvent.REMOVE);
mediator.fireObjAttributeEvent(e);
Expand Down
Expand Up @@ -84,14 +84,14 @@ public void performAction(ActionEvent e, boolean allowAsking) {
protected void removeProcedureParameters() {
ProjectController mediator = getProjectController();
ProcedureParameter[] parameters = mediator.getCurrentProcedureParameters();
for (int i = 0; i < parameters.length; i++) {
mediator.getCurrentProcedure().removeCallParameter(parameters[i].getName());

for (ProcedureParameter parameter : parameters) {
mediator.getCurrentProcedure().removeCallParameter(parameter.getName());

ProcedureParameterEvent e = new ProcedureParameterEvent(
Application.getFrame(),
parameters[i],
MapEvent.REMOVE);
Application.getFrame(),
parameter,
MapEvent.REMOVE);

mediator.fireProcedureParameterEvent(e);
}
Expand Down
Expand Up @@ -99,14 +99,14 @@ protected void removeObjRelationships() {
ProjectController mediator = getProjectController();
ObjEntity entity = mediator.getCurrentObjEntity();
ObjRelationship[] rels = mediator.getCurrentObjRelationships();
for (int i = 0; i < rels.length; i++) {
entity.removeRelationship(rels[i].getName());

for (ObjRelationship rel : rels) {
entity.removeRelationship(rel.getName());
RelationshipEvent e = new RelationshipEvent(
Application.getFrame(),
rels[i],
entity,
MapEvent.REMOVE);
Application.getFrame(),
rel,
entity,
MapEvent.REMOVE);
mediator.fireObjRelationshipEvent(e);
}
}
Expand All @@ -115,15 +115,15 @@ protected void removeDbRelationships() {
ProjectController mediator = getProjectController();
DbEntity entity = mediator.getCurrentDbEntity();
DbRelationship[] rels = mediator.getCurrentDbRelationships();
for (int i = 0; i < rels.length; i++) {
entity.removeRelationship(rels[i].getName());

for (DbRelationship rel : rels) {
entity.removeRelationship(rel.getName());

RelationshipEvent e = new RelationshipEvent(
Application.getFrame(),
rels[i],
entity,
MapEvent.REMOVE);
Application.getFrame(),
rel,
entity,
MapEvent.REMOVE);
mediator.fireDbRelationshipEvent(e);
}

Expand Down
Expand Up @@ -131,11 +131,9 @@ public void actionPerformed(ActionEvent e) {
Color color = view.getOkButton().getBackground();
EntityButtonsIdListAndButtonId = new HashMap<Integer, Integer>();
Integer idEntityButtons = 0;
Iterator it = view.getEntityButtons().iterator();
while (it.hasNext()) {
JButton b = (JButton) it.next();
for (JButton b : view.getEntityButtons()) {
b.addActionListener(new JumpToResultActionListener());
b.addKeyListener(new JumpToResultsKeyListener());
b.addKeyListener(new JumpToResultsKeyListener());
EntityButtonsIdListAndButtonId.put(((FindDialogView.EntityButtonModel) b.getModel()).getIndex().intValue(), idEntityButtons);
idEntityButtons++;
}
Expand Down
Expand Up @@ -51,7 +51,7 @@
public class FindDialogView extends JDialog {

private JButton okButton;
private java.util.List entityButtons;
private java.util.List<JButton> entityButtons;
private static JScrollPane scrollPane;

public FindDialogView(Map objEntityNames, Map dbEntityNames, Map attrNames,
Expand Down Expand Up @@ -119,7 +119,7 @@ public JButton getOkButton() {
return okButton;
}

public java.util.List getEntityButtons() {
public java.util.List<JButton> getEntityButtons() {
return entityButtons;
}

Expand Down
Expand Up @@ -374,7 +374,7 @@ private boolean validateName(Entity entity, Relationship aRelationship, String n
}

private Collection getReverseJoins() {
Collection joins = relationship.getJoins();
Collection<DbJoin> joins = relationship.getJoins();

if ((joins == null) || (joins.size() == 0)) {
return Collections.EMPTY_LIST;
Expand All @@ -384,9 +384,7 @@ private Collection getReverseJoins() {

// Loop through the list of attribute pairs, create reverse pairs
// and put them to the reverse list.
Iterator it = joins.iterator();
while (it.hasNext()) {
DbJoin pair = (DbJoin) it.next();
for (DbJoin pair : joins) {
DbJoin reverseJoin = pair.createReverseJoin();

// since reverse relationship is not yet initialized,
Expand Down
Expand Up @@ -83,14 +83,12 @@ protected String buildValidationText(ValidationResult validationResult) {
StringBuffer buffer = new StringBuffer();
String separator = System.getProperty("line.separator");

Iterator it = validationResult.getFailures().iterator();
while (it.hasNext()) {
for (ValidationFailure failure : validationResult.getFailures()) {

if (buffer.length() > 0) {
buffer.append(separator);
}

ValidationFailure failure = (ValidationFailure) it.next();
if (failure.getSource() != null) {
buffer.append("[SQL: ").append(failure.getSource()).append("] - ");
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ public abstract class CodeGeneratorControllerBase extends CayenneController {

protected ValidationResult validation;

protected List entities;
protected List<ObjEntity> entities;
protected Set selectedEntities;

protected transient ObjEntity currentEntity;
Expand All @@ -68,9 +68,8 @@ public void validate(GeneratorController validator) {
ValidationResult validationBuffer = new ValidationResult();

if (validator != null) {
Iterator it = entities.iterator();
while (it.hasNext()) {
validator.validateEntity(validationBuffer, (ObjEntity) it.next(), false);
for (ObjEntity entity : entities) {
validator.validateEntity(validationBuffer, entity, false);
}
}

Expand All @@ -81,18 +80,14 @@ public boolean updateSelection(Predicate predicate) {

boolean modified = false;

Iterator it = entities.iterator();
while (it.hasNext()) {
ObjEntity entity = (ObjEntity) it.next();

for (ObjEntity entity : entities) {
boolean select = predicate.evaluate(entity);

if (select) {
if (selectedEntities.add(entity.getName())) {
modified = true;
}
}
else {
} else {
if (selectedEntities.remove(entity.getName())) {
modified = true;
}
Expand All @@ -115,11 +110,9 @@ public Collection<Embeddable> getSelectedEmbeddables() {
public List<ObjEntity> getSelectedEntities() {
List<ObjEntity> selected = new ArrayList<ObjEntity>(selectedEntities.size());

Iterator it = entities.iterator();
while (it.hasNext()) {
ObjEntity e = (ObjEntity) it.next();
if (selectedEntities.contains(e.getName())) {
selected.add(e);
for (ObjEntity entity : entities) {
if (selectedEntities.contains(entity.getName())) {
selected.add(entity);
}
}

Expand Down
Expand Up @@ -215,11 +215,8 @@ public void validateEntity(
}

{
Iterator it = entity.getRelationships().iterator();
while (it.hasNext()) {

ValidationFailure failure = validateRelationship((ObjRelationship) it
.next(), clientValidation);
for (ObjRelationship rel : entity.getRelationships()) {
ValidationFailure failure = validateRelationship(rel, clientValidation);
if (failure != null) {
validationBuffer.addFailure(failure);
return;
Expand Down
Expand Up @@ -87,20 +87,14 @@ public void updateAction() {
boolean updateRelationships = view.getRelationships().isSelected();
ProjectController parent = (ProjectController) getParent();

Iterator it = dataMap.getObjEntities().iterator();
while (it.hasNext()) {
ObjEntity entity = (ObjEntity) it.next();

for (ObjEntity entity : dataMap.getObjEntities()) {
if (updateEntities && defaultLockType != entity.getDeclaredLockType()) {
entity.setDeclaredLockType(defaultLockType);
parent.fireObjEntityEvent(new EntityEvent(this, entity));
}

if (updateAttributes) {
Iterator attributes = entity.getAttributes().iterator();
while (attributes.hasNext()) {

ObjAttribute a = (ObjAttribute) attributes.next();
for (ObjAttribute a : entity.getAttributes()) {
if (a.isUsedForLocking() != on) {
a.setUsedForLocking(on);
parent.fireObjAttributeEvent(new AttributeEvent(this, a, entity));
Expand All @@ -109,10 +103,7 @@ public void updateAction() {
}

if (updateRelationships) {
Iterator relationships = entity.getRelationships().iterator();
while (relationships.hasNext()) {

ObjRelationship r = (ObjRelationship) relationships.next();
for (ObjRelationship r : entity.getRelationships()) {
if (r.isUsedForLocking() != on) {
r.setUsedForLocking(on);
parent.fireObjRelationshipEvent(new RelationshipEvent(
Expand Down

0 comments on commit 071c7d5

Please sign in to comment.