Skip to content

Commit

Permalink
Merge pull request molgenis#100 from dennishendriksen/testing
Browse files Browse the repository at this point in the history
fix FindBugs WMI_WRONG_MAP_ITERATOR warnings
  • Loading branch information
RoanKanninga committed Oct 31, 2012
2 parents 646126c + 9a879fe commit 9122195
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 138 deletions.
10 changes: 6 additions & 4 deletions src/org/molgenis/framework/ui/FreemarkerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.log4j.Logger;
import org.molgenis.framework.ui.html.WidgetFactory;
Expand Down Expand Up @@ -97,14 +98,15 @@ public String render(String templatePath, Map<String, Object> templateArgs)// ,
// (nb this method is deprecated but I can't see why)
loaders.add(new ClassTemplateLoader());

for (Object key : templateArgs.keySet())
for (Entry<String, Object> entry : templateArgs.entrySet())
{
if ("model".equals(key) && templateArgs.get(key) != null)
Object value = entry.getValue();
if (entry.getKey() != null && entry.getKey().equals("model") && value != null)
{
loaders.add(new ClassTemplateLoader(templateArgs.get(key).getClass()));
loaders.add(new ClassTemplateLoader(value.getClass()));

// also add superclass because of generated code
loaders.add(new ClassTemplateLoader(templateArgs.get(key).getClass().getSuperclass()));
loaders.add(new ClassTemplateLoader(value.getClass().getSuperclass()));
}
}
loaders.add(new FileTemplateLoader());
Expand Down
10 changes: 6 additions & 4 deletions src/org/molgenis/framework/ui/html/TabbedLayout.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.molgenis.framework.ui.html;

import java.util.Map;
import java.util.Map.Entry;

public class TabbedLayout extends MultipanelLayout
{
Expand Down Expand Up @@ -29,17 +30,18 @@ public String render()
// create tabs
strBuilder.append("<ul>");
int i = 0;
for (String label : elements.keySet())
for (Entry<String, HtmlElement> entry : elements.entrySet())
{
if (elements.get(label) instanceof HyperlinkInput)
HtmlElement htmlElement = entry.getValue();
if (htmlElement instanceof HyperlinkInput)
{
strBuilder.append("<li><a href=\"").append(((HyperlinkInput) elements.get(label)).getValue());
strBuilder.append("<li><a href=\"").append(((HyperlinkInput) htmlElement).getValue());
strBuilder.append("\">").append("</a></li>");
}
else
{
strBuilder.append("<li><a href=\"#").append(getId()).append('-').append(i++).append("\">");
strBuilder.append(label).append("</a></li>");
strBuilder.append(entry.getKey()).append("</a></li>");
}
}
strBuilder.append("</ul>");
Expand Down
121 changes: 3 additions & 118 deletions src/org/molgenis/framework/ui/html/WidgetFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.molgenis.util.SimpleTuple;

Expand Down Expand Up @@ -87,126 +88,10 @@ public static void configure(Configuration conf)
map.put("text", new TextInput());
map.put("hidden", new HiddenInput());

for (String key : map.keySet())
for (Entry<String, HtmlInput<?>> entry : map.entrySet())
{
conf.setSharedVariable(key, new HtmlInputAdapter(map.get(key)));
conf.setSharedVariable(entry.getKey(), new HtmlInputAdapter(entry.getValue()));
}

}
// private Database db;
//
// private static String NAME = "name";
// private static String LABEL = "name";
// private static String VALUE = "name";
// private static String NILLABlE = "nillable";
// private static String READONLY = "readonly";
//
//
// /**
// * Constructor
// *
// * @param db
// * database that is used to construct XREFs and other data
// * dependant widgets
// */
// public WidgetFactory(Database db)
// {
// this.db = db;
// }
//
// /** Factory method for <@date */
// public DateInput date(String name, String label, Date value,
// boolean nillable, boolean readonly)
// {
// return new DateInput(name, "null".equals(label) ? null : label, value,
// nillable, readonly);
// }
//
// /** Factory method for <@datetime */
// public DatetimeInput datetime(String name, String label, Date value,
// boolean nillable, boolean readonly)
// {
// return new DatetimeInput(name, "null".equals(label) ? null : label,
// value, nillable, readonly);
// }
//
// /** Helper method for date default value */
// public Date now()
// {
// return new Date();
// }
//
// /** Factory method for <@action */
// public ActionInput action(String name, String label)
// {
// return new ActionInput(name, "null".equals(label) ? null : label);
// }
//
// /** Factory method for <@string */
// public StringInput string(String name, String label, String value,
// boolean nillable, boolean readonly)
// {
// return new StringInput(name, "null".equals(label) ? null : label,
// "null".equals(value) ? null : value, nillable, readonly);
// }
//
// /** Factory method for <@int */
// public IntInput integer(String name, String label, Integer value,
// boolean nillable, boolean readonly)
// {
// return new IntInput(name, "null".equals(label) ? null : label, "null"
// .equals(value) ? null : value, nillable, readonly);
// }
//
// /** Factory method for <@double */
// public DecimalInput decimal(String name, String label, Double value,
// boolean nillable, boolean readonly)
// {
// return new DecimalInput(name, "null".equals(label) ? null : label,
// "null".equals(value) ? null : value, nillable, readonly);
// }
//
// /** Factory method for <@xref */
// public EntityInput xref(String name, String entity, String label,
// Double value, boolean nillable, boolean readonly)
// {
// return new XrefInput(name, entity, db, "null".equals(label) ? null
// : label, "null".equals(value) ? null : value, nillable,
// readonly);
// }
//
// /** Factory method for <@mref */
// public MrefInput mref(String name, String entity, String label,
// Double value, boolean nillable, boolean readonly)
// {
// return new MrefInput(name, entity, db, "null".equals(label) ? null
// : label, "null".equals(value) ? null : value, nillable,
// readonly);
// }
//
// /** Factory method for <@file */
// public FileInput file(String name, String entity, String label,
// String value, boolean nillable, boolean readonly)
// {
// return new FileInput(name, "null".equals(label) ? null : label, "null"
// .equals(value) ? null : value, nillable, readonly);
// }
//
// /** Factory method for <@file */
// public BoolInput bool(String name, String entity, String label,
// Boolean value, boolean nillable, boolean readonly)
// {
// return new BoolInput(name, "null".equals(label) ? null : label, value,
// nillable, readonly);
// }
//
// /** Factory method for <@checkbox */
// public CheckboxInput checkbox(String name, List<String> options,
// List<String> optionLabels, String value, String label,
// boolean nillable, boolean readonly)
// {
// return new CheckboxInput(name, options, optionLabels, "null"
// .equals(label) ? null : label, value, nillable, readonly);
// }

}
12 changes: 7 additions & 5 deletions src/org/molgenis/model/MolgenisModelValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Vector;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -597,14 +598,15 @@ public static void validateForeignKeys(Model model) throws MolgenisModelExceptio
+ ". \nCouldn't find suitable secondary keys to use as xref_label. \nDid you set a unique=\"true\" or <unique fields=\" ...>?");
}

for (String validLabel : candidates.keySet())
for (Entry<String, List<Field>> entry : candidates.entrySet())
{
// logger.debug("Checking: "+validLabel);
if (xref_label_name.equals(validLabel))
String key = entry.getKey();
if (xref_label_name.equals(key))
{
xref_label = candidates.get(validLabel).get(candidates.get(validLabel).size() - 1);
List<Field> value = entry.getValue();
xref_label = value.get(value.size() - 1);
}
validFieldsBuilder.append(',').append(validLabel);
validFieldsBuilder.append(',').append(key);
}

// still null, must be error
Expand Down
8 changes: 5 additions & 3 deletions src/org/molgenis/model/elements/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,13 @@ else if (label.contains("_"))
{
// match agains all known labels
Map<String, List<Field>> candidates = this.allPossibleXrefLabels();
for (String test : candidates.keySet())
for (Entry<String, List<Field>> entry : candidates.entrySet())
{
if (test.toLowerCase().equals(label.toLowerCase()))
String key = entry.getKey();
if (key.toLowerCase().equals(label.toLowerCase()))
{
result.add(candidates.get(test).get(candidates.get(test).size() - 1));
List<Field> value = entry.getValue();
result.add(value.get(value.size() - 1));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/org/molgenis/util/PropertiesTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map.Entry;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -33,9 +34,9 @@ public PropertiesTuple(Properties p)

private void loadFromProperties(Properties p)
{
for (Object key : p.keySet())
for (Entry<Object, Object> entry : p.entrySet())
{
this.set(key.toString(), p.get(key));
this.set(entry.getKey().toString(), entry.getValue());
}
}
}
5 changes: 3 additions & 2 deletions src/org/molgenis/util/SimpleTuple.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TimeZone;
Expand Down Expand Up @@ -105,9 +106,9 @@ public SimpleTuple(List<String> columnNames)

public SimpleTuple(Map<String, Object> valueMap)
{
for (String key : valueMap.keySet())
for (Entry<String, Object> entry : valueMap.entrySet())
{
this.set(key, valueMap.get(key));
this.set(entry.getKey(), entry.getValue());
}
}

Expand Down

0 comments on commit 9122195

Please sign in to comment.