ItEr33S08ValidacionEProbasFuncionaisItEr32S09: Converting one line if statements to block

This commit is contained in:
Óscar González Fernández 2009-11-03 20:38:03 +01:00
parent a240a640f3
commit b636354971
88 changed files with 592 additions and 357 deletions

View file

@ -163,8 +163,9 @@ public class DataForPlanner {
@Override
public List<ITaskFundamentalProperties> getChildren(
ITaskFundamentalProperties object) {
if (object == container)
if (object == container) {
return containerChildren;
}
return new ArrayList<ITaskFundamentalProperties>();
}

View file

@ -70,8 +70,9 @@ public class ShareBean {
}
public void setName(String name) {
if (StringUtils.isEmpty(name))
if (StringUtils.isEmpty(name)) {
return;
}
this.name = name;
}
@ -80,8 +81,9 @@ public class ShareBean {
}
public void setHours(Integer share) {
if (share == null || share <= 0)
if (share == null || share <= 0) {
return;
}
this.hours = share;
}

View file

@ -47,12 +47,15 @@ public class DependencyComponent extends XulElement implements AfterCompose {
public DependencyComponent(TaskComponent source, TaskComponent destination,
DependencyType type) {
this.type = type;
if (source == null)
if (source == null) {
throw new IllegalArgumentException("source cannot be null");
if (destination == null)
}
if (destination == null) {
throw new IllegalArgumentException("destination cannot be null");
if (type == null)
}
if (type == null) {
throw new IllegalArgumentException("type must be not null");
}
this.source = source;
this.destination = destination;
}

View file

@ -77,8 +77,9 @@ public class DependencyList extends XulElement implements AfterCompose {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!evt.getPropertyName().equals("visible"))
if (!evt.getPropertyName().equals("visible")) {
return;
}
if (dependencyMustBeVisible() != isDependencyNowVisible()) {
toggleDependencyExistence(dependencyMustBeVisible());
}
@ -156,8 +157,9 @@ public class DependencyList extends XulElement implements AfterCompose {
listener = new IZoomLevelChangedListener() {
@Override
public void zoomLevelChanged(ZoomLevel detailLevel) {
if (!isInPage())
if (!isInPage()) {
return;
}
for (DependencyComponent dependencyComponent : getDependencyComponents()) {
dependencyComponent.zoomChanged();
}

View file

@ -61,10 +61,12 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
@Override
public Task findAssociatedBean(T domainObject)
throws IllegalArgumentException {
if (domainObject == null)
if (domainObject == null) {
throw new IllegalArgumentException("domainObject is null");
if (!fromDomainToTask.containsKey(domainObject))
}
if (!fromDomainToTask.containsKey(domainObject)) {
throw new IllegalArgumentException("not found " + domainObject);
}
return fromDomainToTask.get(domainObject);
}
@ -85,8 +87,9 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
fromTaskToParent.put(task, parent);
} else if (insertionPositionForTop != null) {
topLevel.add(insertionPositionForTop, task);
} else
} else {
topLevel.add(task);
}
}
void remove(T domainObject) {
@ -104,10 +107,12 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
@Override
public T findAssociatedDomainObject(Task task)
throws IllegalArgumentException {
if (task == null)
if (task == null) {
throw new IllegalArgumentException("taskBean is null");
if (!fromTaskToDomain.containsKey(task))
}
if (!fromTaskToDomain.containsKey(task)) {
throw new IllegalArgumentException();
}
return fromTaskToDomain.get(task);
}
@ -283,8 +288,9 @@ public class FunctionalityExposedForExtensions<T> implements IContext<T> {
}
public void addDependency(Dependency dependency) {
if (!canAddDependency(dependency))
if (!canAddDependency(dependency)) {
return;
}
diagramGraph.add(dependency);
getDependencyList().addDependencyComponent(
getTaskList().asDependencyComponent(dependency));

View file

@ -205,8 +205,9 @@ public class LeftTasksTree extends HtmlMacroComponent {
}
private int getPositionOfChild() {
if (positionOfChildCached != null)
if (positionOfChildCached != null) {
return positionOfChildCached;
}
int[] path = tasksTreeModel.getPath(parent, child);
return positionOfChildCached = path[path.length - 1];
}
@ -251,8 +252,9 @@ public class LeftTasksTree extends HtmlMacroComponent {
}
public void isBeingRendered(final Task parent, final Treeitem item) {
if (!pendingToAddChildren.contains(parent))
if (!pendingToAddChildren.contains(parent)) {
return;
}
markLoaded(item);
fillModel(parent, 0, parent.getTasks(), false);
pendingToAddChildren.remove(parent);
@ -270,8 +272,9 @@ public class LeftTasksTree extends HtmlMacroComponent {
private Method setLoadedMethod = null;
private Method getSetLoadedMethod() {
if (setLoadedMethod != null)
if (setLoadedMethod != null) {
return setLoadedMethod;
}
try {
Method method = Treeitem.class.getDeclaredMethod("setLoaded",
Boolean.TYPE);

View file

@ -196,9 +196,9 @@ public class LeftTasksTreeRow extends GenericForwardComposer {
}
break;
case RIGHT:
if (position < textBoxes.size() - 1)
if (position < textBoxes.size() - 1) {
textBoxes.get(position + 1).focus();
else {
} else {
focusGoDown(0);
}
break;

View file

@ -75,8 +75,9 @@ public class Planner extends HtmlMacroComponent {
}
TaskList getTaskList() {
if (ganttPanel == null)
if (ganttPanel == null) {
return null;
}
List<Object> children = ganttPanel.getChildren();
return ComponentsFinder.findComponentsOfType(TaskList.class, children).get(0);
}
@ -86,13 +87,15 @@ public class Planner extends HtmlMacroComponent {
}
public DependencyList getDependencyList() {
if (ganttPanel == null)
if (ganttPanel == null) {
return null;
}
List<Object> children = ganttPanel.getChildren();
List<DependencyList> found = ComponentsFinder.findComponentsOfType(DependencyList.class,
children);
if (found.isEmpty())
if (found.isEmpty()) {
return null;
}
return found.get(0);
}
@ -134,8 +137,9 @@ public class Planner extends HtmlMacroComponent {
}
public <T> void setConfiguration(PlannerConfiguration<T> configuration) {
if (configuration == null)
if (configuration == null) {
return;
}
this.diagramGraph = new GanttDiagramGraph();
FunctionalityExposedForExtensions<T> context = new FunctionalityExposedForExtensions<T>(
this, configuration.getAdapter(), configuration.getNavigator(),
@ -200,8 +204,9 @@ public class Planner extends HtmlMacroComponent {
private <T> CommandContextualized<T> contextualize(IContext<T> context,
ICommand<T> command) {
if (command == null)
if (command == null) {
return null;
}
return CommandContextualized.create(command, context);
}

View file

@ -78,8 +78,9 @@ public class TabsRegistry {
private void hideAllExcept(ITab tab) {
for (ITab t : tabs) {
if (t.equals(tab))
if (t.equals(tab)) {
continue;
}
t.hide();
}
}

View file

@ -62,10 +62,11 @@ public class TaskComponent extends Div implements AfterCompose {
private static int stripPx(String pixels) {
Matcher matcher = pixelsSpecificationPattern.matcher(pixels);
if (!matcher.matches())
if (!matcher.matches()) {
throw new IllegalArgumentException("pixels " + pixels
+ " is not valid. It must be "
+ pixelsSpecificationPattern.pattern());
}
return Integer.valueOf(matcher.group(1));
}
@ -311,8 +312,9 @@ public class TaskComponent extends Div implements AfterCompose {
@Override
public void setParent(Component parent) {
if (parent != null && !(parent instanceof TaskList))
if (parent != null && !(parent instanceof TaskList)) {
throw new UiException("Unsupported parent for rows: " + parent);
}
super.setParent(parent);
}
@ -321,8 +323,9 @@ public class TaskComponent extends Div implements AfterCompose {
}
private void updateProperties() {
if (!isInPage())
if (!isInPage()) {
return;
}
setLeft("0");
setLeft(getMapper().toPixels(this.task.getBeginDate()) + "px");
setWidth("0");

View file

@ -55,8 +55,9 @@ public class TaskContainerComponent extends TaskComponent implements
public TaskContainerComponent(TaskContainer taskContainer, TaskList taskList) {
super(taskContainer, taskList.getDisabilityConfiguration());
if (!taskContainer.isContainer())
if (!taskContainer.isContainer()) {
throw new IllegalArgumentException();
}
this.expandListener = new IExpandListener() {
@Override

View file

@ -148,8 +148,9 @@ public class TaskList extends XulElement implements AfterCompose {
private TaskComponent getFirstTopTaskComponent() {
List<TaskComponent> taskComponents = getTopLevelTaskComponents();
if (taskComponents.isEmpty())
if (taskComponents.isEmpty()) {
return null;
}
return taskComponents.get(0);
}
@ -194,8 +195,9 @@ public class TaskList extends XulElement implements AfterCompose {
private void addListenerForTaskComponentEditForm(
final TaskComponent taskComponent) {
if (editTaskCommand == null)
if (editTaskCommand == null) {
return;
}
taskComponent.addEventListener("onDoubleClick", new EventListener() {
@Override

View file

@ -87,10 +87,11 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
}
public void setLengthMilliseconds(long lengthMilliseconds) {
if (lengthMilliseconds < 0)
if (lengthMilliseconds < 0) {
throw new IllegalArgumentException(
"a task must not have a negative length. Received value: "
+ lengthMilliseconds);
}
this.lengthMilliseconds = lengthMilliseconds;
}

View file

@ -77,12 +77,15 @@ public class Dependency {
public Dependency(Task source, Task destination,
DependencyType type, boolean visible) {
if (source == null)
if (source == null) {
throw new IllegalArgumentException("source cannot be null");
if (destination == null)
}
if (destination == null) {
throw new IllegalArgumentException("destination cannot be null");
if (type == null)
}
if (type == null) {
throw new IllegalArgumentException("type cannot be null");
}
this.source = source;
this.destination = destination;
this.type = type;
@ -102,12 +105,15 @@ public class Dependency {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
Dependency other = (Dependency) obj;
return new EqualsBuilder().append(this.destination, other.destination)
.append(this.source, other.source)

View file

@ -79,8 +79,9 @@ public enum DependencyType {
};
private static Date getBigger(Date date1, Date date2) {
if (date1.before(date2))
if (date1.before(date2)) {
return date2;
}
return date1;
}

View file

@ -67,16 +67,18 @@ public class GanttDiagramGraph {
private final Map<Task, Object> alreadyRegistered = new WeakHashMap<Task, Object>();
private ParentShrinkingEnforcer(final TaskContainer container) {
if (container == null)
if (container == null) {
throw new IllegalArgumentException("container cannot be null");
}
this.container = container;
registerListeners();
}
void registerListeners() {
for (Task subtask : this.container.getTasks()) {
if (alreadyRegistered.containsKey(subtask))
if (alreadyRegistered.containsKey(subtask)) {
continue;
}
subtask
.addFundamentalPropertiesChangeListener(new PropertyChangeListener() {
@ -102,8 +104,9 @@ public class GanttDiagramGraph {
private final Task task;
private DependencyRulesEnforcer(Task task) {
if (task == null)
if (task == null) {
throw new IllegalArgumentException("task cannot be null");
}
this.task = task;
this.task
.addFundamentalPropertiesChangeListener(new PropertyChangeListener() {
@ -121,8 +124,9 @@ public class GanttDiagramGraph {
Date beginDate = task.getBeginDate();
Date newStart = Dependency
.calculateStart(task, beginDate, incoming);
if (!beginDate.equals(newStart))
if (!beginDate.equals(newStart)) {
task.setBeginDate(newStart);
}
Date endDate = task.getEndDate();
Date newEnd = Dependency.calculateEnd(task, endDate, incoming);
if (!endDate.equals(newEnd)) {

View file

@ -53,14 +53,17 @@ public abstract class Task implements ITaskFundamentalProperties {
public Task(String name, Date beginDate, long lengthMilliseconds) {
this();
if (name == null)
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
if (beginDate == null)
}
if (beginDate == null) {
throw new IllegalArgumentException("beginDate cannot be null");
if (lengthMilliseconds < 0)
}
if (lengthMilliseconds < 0) {
throw new IllegalArgumentException(
"length in milliseconds must be positive. Instead it is "
+ lengthMilliseconds);
}
this.fundamentalProperties.setName(name);
this.fundamentalProperties.setBeginDate(beginDate);
this.fundamentalProperties.setLengthMilliseconds(lengthMilliseconds);

View file

@ -57,8 +57,9 @@ public class TaskContainer extends Task {
private static <T> T getSmallest(Collection<T> elements,
Comparator<T> comparator) {
List<T> withoutNulls = removeNulls(elements);
if (withoutNulls.isEmpty())
if (withoutNulls.isEmpty()) {
throw new IllegalArgumentException("at least one required");
}
T result = null;
for (T element : withoutNulls) {
result = result == null ? element : (comparator.compare(result,
@ -111,8 +112,9 @@ public class TaskContainer extends Task {
}
public Date getSmallestBeginDateFromChildren() {
if (tasks.isEmpty())
if (tasks.isEmpty()) {
return getBeginDate();
}
return getSmallest(getStartDates());
}
@ -133,8 +135,9 @@ public class TaskContainer extends Task {
}
public Date getBiggestDateFromChildren() {
if (tasks.isEmpty())
if (tasks.isEmpty()) {
return getEndDate();
}
return getBiggest(getEndDates());
}

View file

@ -54,8 +54,9 @@ public class LoadLevel {
protected abstract boolean contains(int percentage);
public static Category categoryFor(int percentage) {
for (Category category : values()) {
if (category.contains(percentage))
if (category.contains(percentage)) {
return category;
}
}
throw new IllegalArgumentException("couldn't handle " + percentage);
}

View file

@ -86,8 +86,9 @@ public class LoadPeriod {
+ o2);
}
int comparison = compareLocalDates(o1.start, o2.start);
if (comparison != 0)
if (comparison != 0) {
return comparison;
}
return compareLocalDates(o1.end, o2.end);
}
});
@ -95,10 +96,12 @@ public class LoadPeriod {
}
private static int compareLocalDates(LocalDate l1, LocalDate l2) {
if (l1.isBefore(l2))
if (l1.isBefore(l2)) {
return -1;
if (l1.isAfter(l2))
}
if (l1.isAfter(l2)) {
return 1;
}
return 0;
}

View file

@ -43,10 +43,12 @@ public class ContextRelativeToOtherComponent<T> implements IContext<T> {
private ContextRelativeToOtherComponent(Component component,
IContext<T> context) {
if (component == null)
if (component == null) {
throw new IllegalArgumentException("component must be not null");
if (context == null)
}
if (context == null) {
throw new IllegalArgumentException("context must be not null");
}
this.component = component;
this.context = context;
}

View file

@ -66,8 +66,9 @@ public class OnColumnsRowRenderer<C, T> implements RowRenderer {
if (isTypeForInterface(type, ICellForDetailItemRenderer.class)) {
if (type instanceof ParameterizedType) {
return (ParameterizedType) type;
} else
} else {
informCannotBeInferred(renderer);
}
}
}
throw new RuntimeException("shouldn't reach here. Uncovered case for "
@ -110,9 +111,10 @@ public class OnColumnsRowRenderer<C, T> implements RowRenderer {
@Override
public void render(Row row, Object data) {
if (!type.isInstance(data))
if (!type.isInstance(data)) {
throw new IllegalArgumentException(data + " is not instance of "
+ type);
}
for (C item : columns) {
Component child = cellRenderer.cellFor(item, type.cast(data));
child.setParent(row);

View file

@ -90,8 +90,9 @@ public class DetailFiveTimeTrackerState extends TimeTrackerStateUsingJodaTime {
@Override
protected LocalDate round(LocalDate date, boolean down) {
int dayOfWeek = date.getDayOfWeek();
if (dayOfWeek == 1)
if (dayOfWeek == 1) {
return date;
}
return down ? date.withDayOfWeek(1) : date.withDayOfWeek(1)
.plusWeeks(1);
}

View file

@ -70,10 +70,12 @@ public class DetailThreeTimeTrackerState extends TimeTrackerStateUsingJodaTime {
@Override
protected LocalDate round(LocalDate date, boolean down) {
if (date.getMonthOfYear() == 1 && date.getDayOfMonth() == 1)
if (date.getMonthOfYear() == 1 && date.getDayOfMonth() == 1) {
return date;
if (date.getMonthOfYear() == 7 && date.getDayOfMonth() == 1)
}
if (date.getMonthOfYear() == 7 && date.getDayOfMonth() == 1) {
return date;
}
date = date.withDayOfMonth(1);
if (date.getMonthOfYear() < 7) {
return down ? date.withMonthOfYear(1) : date.withMonthOfYear(7);

View file

@ -34,8 +34,9 @@ public enum ZoomLevel {
private final TimeTrackerState state;
private ZoomLevel(TimeTrackerState state) {
if (state == null)
if (state == null) {
throw new IllegalArgumentException("state cannot be null");
}
this.state = state;
}

View file

@ -37,12 +37,15 @@ public class Interval {
private final long lengthBetween;
public Interval(Date start, Date finish) {
if (start == null)
if (start == null) {
throw new IllegalArgumentException("begin cannot be null");
if (finish == null)
}
if (finish == null) {
throw new IllegalArgumentException("end cannot be null");
if (start.compareTo(finish) > 0)
}
if (start.compareTo(finish) > 0) {
throw new IllegalArgumentException("start must be prior to end");
}
this.start = start;
this.finish = finish;
lengthBetween = this.finish.getTime() - this.start.getTime();
@ -74,9 +77,10 @@ public class Interval {
}
public double getProportion(Date date) {
if (!isIncluded(date))
if (!isIncluded(date)) {
throw new IllegalArgumentException("date " + date
+ " must be between [" + start + "," + finish + "]");
}
return ((double) date.getTime() - start.getTime()) / lengthBetween;
}

View file

@ -83,10 +83,12 @@ public class MenuBuilder<T extends XulElement> {
}
public MenuBuilder<T> item(String name, ItemAction<T> itemAction) {
if (name == null)
if (name == null) {
throw new IllegalArgumentException("name cannot be null");
if (itemAction == null)
}
if (itemAction == null) {
throw new IllegalArgumentException("itemAction cannot be null");
}
items.add(new Item(name, itemAction));
return this;
}

View file

@ -167,8 +167,9 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
private MutableTreeModel(Class<T> type, Node<T> root) {
super(root);
if (type == null)
if (type == null) {
throw new IllegalArgumentException("type cannot be null");
}
nodesByDomainObject.put(unwrap(root), root);
this.root = root;
}
@ -177,8 +178,9 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
public int[] getPath(Object parent, Object last) {
Node<T> parentNode = find(parent);
Node<T> lastNode = find(last);
if (parentNode == null || lastNode == null)
if (parentNode == null || lastNode == null) {
return new int[0];
}
List<Integer> path = lastNode.until(parentNode);
return asIntArray(path);
}
@ -221,8 +223,9 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
}
private void add(Node<T> parent, Integer position, List<Node<T>> children) {
if (children.isEmpty())
if (children.isEmpty()) {
return;
}
int indexFrom = position == null ? parent.children.size() : position;
int indexTo = indexFrom + children.size() - 1;
parent.addAll(position, children);
@ -254,9 +257,10 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
public void remove(T node) {
Node<T> found = find(node);
if (found.isRoot())
if (found.isRoot()) {
throw new IllegalArgumentException(node
+ " is root. It can't be removed");
}
int positionInParent = found.remove();
nodesByDomainObject.remove(node);
fireEvent(unwrap(found.parentNode), positionInParent, positionInParent,
@ -265,8 +269,9 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
public T getParent(T node) {
Node<T> associatedNode = find(node);
if (associatedNode.equals(root))
if (associatedNode.equals(root)) {
throw new IllegalArgumentException(node + " is root");
}
return unwrap(associatedNode.getParent());
}

View file

@ -58,9 +58,10 @@ public class OnZKDesktopRegistry<T> {
}
public T retrieve() throws IllegalStateException {
if (!isRegistered())
if (!isRegistered()) {
throw new IllegalStateException("no " + klass.getSimpleName()
+ " registered");
}
return klass.cast(get());
}

View file

@ -44,8 +44,9 @@ public class WeakReferencedListeners<T> {
}
public synchronized void addListener(T listener) {
if (listener == null)
if (listener == null) {
throw new IllegalArgumentException("listener cannot be null");
}
listeners.add(new WeakReference<T>(listener));
}
@ -55,9 +56,9 @@ public class WeakReferencedListeners<T> {
ArrayList<T> active = new ArrayList<T>();
while (listIterator.hasNext()) {
T listener = listIterator.next().get();
if (listener == null)
if (listener == null) {
listIterator.remove();
else {
} else {
active.add(listener);
}
}

View file

@ -37,10 +37,11 @@ public class ScriptDependenciesSorter implements IScriptsRegister {
public static List<ScriptDependency> extractFrom(Class<?> classWithScripts) {
ScriptsRequiredDeclaration annotation = classWithScripts
.getAnnotation(ScriptsRequiredDeclaration.class);
if (annotation == null)
if (annotation == null) {
throw new IllegalArgumentException(classWithScripts
+ " must be annotated with "
+ ScriptsRequiredDeclaration.class.getName());
}
List<ScriptDependency> dependsOn = getDependencies(annotation);
List<ScriptDependency> result = new ArrayList<ScriptDependency>();
for (Field field : getStringFields(getStaticFields(classWithScripts

View file

@ -68,8 +68,9 @@ public class ScriptDependency {
@Override
public boolean equals(Object other) {
if (this == other)
if (this == other) {
return true;
}
if (other instanceof ScriptDependency) {
return url.equals(((ScriptDependency) other).url);
}

View file

@ -139,8 +139,9 @@ public class AdvanceType extends BaseEntity {
}
public String getType() {
if (isUpdatable())
if (isUpdatable()) {
return "De Usuario";
}
return "Predefinido";
}
@ -148,25 +149,24 @@ public class AdvanceType extends BaseEntity {
}
public boolean isPrecisionValid(BigDecimal precision) {
if ((this.defaultMaxValue == null) || (precision == null))
if ((this.defaultMaxValue == null) || (precision == null)) {
return true;
if (this.defaultMaxValue.compareTo(precision) < 0)
return false;
return true;
}
return this.defaultMaxValue.compareTo(precision) >= 0;
}
public boolean isDefaultMaxValueValid(BigDecimal defaultMaxValue) {
if ((this.unitPrecision == null) || (defaultMaxValue == null))
if ((this.unitPrecision == null) || (defaultMaxValue == null)) {
return true;
if (this.unitPrecision.compareTo(defaultMaxValue) > 0)
return false;
return true;
}
return this.unitPrecision.compareTo(defaultMaxValue) <= 0;
}
public static boolean equivalentInDB(AdvanceType type, AdvanceType otherType) {
if (type.getId() == null || otherType.getId() == null)
if (type.getId() == null || otherType.getId() == null) {
return false;
}
return type.getId().equals(otherType.getId());
}

View file

@ -95,10 +95,12 @@ public class BaseCalendarDAO extends GenericDAOHibernate<BaseCalendar, Long>
@Override
public boolean thereIsOtherWithSameName(BaseCalendar baseCalendar) {
List<BaseCalendar> withSameName = findByName(baseCalendar);
if (withSameName.isEmpty())
if (withSameName.isEmpty()) {
return false;
if (withSameName.size() > 1)
}
if (withSameName.size() > 1) {
return true;
}
return areDifferentInDB(withSameName.get(0), baseCalendar);
}

View file

@ -30,9 +30,10 @@ public class IntervalOfPartialDates {
private final PartialDate end;
public IntervalOfPartialDates(PartialDate start, PartialDate end) {
if (!start.getGranularity().equals(end.getGranularity()))
if (!start.getGranularity().equals(end.getGranularity())) {
throw new IllegalArgumentException(
"the from and the to must have the same granularity");
}
if (!start.before(end)) {
throw new IllegalArgumentException(
"the start must be before the end");
@ -55,8 +56,9 @@ public class IntervalOfPartialDates {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
}
if (obj instanceof IntervalOfPartialDates) {
IntervalOfPartialDates other = (IntervalOfPartialDates) obj;
return new EqualsBuilder().append(this.start, other.start).append(

View file

@ -282,10 +282,12 @@ public class PartialDate implements ReadablePartial {
Iterator<Integer> otherIterator = other.values.iterator();
while (iterator.hasNext()) {
int diff = iterator.next() - otherIterator.next();
if (diff > 0)
if (diff > 0) {
return false;
if (diff < 0)
}
if (diff < 0) {
return true;
}
}
return false;
}
@ -295,9 +297,10 @@ public class PartialDate implements ReadablePartial {
}
public LocalDate tryToConvertToLocalDate() throws IllegalArgumentException {
if (!this.canBeConvertedToLocalDate())
if (!this.canBeConvertedToLocalDate()) {
throw new IllegalArgumentException("the partialDate " + this
+ " can't support be converted to local date");
}
return new LocalDate(this.normalizedInstant, ISOChronology
.getInstance(DateTimeZone.getDefault()));
}
@ -405,10 +408,11 @@ public class PartialDate implements ReadablePartial {
}
public Integer valueFor(Granularity granularity) {
if (this.granularity.isMoreCoarseGrainedThan(granularity))
if (this.granularity.isMoreCoarseGrainedThan(granularity)) {
throw new IllegalArgumentException(granularity
+ " is more specific than this instance granularity: "
+ this.granularity);
}
return get(granularity.getMostSpecific());
}

View file

@ -68,10 +68,12 @@ public class IntervalOfPartialDatesType implements CompositeUserType {
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
if (x == y) {
return true;
if (x == null || y == null)
}
if (x == null || y == null) {
return false;
}
return x.equals(y);
}
@ -114,8 +116,9 @@ public class IntervalOfPartialDatesType implements CompositeUserType {
0, 2), owner);
PartialDate end = PARTIAL_DATE_TYPE.nullSafeGet(rs, subArray(names, 2,
2), owner);
if (start == null || end == null)
if (start == null || end == null) {
return null;
}
return new IntervalOfPartialDates(start, end);
}

View file

@ -82,10 +82,12 @@ public class PartialDateType implements UserType {
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
if (x == y) {
return true;
if (x == null || y == null)
}
if (x == null || y == null) {
return false;
}
return x.equals(y);
}
@ -106,8 +108,9 @@ public class PartialDateType implements UserType {
names[0]);
String granularity = (String) Hibernate.STRING
.nullSafeGet(rs, names[1]);
if (timestamp == null || granularity == null)
if (timestamp == null || granularity == null) {
return null;
}
return PartialDate.createFromDataForPersistence(timestamp, granularity);
}

View file

@ -48,8 +48,9 @@ public class TimeQuantityType implements UserType {
JSONObject jsonObject = new JSONObject();
for (Granularity granularity : Granularity.values()) {
Integer value = timeQuantity.valueFor(granularity);
if (value != 0)
if (value != 0) {
jsonObject.put(granularity.name(), value);
}
}
return jsonObject.toString();
}
@ -86,10 +87,12 @@ public class TimeQuantityType implements UserType {
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
if (x == y) {
return true;
if (x == null || y == null)
}
if (x == null || y == null) {
return false;
}
return x.equals(y);
}

View file

@ -164,10 +164,12 @@ public abstract class OrderElement extends BaseEntity {
public boolean isFormatCodeValid(String code) {
if (code.contains("_"))
if (code.contains("_")) {
return false;
if (code.equals(""))
}
if (code.equals("")) {
return false;
}
return true;
}

View file

@ -55,8 +55,9 @@ public class OrderLineGroupManipulator implements IOrderLineGroup {
}
private void setParentIfRequired(OrderElement orderElement) {
if (this.parent != null)
if (this.parent != null) {
orderElement.setParent(this.parent);
}
}
@Override

View file

@ -74,9 +74,10 @@ public class GenericDayAssignment extends DayAssignment {
protected void setGenericResourceAllocation(
GenericResourceAllocation genericResourceAllocation) {
if (this.genericResourceAllocation != null)
if (this.genericResourceAllocation != null) {
throw new IllegalStateException(
"the allocation cannot be changed once it has been set");
}
this.genericResourceAllocation = genericResourceAllocation;
}

View file

@ -97,8 +97,9 @@ public class GenericResourceAllocation extends
public List<GenericDayAssignment> getOrderedAssignmentsFor(Resource resource) {
List<GenericDayAssignment> list = getOrderedAssignmentsFor().get(
resource);
if (list == null)
if (list == null) {
return Collections.emptyList();
}
return Collections.unmodifiableList(list);
}

View file

@ -144,9 +144,10 @@ public abstract class ResourceAllocation<T extends DayAssignment> extends
List<AllocationBeingModified> allocations) {
for (AllocationBeingModified allocationBeingModified : allocations) {
if (allocationBeingModified
.getBeingModified().getTask() == null)
.getBeingModified().getTask() == null) {
throw new IllegalArgumentException(
"all allocations must have task");
}
}
}

View file

@ -64,8 +64,9 @@ public class ResourcesPerDay {
@Override
public boolean equals(Object obj) {
if (obj == this)
if (obj == this) {
return true;
}
if (obj instanceof ResourcesPerDay) {
ResourcesPerDay other = (ResourcesPerDay) obj;
return amount.equals(other.getAmount());

View file

@ -75,9 +75,10 @@ public class SpecificDayAssignment extends DayAssignment {
public void setSpecificResourceAllocation(
SpecificResourceAllocation specificResourceAllocation) {
if (this.specificResourceAllocation != null)
if (this.specificResourceAllocation != null) {
throw new IllegalStateException(
"the allocation cannot be changed once it has been set");
}
this.specificResourceAllocation = specificResourceAllocation;
}

View file

@ -177,9 +177,10 @@ public class Task extends TaskElement {
public TaskGroup split(int... shares) {
int totalSumOfHours = sum(shares);
if (totalSumOfHours != getWorkHours())
if (totalSumOfHours != getWorkHours()) {
throw new IllegalArgumentException(
"the shares don't sum up the work hours");
}
TaskGroup result = TaskGroup.create();
result.copyPropertiesFrom(this);
result.shareOfHours = this.shareOfHours;

View file

@ -62,8 +62,9 @@ public abstract class TaskElement extends BaseEntity {
private BaseCalendar calendar;
public Integer getWorkHours() {
if (shareOfHours != null)
if (shareOfHours != null) {
return shareOfHours;
}
return defaultWorkHours();
}
@ -116,9 +117,10 @@ public abstract class TaskElement extends BaseEntity {
public void setOrderElement(OrderElement orderElement)
throws IllegalArgumentException, IllegalStateException {
Validate.notNull(orderElement, "orderElement must be not null");
if (this.orderElement != null)
if (this.orderElement != null) {
throw new IllegalStateException(
"once a orderElement is set, it cannot be changed");
}
this.orderElement = orderElement;
}

View file

@ -90,8 +90,9 @@ public class TaskGroup extends TaskElement {
for (TaskElement t : taskElements) {
if (t instanceof TaskGroup) {
TaskGroup group = (TaskGroup) t;
if (!group.canBeMerged())
if (!group.canBeMerged()) {
return false;
}
}
}
return true;
@ -109,10 +110,12 @@ public class TaskGroup extends TaskElement {
HoursGroup hoursGroup = null;
for (TaskElement taskElement : taskElements) {
HoursGroup current = getHoursGroupFor(taskElement);
if (current == null)
if (current == null) {
return false;
if (hoursGroup == null)
}
if (hoursGroup == null) {
hoursGroup = current;
}
if (!current.equals(hoursGroup)) {
return false;
}
@ -133,9 +136,10 @@ public class TaskGroup extends TaskElement {
}
public Task merge() {
if (!canBeMerged())
if (!canBeMerged()) {
throw new IllegalStateException(
"merge must not be called on a TaskGroup such canBeMerged returns false");
}
HoursGroup hoursGroup = inferHoursGroupFromChildren();
Task result = Task.createTask(hoursGroup);
result.copyPropertiesFrom(this);

View file

@ -64,10 +64,12 @@ public class ResourcesPerDayType implements UserType {
@Override
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
if (x == y) {
return true;
if (x == null || y == null)
}
if (x == null || y == null) {
return false;
}
return x.equals(y);
}
@ -86,8 +88,9 @@ public class ResourcesPerDayType implements UserType {
throws HibernateException, SQLException {
BigDecimal bigDecimal = (BigDecimal) Hibernate.BIG_DECIMAL.nullSafeGet(
rs, names[0]);
if (bigDecimal == null)
if (bigDecimal == null) {
return null;
}
return ResourcesPerDay.amount(bigDecimal);
}

View file

@ -54,10 +54,12 @@ public class CriterionDAO extends GenericDAOHibernate<Criterion, Long>
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
public boolean thereIsOtherWithSameNameAndType(Criterion criterion) {
List<Criterion> withSameNameAndType = findByNameAndType(criterion);
if (withSameNameAndType.isEmpty())
if (withSameNameAndType.isEmpty()) {
return false;
if (withSameNameAndType.size() > 1)
}
if (withSameNameAndType.size() > 1) {
return true;
}
return areDifferentInDB(withSameNameAndType.get(0), criterion);
}
@ -68,8 +70,9 @@ public class CriterionDAO extends GenericDAOHibernate<Criterion, Long>
@Override
public List<Criterion> findByNameAndType(Criterion criterion) {
if (criterion.getType() == null) return new ArrayList<Criterion>();
if (criterion.getType() == null) {
return new ArrayList<Criterion>();
}
Criteria c = getSession().createCriteria(Criterion.class);
c.add(Restrictions.eq("name", criterion.getName()).ignoreCase())
.createCriteria("type")
@ -81,9 +84,10 @@ public class CriterionDAO extends GenericDAOHibernate<Criterion, Long>
public Criterion findUniqueByNameAndType(Criterion criterion) throws InstanceNotFoundException {
List<Criterion> list = findByNameAndType(criterion);
if (list.size() != 1)
if (list.size() != 1) {
throw new InstanceNotFoundException(criterion, Criterion.class
.getName());
}
return list.get(0);
}
@ -98,8 +102,9 @@ public class CriterionDAO extends GenericDAOHibernate<Criterion, Long>
@Override
public Criterion find(Criterion criterion) throws InstanceNotFoundException {
if (criterion.getId() != null)
if (criterion.getId() != null) {
return super.find(criterion.getId());
}
Criterion result = findUniqueByNameAndType(criterion);
return result;

View file

@ -128,8 +128,9 @@ public class CriterionCompounder {
@Override
public boolean isSatisfiedBy(Resource resource) {
for (ICriterion criterion : criterions) {
if (!criterion.isSatisfiedBy(resource))
if (!criterion.isSatisfiedBy(resource)) {
return false;
}
}
return true;
}
@ -137,8 +138,9 @@ public class CriterionCompounder {
@Override
public boolean isSatisfiedBy(Resource resource, Date start, Date end) {
for (ICriterion criterion : criterions) {
if (!criterion.isSatisfiedBy(resource, start, end))
if (!criterion.isSatisfiedBy(resource, start, end)) {
return false;
}
}
return true;
}

View file

@ -167,7 +167,9 @@ public class CriterionSatisfaction extends BaseEntity {
|| getStartDate().equals(finish) || getStartDate().before(finish));
Validate.isTrue(finishDate == null || isNewObject() ||
getEndDate().equals(finish) || getEndDate().before(finish));
if(finish !=null) finish = new Date(finish.getTime());
if(finish !=null) {
finish = new Date(finish.getTime());
}
this.finishDate = finish;
}
@ -176,7 +178,9 @@ public class CriterionSatisfaction extends BaseEntity {
}
public void setEndDate(Date date) {
if(date != null) finish(date);
if(date != null) {
finish(date);
}
this.finishDate = date;
}

View file

@ -218,11 +218,13 @@ public class CriterionType extends BaseEntity implements
*/
@Override
public boolean equals(Object o) {
if (o instanceof CriterionType == false)
if (o instanceof CriterionType == false) {
return false;
}
if (this == o)
if (this == o) {
return true;
}
CriterionType criterionType = (CriterionType) o;

View file

@ -43,10 +43,12 @@ public abstract class Interval {
public static Interval range(Date start, Date end) {
Validate.notNull(start, "start date must be not null");
if (end == null)
if (end == null) {
return from(start);
if (start.equals(end))
}
if (start.equals(end)) {
return point(start);
}
return new Range(start, end);
}

View file

@ -84,8 +84,9 @@ public abstract class Resource extends BaseEntity{
Set<CriterionSatisfaction> satisfactionActives =
new HashSet<CriterionSatisfaction>();
for(CriterionSatisfaction satisfaction:criterionSatisfactions){
if(!satisfaction.isIsDeleted())
if(!satisfaction.isIsDeleted()) {
satisfactionActives.add(satisfaction);
}
}
return satisfactionActives;
}
@ -187,8 +188,9 @@ public abstract class Resource extends BaseEntity{
private boolean isAcceptedByAllPredicates(
CriterionSatisfaction criterionSatisfaction) {
for (IPredicate predicate : predicates) {
if (!predicate.accepts(criterionSatisfaction))
if (!predicate.accepts(criterionSatisfaction)) {
return false;
}
}
return true;
}
@ -437,7 +439,9 @@ public abstract class Resource extends BaseEntity{
( posteriorSameCriterion == null ||
!posteriorSameCriterion.overlapsWith(interval)));
if(!canAdd) return false;
if(!canAdd) {
return false;
}
if (type.isAllowSimultaneousCriterionsPerResource()){
return true;
}
@ -470,7 +474,9 @@ public abstract class Resource extends BaseEntity{
( posteriorSameCriterion == null ||
!posteriorSameCriterion.overlapsWith(interval)));
if(!canAdd) return false;
if(!canAdd) {
return false;
}
if (type.isAllowSimultaneousCriterionsPerResource()){
return true;
}
@ -562,8 +568,9 @@ public abstract class Resource extends BaseEntity{
if (previous != null) {
checkNotOverlaps(previous, current);
}
if (next != null)
if (next != null) {
checkNotOverlaps(current, next);
}
}
}

View file

@ -88,8 +88,9 @@ public class ListSorter<T> {
*/
public void modified(T element) throws NoSuchElementException {
int index = indexOfElement(element);
if ((index == list.size()))
if ((index == list.size())) {
throw new NoSuchElementException("not found: " + element);
}
list.remove(index);
insert(element);
}
@ -104,8 +105,9 @@ public class ListSorter<T> {
private int indexOfElement(T element) {
int index = 0;
for (T t : list) {
if (t == element)
if (t == element) {
break;
}
index++;
}
return index;
@ -119,9 +121,10 @@ public class ListSorter<T> {
*/
public void add(T element) {
Validate.notNull(element);
if (exists(element))
if (exists(element)) {
throw new IllegalArgumentException(element
+ " already exists. Duplicateds not allowed");
}
insert(element);
}

View file

@ -92,8 +92,9 @@ public class DayAssignmentMatchers {
public boolean matches(Object value) {
if (value instanceof List) {
List<? extends DayAssignment> assignments = (List<? extends DayAssignment>) value;
if (assignments.size() != hours.length)
if (assignments.size() != hours.length) {
return false;
}
for (int i = 0; i < hours.length; i++) {
if (hours[i] != assignments.get(i).getHours()) {
return false;

View file

@ -105,9 +105,10 @@ public class AdvanceTypeCRUDController extends GenericForwardComposer {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (((BigDecimal) value) == null)
if (((BigDecimal) value) == null) {
throw new WrongValueException(comp,
_("Value is not valid, the default max value must not be null"));
}
if (!(advanceTypeModel.isPrecisionValid((BigDecimal) value))) {
throw new WrongValueException(
@ -124,9 +125,10 @@ public class AdvanceTypeCRUDController extends GenericForwardComposer {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (((BigDecimal) value) == null)
if (((BigDecimal) value) == null) {
throw new WrongValueException(comp,
_("Value is not valid, the Precision value must not be null "));
}
if (!(advanceTypeModel
.isDefaultMaxValueValid((BigDecimal) value))) {
throw new WrongValueException(
@ -143,9 +145,10 @@ public class AdvanceTypeCRUDController extends GenericForwardComposer {
@Override
public void validate(Component comp, Object value)
throws WrongValueException {
if (((String) value).isEmpty())
if (((String) value).isEmpty()) {
throw new WrongValueException(comp,
_("The name is not valid, the name must not be null "));
}
if (!(advanceTypeModel.distinctNames((String) value))) {
throw new WrongValueException(comp,
_("The name is not valid, Exist other advance type with a similar name. "));

View file

@ -141,8 +141,9 @@ public class AdvanceTypeModel implements IAdvanceTypeModel {
@Override
@Transactional
public boolean distinctNames(String name) {
if (name.isEmpty())
if (name.isEmpty()) {
return true;
}
List<AdvanceType> listAdvanceType = advanceTypeDAO
.list(AdvanceType.class);
for (AdvanceType advanceType : listAdvanceType) {

View file

@ -98,8 +98,9 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
public boolean contains(String requestPath) {
for (CustomMenuItem item : thisAndChildren()) {
if (requestContains(requestPath, item.unencodedURL))
if (requestContains(requestPath, item.unencodedURL)) {
return true;
}
}
return false;
}
@ -198,8 +199,9 @@ public class CustomMenuController extends Div implements IMenuItemsRegister {
public List<CustomMenuItem> getCustomMenuSecondaryItems() {
for (CustomMenuItem ci : this.firstLevel) {
if (ci.isActiveParent())
if (ci.isActiveParent()) {
return ci.getChildren();
}
}
return Collections.<CustomMenuItem> emptyList();
}

View file

@ -120,15 +120,17 @@ public abstract class Finder implements IFinder {
*/
public ListModel getSubModel(Object value, int nRows) {
final String idx = value == null ? "" : objectToString(value);
if (nRows < 0)
if (nRows < 0) {
nRows = 10;
}
final LinkedList data = new LinkedList();
for (int i = 0; i < getSize(); i++) {
if (idx.equals("")
|| entryMatchesText(_toString(getElementAt(i)), idx)) {
data.add(getElementAt(i));
if (--nRows <= 0)
if (--nRows <= 0) {
break; // done
}
}
}
return new SimpleListModelExt(data);

View file

@ -50,8 +50,9 @@ public class ConverterFactory implements IConverterFactory {
@Override
public <T> IConverter<? super T> getConverterFor(Class<T> klass) {
if (convertersByType.containsKey(klass))
if (convertersByType.containsKey(klass)) {
return (IConverter<? super T>) convertersByType.get(klass);
}
for (Class<?> registeredKlass : convertersByType.keySet()) {
if (registeredKlass.isAssignableFrom(klass)) {
IConverter<?> result = convertersByType.get(registeredKlass);

View file

@ -75,8 +75,9 @@ public class RedirectorSynthetiser implements BeanFactoryPostProcessor {
}
private URLHandler<?> getHandler() {
if (urlHandler != null)
if (urlHandler != null) {
return urlHandler;
}
URLHandlerRegistry registry = (URLHandlerRegistry) BeanFactoryUtils
.beanOfType(beanFactory, URLHandlerRegistry.class);
urlHandler = registry.getRedirectorFor(pageInterface);

View file

@ -20,6 +20,8 @@
package org.navalplanner.web.common.entrypoints;
import static org.navalplanner.web.I18nHelper._;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
@ -41,8 +43,6 @@ import org.zkoss.zk.ui.event.BookmarkEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import static org.navalplanner.web.I18nHelper._;
/**
* <br />
* @author Óscar González Fernández <ogonzalez@igalia.com>
@ -95,8 +95,9 @@ public class URLHandler<T> {
}
public void doTransition(String methodName, Object... values) {
if (isFlagedInThisRequest())
if (isFlagedInThisRequest()) {
return;
}
flagAlreadyExecutedInThisRequest();
if (!metadata.containsKey(methodName)) {
LOG.error("Method " + methodName
@ -120,8 +121,9 @@ public class URLHandler<T> {
.getRequestPath();
if (requestPath.contains(page)) {
doBookmark(fragment);
} else
} else {
sendRedirect(fragment);
}
}
private boolean isFlagedInThisRequest() {
@ -138,8 +140,9 @@ public class URLHandler<T> {
}
private String stripHash(String fragment) {
if (fragment.startsWith("#"))
if (fragment.startsWith("#")) {
return fragment.substring(1);
}
return fragment;
}
@ -151,12 +154,14 @@ public class URLHandler<T> {
private String getFragment(String[] parameterNames,
String[] stringRepresentations) {
StringBuilder result = new StringBuilder();
if (parameterNames.length > 0)
if (parameterNames.length > 0) {
result.append("#");
}
for (int i = 0; i < parameterNames.length; i++) {
result.append(parameterNames[i]);
if (stringRepresentations[i] != null)
if (stringRepresentations[i] != null) {
result.append("=").append(stringRepresentations[i]);
}
if (i < parameterNames.length - 1) {
result.append(";");
}
@ -224,8 +229,9 @@ public class URLHandler<T> {
}
private String insertSemicolonIfNeeded(String uri) {
if (!uri.startsWith(";"))
if (!uri.startsWith(";")) {
return ";" + uri;
}
return uri;
}

View file

@ -47,8 +47,9 @@ public class URLHandlerRegistry implements IURLHandlerRegistry {
@SuppressWarnings("unchecked")
public <T> URLHandler<T> getRedirectorFor(Class<T> klassWithLinkableMetadata) {
if (cached.containsKey(klassWithLinkableMetadata))
if (cached.containsKey(klassWithLinkableMetadata)) {
return (URLHandler<T>) cached.get(klassWithLinkableMetadata);
}
URLHandler<T> result = new URLHandler<T>(converterFactory,
executorRetriever, klassWithLinkableMetadata);
cached.put(klassWithLinkableMetadata, result);

View file

@ -107,8 +107,9 @@ public class AsignedHoursToOrderElementModel implements
if (orderElement == null) {
return 0;
}
if (orderElement.getChildren().isEmpty())
if (orderElement.getChildren().isEmpty()) {
return 0;
}
int asignedDirectChildren = getTotalAsignedHours()
- this.asignedDirectHours;
return asignedDirectChildren;

View file

@ -271,8 +271,9 @@ public class ManageOrderElementAdvancesController extends
if ((advance.getAdvanceType() != null)
&& (advance.getAdvanceType().getId().equals(advanceType
.getId())))
.getId()))) {
comboAdvanceTypes.setSelectedItem(comboItem);
}
}
}
comboAdvanceTypes.addEventListener(Events.ON_SELECT,
@ -669,8 +670,9 @@ public class ManageOrderElementAdvancesController extends
Listitem listItem = (Listitem) editAdvances.getChildren().get(i);
AdvanceAssignment advance = (AdvanceAssignment) listItem
.getValue();
if (advance.getAdvanceType() == null)
if (advance.getAdvanceType() == null) {
return false;
}
DirectAdvanceAssignment directAdvanceAssignment;
if (advance instanceof IndirectAdvanceAssignment) {
@ -679,8 +681,9 @@ public class ManageOrderElementAdvancesController extends
} else {
directAdvanceAssignment = (DirectAdvanceAssignment) advance;
}
if (directAdvanceAssignment.getMaxValue() == null)
if (directAdvanceAssignment.getMaxValue() == null) {
return false;
}
}
}
return true;
@ -692,10 +695,9 @@ public class ManageOrderElementAdvancesController extends
Listitem listItem = (Listitem) editAdvancesMeasurement.getChildren().get(i);
AdvanceMeasurement advance = (AdvanceMeasurement) listItem
.getValue();
if (advance.getValue() == null)
return false;
if (advance.getDate() == null)
if (advance.getValue() == null || advance.getDate() == null) {
return false;
}
}
}
return true;

View file

@ -96,8 +96,7 @@ public class ManageOrderElementAdvancesModel implements
@Override
public String getInfoAdvanceAssignment(){
if ((this.advanceAssignment == null) ||
(this.orderElement == null)) {
if (this.advanceAssignment == null || this.orderElement == null) {
return "";
}
return getInfoAdvanceAssignment(this.advanceAssignment);
@ -119,8 +118,7 @@ public class ManageOrderElementAdvancesModel implements
@Override
@Transactional(readOnly = true)
public List<AdvanceMeasurement> getAdvanceMeasurements() {
if ((this.advanceAssignment == null) ||
(this.orderElement == null)) {
if (this.advanceAssignment == null || this.orderElement == null) {
return new ArrayList<AdvanceMeasurement>();
}
return new ArrayList<AdvanceMeasurement>(this.advanceAssignment
@ -275,8 +273,9 @@ public class ManageOrderElementAdvancesModel implements
@Override
public boolean isReadOnlyAdvanceMeasurements(){
if (this.advanceAssignment == null)
if (this.advanceAssignment == null) {
return true;
}
return this.isIndirectAdvanceAssignment;
}
@ -308,8 +307,9 @@ public class ManageOrderElementAdvancesModel implements
DuplicateValueTrueReportGlobalAdvanceException{
updateRemoveAdvances();
for (AdvanceAssignment advanceAssignment : this.listAdvanceAssignments) {
if (advanceAssignment instanceof DirectAdvanceAssignment)
if (advanceAssignment instanceof DirectAdvanceAssignment) {
validateBasicData((DirectAdvanceAssignment) advanceAssignment);
}
}
}
@ -334,9 +334,10 @@ public class ManageOrderElementAdvancesModel implements
AdvanceAssignment advanceAssignment) {
for (AdvanceAssignment advance : this.orderElement
.getDirectAdvanceAssignments()) {
if ((advance.getVersion() != null)
&& (advance.getId().equals(advanceAssignment.getId())))
if (advance.getVersion() != null
&& advance.getId().equals(advanceAssignment.getId())) {
return advance;
}
}
return null;
}
@ -362,7 +363,9 @@ public class ManageOrderElementAdvancesModel implements
BigDecimal precision = this.advanceAssignment.getAdvanceType()
.getUnitPrecision();
BigDecimal result[] = value.divideAndRemainder(precision);
if(result[1].compareTo(BigDecimal.ZERO) == 0) return true;
if(result[1].compareTo(BigDecimal.ZERO) == 0) {
return true;
}
return false;
}
return true;
@ -370,26 +373,30 @@ public class ManageOrderElementAdvancesModel implements
@Override
public boolean greatThanMaxValue(BigDecimal value){
if ((this.advanceAssignment == null)
|| (this.advanceAssignment.getMaxValue() == null))
if (this.advanceAssignment == null
|| this.advanceAssignment.getMaxValue() == null) {
return false;
if (value.compareTo(this.advanceAssignment.getMaxValue()) > 0)
}
if (value.compareTo(this.advanceAssignment.getMaxValue()) > 0) {
return true;
}
return false;
}
@Override
public boolean isDistinctValidDate(Date value,
AdvanceMeasurement newAdvanceMeasurement) {
if (this.advanceAssignment == null)
if (this.advanceAssignment == null) {
return true;
}
for (AdvanceMeasurement advanceMeasurement : advanceAssignment
.getAdvanceMeasurements()) {
LocalDate oldDate = advanceMeasurement.getDate();
if ((oldDate != null)
&& (!newAdvanceMeasurement.equals(advanceMeasurement))
&& (oldDate.compareTo(new LocalDate(value)) == 0))
if (oldDate != null
&& !newAdvanceMeasurement.equals(advanceMeasurement)
&& oldDate.compareTo(new LocalDate(value)) == 0) {
return false;
}
}
return true;
}

View file

@ -85,8 +85,9 @@ public class OrderElementModel implements IOrderElementModel {
public List<CriterionType> getCriterionTypes() {
List<CriterionType> result = new ArrayList<CriterionType>();
if (mapCriterionTypes.isEmpty())
if (mapCriterionTypes.isEmpty()) {
loadCriterionTypes();
}
result.addAll(mapCriterionTypes.values());
return result;
@ -95,8 +96,9 @@ public class OrderElementModel implements IOrderElementModel {
@Override
@Transactional(readOnly = true)
public CriterionType getCriterionTypeByName(String name) {
if (mapCriterionTypes.isEmpty())
if (mapCriterionTypes.isEmpty()) {
loadCriterionTypes();
}
return mapCriterionTypes.get(name);
}

View file

@ -215,8 +215,9 @@ public class OrderElementTreeModel {
}
private boolean find(OrderElement child, List<OrderElement> children) {
if (children.indexOf(child) >= 0)
if (children.indexOf(child) >= 0) {
return true;
}
for (OrderElement criterionDTO : children) {
return find(child, getChildren(criterionDTO));
}

View file

@ -219,8 +219,9 @@ public class OrderModel implements IOrderModel {
public void save() throws ValidationException {
reattachCriterions();
InvalidValue[] invalidValues = orderValidator.getInvalidValues(order);
if (invalidValues.length > 0)
if (invalidValues.length > 0) {
throw new ValidationException(invalidValues);
}
order.checkValid();
this.orderDAO.save(order);
@ -336,10 +337,11 @@ public class OrderModel implements IOrderModel {
return convertToTaskGroup(group);
} else {
OrderLine line = (OrderLine) order;
if (line.getHoursGroups().isEmpty())
if (line.getHoursGroups().isEmpty()) {
throw new IllegalArgumentException(_(
"The line must have at least one {0} associated",
HoursGroup.class.getSimpleName()));
}
return line.getHoursGroups().size() > 1 ? convertToTaskGroup(line)
: convertToTask(line);
}

View file

@ -280,9 +280,10 @@ public class ResourceAllocationsBeingEdited {
}
public FormBinder createFormBinder() {
if (formBinder != null)
if (formBinder != null) {
throw new IllegalStateException(
"there is already a binder associated with this object");
}
formBinder = new FormBinder(this);
return formBinder;
}

View file

@ -47,10 +47,12 @@ public class SpecificAllocationDTO extends AllocationDTO {
}
private static boolean areEquals(Resource one, Resource other) {
if (one == other)
if (one == other) {
return true;
if (one == null || other == null)
}
if (one == null || other == null) {
return false;
}
return one.equals(other);
}

View file

@ -135,9 +135,10 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
CalendarAllocationController calendarAllocationController,
List<ICommand<TaskElement>> additional) {
Order orderReloaded = reload(order);
if (!orderReloaded.isSomeTaskElementScheduled())
if (!orderReloaded.isSomeTaskElementScheduled()) {
throw new IllegalArgumentException(_(
"The order {0} must be scheduled", orderReloaded));
}
PlannerConfiguration<TaskElement> configuration = createConfiguration(orderReloaded);
addAdditional(additional, configuration);
ISaveCommand saveCommand = buildSaveCommand();

View file

@ -49,8 +49,9 @@ public class MergeTaskCommand implements IMergeTaskCommand {
return;
}
TaskGroup old = (TaskGroup) task;
if (!old.canBeMerged())
if (!old.canBeMerged()) {
return;
}
Task result = old.merge();
context.replace(old, result);
planningState.removed(old);

View file

@ -70,8 +70,9 @@ public class ShareBean {
}
public void setName(String name) {
if (StringUtils.isEmpty(name))
if (StringUtils.isEmpty(name)) {
return;
}
this.name = name;
}
@ -80,8 +81,9 @@ public class ShareBean {
}
public void setHours(Integer share) {
if (share == null || share <= 0)
if (share == null || share <= 0) {
return;
}
this.hours = share;
}

View file

@ -150,8 +150,9 @@ public class CriterionAdminController_V2 extends GenericForwardComposer {
}
public boolean allowRemove(CriterionType criterionType){
if(criterionType.getCriterions().size() > 0)
if(criterionType.getCriterions().size() > 0) {
return false;
}
return true;
}

View file

@ -422,8 +422,9 @@ public class CriterionTreeModel implements ICriterionTreeModel{
}
private boolean find(CriterionDTO child,List<CriterionDTO> children){
if(children.indexOf(child) >= 0)
if(children.indexOf(child) >= 0) {
return true;
}
for(CriterionDTO criterionDTO : children){
return find(child,getChildren(criterionDTO));
}

View file

@ -110,8 +110,9 @@ public class CriterionsModel implements ICriterionsModel {
@Transactional(readOnly = true)
public ICriterionType<?> getTypeFor(Criterion criterion) {
for (ICriterionType<?> criterionType : getTypes()) {
if (criterionType.contains(criterion))
if (criterionType.contains(criterion)) {
return criterionType;
}
}
throw new RuntimeException(_("{0} not found type for criterion ", criterion));
}
@ -121,8 +122,9 @@ public class CriterionsModel implements ICriterionsModel {
public void saveCriterion() throws ValidationException {
InvalidValue[] invalidValues = criterionValidator
.getInvalidValues(criterion);
if (invalidValues.length > 0)
if (invalidValues.length > 0) {
throw new ValidationException(invalidValues);
}
try {
save(criterion);
} finally {
@ -163,8 +165,9 @@ public class CriterionsModel implements ICriterionsModel {
@Transactional(readOnly = true)
public <T extends Resource> List<T> getResourcesSatisfyingCurrentCriterionOfType(
Class<T> klass) {
if (criterion == null)
if (criterion == null) {
return new ArrayList<T>();
}
return getResourcesSatisfying(klass, criterion);
}

View file

@ -151,8 +151,9 @@ public class CriterionsModel_V2 implements ICriterionsModel_V2 {
@Transactional(readOnly = true)
public ICriterionType<?> getTypeFor(Criterion criterion) {
for (ICriterionType<?> criterionType : getTypes()) {
if (criterionType.contains(criterion))
if (criterionType.contains(criterion)) {
return criterionType;
}
}
throw new RuntimeException(_("{0} not found type for criterion ", criterion));
}
@ -162,8 +163,9 @@ public class CriterionsModel_V2 implements ICriterionsModel_V2 {
public void saveCriterionType() throws ValidationException {
InvalidValue[] invalidValues = criterionTypeValidator
.getInvalidValues(criterionType);
if (invalidValues.length > 0)
if (invalidValues.length > 0) {
throw new ValidationException(invalidValues);
}
criterionTreeModel.saveCriterions(criterionType);
criterionTypeDAO.save(criterionType);
}
@ -184,8 +186,9 @@ public class CriterionsModel_V2 implements ICriterionsModel_V2 {
@Transactional(readOnly = true)
public <T extends Resource> List<T> getResourcesSatisfyingCurrentCriterionOfType(
Class<T> klass) {
if (criterion == null)
if (criterion == null) {
return new ArrayList<T>();
}
return getResourcesSatisfying(klass, criterion);
}

View file

@ -269,37 +269,34 @@ public class AssignedMachineCriterionsModel implements IAssignedMachineCriterion
private boolean sameCriterion(CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction) {
if (otherSatisfaction.getCriterionWithItsType() == null)
if (otherSatisfaction.getCriterionWithItsType() == null){
return false;
}
Criterion otherCriterion = otherSatisfaction.getCriterionWithItsType()
.getCriterion();
if (otherCriterion.getId().equals(
satisfaction.getCriterionWithItsType().getCriterion().getId()))
return true;
return false;
return otherCriterion.getId().equals(
satisfaction.getCriterionWithItsType().getCriterion().getId());
}
private boolean sameCriterionType(
CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction) {
if (otherSatisfaction.getCriterionWithItsType() == null)
if (otherSatisfaction.getCriterionWithItsType() == null) {
return false;
}
ICriterionType<?> criterionType = otherSatisfaction
.getCriterionWithItsType().getType();
if (criterionType.equals(satisfaction.getCriterionWithItsType()
.getType()))
return true;
return false;
return criterionType.equals(satisfaction.getCriterionWithItsType()
.getType());
}
private boolean sameInterval(CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction) {
if (otherSatisfaction.getStartDate() == null)
if (otherSatisfaction.getStartDate() == null) {
return false;
}
Interval otherInterval = otherSatisfaction.getInterval();
if (satisfaction.overlapsWith(otherInterval))
return true;
return false;
return satisfaction.overlapsWith(otherInterval);
}
public void save() throws ValidationException {
@ -307,8 +304,9 @@ public class AssignedMachineCriterionsModel implements IAssignedMachineCriterion
for (CriterionSatisfactionDTO satisfactionDTO : this.criterionSatisfactionDTOs) {
invalidValues = satisfactionValidator
.getInvalidValues(satisfactionDTO);
if (invalidValues.length > 0)
if (invalidValues.length > 0) {
throw new ValidationException(invalidValues);
}
save(satisfactionDTO);
}
}

View file

@ -34,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.zkoss.zk.ui.WrongValueException;
/**
*
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
*/
@ -74,40 +73,40 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
@Transactional(readOnly = true)
public void prepareForEdit(Worker worker) {
this.worker = worker;
if(worker != null){
if (worker != null) {
reattachmentWorker();
initDTOs();
}
}
public void prepareForCreate(Worker worker){
public void prepareForCreate(Worker worker) {
this.worker = worker;
this.criterionSatisfactionDTOs = new HashSet<CriterionSatisfactionDTO>();
}
private void initDTOs(){
private void initDTOs() {
criterionSatisfactionDTOs = new HashSet<CriterionSatisfactionDTO>();
for(CriterionSatisfaction criterionSatisfaction :
worker.getCriterionSatisfactions()){
if(!criterionSatisfaction.isIsDeleted()){
CriterionSatisfactionDTO dto =
new CriterionSatisfactionDTO(criterionSatisfaction);
criterionSatisfactionDTOs.add(dto);
}
for (CriterionSatisfaction criterionSatisfaction : worker
.getCriterionSatisfactions()) {
if (!criterionSatisfaction.isIsDeleted()) {
CriterionSatisfactionDTO dto = new CriterionSatisfactionDTO(
criterionSatisfaction);
criterionSatisfactionDTOs.add(dto);
}
}
}
@Override
public Set<CriterionSatisfactionDTO> getAllCriterionSatisfactions() {
if(worker == null){
if (worker == null) {
return new HashSet<CriterionSatisfactionDTO>();
}
return allSatisfactionsDTO();
}
@Override
@Override
public Set<CriterionSatisfactionDTO> getFilterCriterionSatisfactions() {
if(worker == null){
if (worker == null) {
return new HashSet<CriterionSatisfactionDTO>();
}
return filterSatisfactionsDTO();
@ -115,7 +114,7 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
@Override
@Transactional(readOnly = true)
public void reattachmentWorker(){
public void reattachmentWorker() {
resourceDAO.reattach(worker);
for (CriterionSatisfaction criterionSatisfaction : worker
.getCriterionSatisfactions()) {
@ -128,26 +127,26 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
}
@Override
public void addCriterionSatisfaction(){
public void addCriterionSatisfaction() {
CriterionSatisfactionDTO criterionSatisfactionDTO = new CriterionSatisfactionDTO();
this.criterionSatisfactionDTOs.add(criterionSatisfactionDTO);
}
private Set<CriterionSatisfactionDTO> allSatisfactionsDTO(){
private Set<CriterionSatisfactionDTO> allSatisfactionsDTO() {
Set<CriterionSatisfactionDTO> satisfactions = new HashSet<CriterionSatisfactionDTO>();
for(CriterionSatisfactionDTO criterionSatisfactionDTO : criterionSatisfactionDTOs){
if(!criterionSatisfactionDTO.isIsDeleted()){
for (CriterionSatisfactionDTO criterionSatisfactionDTO : criterionSatisfactionDTOs) {
if (!criterionSatisfactionDTO.isIsDeleted()) {
satisfactions.add(criterionSatisfactionDTO);
}
}
return satisfactions;
}
private Set<CriterionSatisfactionDTO> filterSatisfactionsDTO(){
private Set<CriterionSatisfactionDTO> filterSatisfactionsDTO() {
Set<CriterionSatisfactionDTO> satisfactions = new HashSet<CriterionSatisfactionDTO>();
for(CriterionSatisfactionDTO criterionSatisfactionDTO : criterionSatisfactionDTOs){
if((!criterionSatisfactionDTO.isIsDeleted())&&
(criterionSatisfactionDTO.isCurrent())){
for (CriterionSatisfactionDTO criterionSatisfactionDTO : criterionSatisfactionDTOs) {
if ((!criterionSatisfactionDTO.isIsDeleted())
&& (criterionSatisfactionDTO.isCurrent())) {
satisfactions.add(criterionSatisfactionDTO);
}
}
@ -155,10 +154,10 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
}
@Override
public void remove(CriterionSatisfactionDTO criterionSatisfactionDTO){
if(criterionSatisfactionDTO.isNewObject()){
public void remove(CriterionSatisfactionDTO criterionSatisfactionDTO) {
if (criterionSatisfactionDTO.isNewObject()) {
criterionSatisfactionDTOs.remove(criterionSatisfactionDTO);
}else{
} else {
criterionSatisfactionDTO.setIsDeleted(true);
}
}
@ -168,10 +167,10 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
public List<CriterionWithItsType> getCriterionWithItsType() {
criterionsWithItsTypes = new ArrayList<CriterionWithItsType>();
List<CriterionType> listTypes = getCriterionTypes();
for(CriterionType criterionType : listTypes){
if(criterionType.isEnabled()){
for (CriterionType criterionType : listTypes) {
if (criterionType.isEnabled()) {
Set<Criterion> listCriterion = getDirectCriterions(criterionType);
getCriterionWithItsType(criterionType,listCriterion );
getCriterionWithItsType(criterionType, listCriterion);
}
}
return criterionsWithItsTypes;
@ -182,22 +181,26 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
.getCriterionTypesByResources(applicableResources);
}
private void getCriterionWithItsType(CriterionType type, Set<Criterion> children){
for(Criterion criterion : children){
if(criterion.isActive()){
//Create the criterion with its criterionType and its Hierarchy label
CriterionWithItsType criterionAndType = new CriterionWithItsType(type,criterion);
//Add to the list
private void getCriterionWithItsType(CriterionType type,
Set<Criterion> children) {
for (Criterion criterion : children) {
if (criterion.isActive()) {
// Create the criterion with its criterionType and its Hierarchy
// label
CriterionWithItsType criterionAndType = new CriterionWithItsType(
type, criterion);
// Add to the list
criterionsWithItsTypes.add(criterionAndType);
getCriterionWithItsType(type,criterion.getChildren());
}
getCriterionWithItsType(type, criterion.getChildren());
}
}
}
private static Set<Criterion> getDirectCriterions(CriterionType criterionType){
private static Set<Criterion> getDirectCriterions(
CriterionType criterionType) {
Set<Criterion> criterions = new HashSet<Criterion>();
for(Criterion criterion : criterionType.getCriterions()){
if(criterion.getParent() == null){
for (Criterion criterion : criterionType.getCriterions()) {
if (criterion.getParent() == null) {
criterions.add(criterion);
}
}
@ -205,47 +208,51 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
}
@Override
public void setCriterionWithItsType(CriterionSatisfactionDTO criterionSatisfactionDTO,
CriterionWithItsType criterionAndType) throws WrongValueException{
criterionSatisfactionDTO.setCriterionWithItsType(criterionAndType);
public void setCriterionWithItsType(
CriterionSatisfactionDTO criterionSatisfactionDTO,
CriterionWithItsType criterionAndType) throws WrongValueException {
criterionSatisfactionDTO.setCriterionWithItsType(criterionAndType);
}
@Override
public boolean checkSameCriterionAndSameInterval(CriterionSatisfactionDTO satisfaction){
public boolean checkSameCriterionAndSameInterval(
CriterionSatisfactionDTO satisfaction) {
return existSameCriterionAndInterval(satisfaction);
}
@Override
public boolean checkNotAllowSimultaneousCriterionsPerResource(
CriterionSatisfactionDTO satisfaction){
ICriterionType<?> type = satisfaction.getCriterionWithItsType().getType();
CriterionSatisfactionDTO satisfaction) {
ICriterionType<?> type = satisfaction.getCriterionWithItsType()
.getType();
if (type.isAllowSimultaneousCriterionsPerResource()) {
return false;
}
return existSameCriterionTypeAndInterval(satisfaction);
}
private boolean existSameCriterionTypeAndInterval(CriterionSatisfactionDTO satisfaction){
for(CriterionSatisfactionDTO otherSatisfaction : criterionSatisfactionDTOs){
if((!otherSatisfaction.equals(satisfaction))&&
(!otherSatisfaction.isIsDeleted())&&
(!satisfaction.isIsDeleted())&&
(sameCriterionType(otherSatisfaction,satisfaction)) &&
(sameInterval(otherSatisfaction,satisfaction))) {
private boolean existSameCriterionTypeAndInterval(
CriterionSatisfactionDTO satisfaction) {
for (CriterionSatisfactionDTO otherSatisfaction : criterionSatisfactionDTOs) {
if ((!otherSatisfaction.equals(satisfaction))
&& (!otherSatisfaction.isIsDeleted())
&& (!satisfaction.isIsDeleted())
&& (sameCriterionType(otherSatisfaction, satisfaction))
&& (sameInterval(otherSatisfaction, satisfaction))) {
return true;
}
}
return false;
}
private boolean existSameCriterionAndInterval(CriterionSatisfactionDTO satisfaction){
for(CriterionSatisfactionDTO otherSatisfaction : criterionSatisfactionDTOs){
if((!otherSatisfaction.equals(satisfaction))&&
(!otherSatisfaction.isIsDeleted())&&
(!satisfaction.isIsDeleted())&&
(sameCriterion(otherSatisfaction,satisfaction)) &&
(sameInterval(otherSatisfaction,satisfaction))) {
private boolean existSameCriterionAndInterval(
CriterionSatisfactionDTO satisfaction) {
for (CriterionSatisfactionDTO otherSatisfaction : criterionSatisfactionDTOs) {
if ((!otherSatisfaction.equals(satisfaction))
&& (!otherSatisfaction.isIsDeleted())
&& (!satisfaction.isIsDeleted())
&& (sameCriterion(otherSatisfaction, satisfaction))
&& (sameInterval(otherSatisfaction, satisfaction))) {
return true;
}
}
@ -253,83 +260,96 @@ public class AssignedCriterionsModel implements IAssignedCriterionsModel {
}
private boolean sameCriterion(CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction){
if(otherSatisfaction.getCriterionWithItsType() == null) return false;
Criterion otherCriterion = otherSatisfaction.getCriterionWithItsType().getCriterion();
if(otherCriterion.getId().equals(satisfaction.getCriterionWithItsType().getCriterion().getId()))
CriterionSatisfactionDTO satisfaction) {
if (otherSatisfaction.getCriterionWithItsType() == null) {
return false;
}
Criterion otherCriterion = otherSatisfaction.getCriterionWithItsType()
.getCriterion();
if (otherCriterion.getId().equals(
satisfaction.getCriterionWithItsType().getCriterion().getId())) {
return true;
}
return false;
}
private boolean sameCriterionType(CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction){
if(otherSatisfaction.getCriterionWithItsType() == null) return false;
ICriterionType<?> criterionType = otherSatisfaction.getCriterionWithItsType().getType();
if(criterionType.equals(satisfaction.getCriterionWithItsType().getType()))
return true;
return false;
private boolean sameCriterionType(
CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction) {
if (otherSatisfaction.getCriterionWithItsType() == null) {
return false;
}
ICriterionType<?> criterionType = otherSatisfaction
.getCriterionWithItsType().getType();
return criterionType.equals(satisfaction.getCriterionWithItsType()
.getType());
}
private boolean sameInterval(CriterionSatisfactionDTO otherSatisfaction,
CriterionSatisfactionDTO satisfaction){
if(otherSatisfaction.getStartDate() == null) return false;
CriterionSatisfactionDTO satisfaction) {
if (otherSatisfaction.getStartDate() == null) {
return false;
}
Interval otherInterval = otherSatisfaction.getInterval();
Interval interval = satisfaction.getInterval();
if((satisfaction.overlapsWith(otherInterval))||
(otherSatisfaction.overlapsWith(interval)))
return true;
return false;
return (satisfaction.overlapsWith(otherInterval))
|| (otherSatisfaction.overlapsWith(interval));
}
@Override
public void validate()
throws ValidationException,IllegalStateException {
public void validate() throws ValidationException, IllegalStateException {
validateDTOs();
}
@Override
public void confirm()
throws ValidationException,IllegalStateException {
public void confirm() throws ValidationException, IllegalStateException {
updateDTOs();
}
private void validateDTOs() throws ValidationException{
Set<CriterionSatisfactionDTO> listDTOs =
new HashSet<CriterionSatisfactionDTO>(criterionSatisfactionDTOs);
for(CriterionSatisfactionDTO satisfactionDTO : listDTOs){
private void validateDTOs() throws ValidationException {
Set<CriterionSatisfactionDTO> listDTOs = new HashSet<CriterionSatisfactionDTO>(
criterionSatisfactionDTOs);
for (CriterionSatisfactionDTO satisfactionDTO : listDTOs) {
InvalidValue[] invalidValues;
invalidValues = satisfactionDTOValidator.getInvalidValues(satisfactionDTO);
if (invalidValues.length > 0){
invalidValues = satisfactionDTOValidator
.getInvalidValues(satisfactionDTO);
if (invalidValues.length > 0) {
throw new ValidationException(invalidValues);
}
Criterion criterion = satisfactionDTO.getCriterionWithItsType().getCriterion();
if(checkSameCriterionAndSameInterval(satisfactionDTO)){
throw new IllegalStateException(_(" The "+criterion.getName()+
" can not be assigned to this resource. Its interval overlap with other criterion"));
Criterion criterion = satisfactionDTO.getCriterionWithItsType()
.getCriterion();
if (checkSameCriterionAndSameInterval(satisfactionDTO)) {
throw new IllegalStateException(
_(" The "
+ criterion.getName()
+ " can not be assigned to this resource. Its interval overlap with other criterion"));
}
if(checkNotAllowSimultaneousCriterionsPerResource(satisfactionDTO)){
throw new IllegalStateException(_(" The "+criterion.getName()+
"is not valid, the criterionType overlap other criterionSatisfaction whith same criterionType"));
if (checkNotAllowSimultaneousCriterionsPerResource(satisfactionDTO)) {
throw new IllegalStateException(
_(" The "
+ criterion.getName()
+ "is not valid, the criterionType overlap other criterionSatisfaction whith same criterionType"));
}
}
}
private void updateDTOs()throws ValidationException,IllegalStateException {
//Create a new list of Criterion satisfaction
private void updateDTOs() throws ValidationException, IllegalStateException {
// Create a new list of Criterion satisfaction
Set<CriterionSatisfaction> newList = new HashSet<CriterionSatisfaction>();
for(CriterionSatisfactionDTO satisfactionDTO :criterionSatisfactionDTOs){
for (CriterionSatisfactionDTO satisfactionDTO : criterionSatisfactionDTOs) {
CriterionSatisfaction satisfaction;
if(satisfactionDTO.isNewObject()){
Criterion criterion = satisfactionDTO.getCriterionWithItsType().getCriterion();
if (satisfactionDTO.isNewObject()) {
Criterion criterion = satisfactionDTO.getCriterionWithItsType()
.getCriterion();
Interval interval = satisfactionDTO.getInterval();
satisfaction = CriterionSatisfaction.create(criterion, worker, interval);
satisfaction = CriterionSatisfaction.create(criterion, worker,
interval);
}else{
} else {
satisfaction = satisfactionDTO.getCriterionSatisfaction();
if(satisfactionDTO.isIsDeleted()){
satisfaction.setIsDeleted(true);
}else{
if (satisfactionDTO.isIsDeleted()) {
satisfaction.setIsDeleted(true);
} else {
satisfaction.setStartDate(satisfactionDTO.getStartDate());
satisfaction.finish(satisfactionDTO.getEndDate());
}

View file

@ -68,8 +68,12 @@ public class CriterionSatisfactionDTO implements INewObject {
}
public String getState() {
if(startDate == null) return "";
if( !isFinished() || isCurrent() ) return "Current";
if (startDate == null) {
return "";
}
if (!isFinished() || isCurrent()) {
return "Current";
}
return "Expired";
}
@ -112,8 +116,10 @@ public class CriterionSatisfactionDTO implements INewObject {
public boolean isCurrent() {
Date now = new Date();
if(!isFinished()) return true;
return (now.compareTo(getEndDate()) <= 0);
if (!isFinished()) {
return true;
}
return now.compareTo(getEndDate()) <= 0;
}
public Interval getInterval() {
@ -146,41 +152,58 @@ public class CriterionSatisfactionDTO implements INewObject {
}
public boolean isLessToEndDate(Date startDate){
if((getEndDate() == null) ||
(startDate == null)) return true;
if(startDate.compareTo(getEndDate()) < 0) return true;
if (getEndDate() == null || startDate == null) {
return true;
}
if (startDate.compareTo(getEndDate()) < 0) {
return true;
}
return false;
}
public boolean isPreviousStartDate(Date startDate){
if(newObject) return true;
if((getStartDate() == null) ||
(startDate == null)) return true;
if(startDate.compareTo(getCriterionSatisfaction().getStartDate()) <= 0)
if (newObject) {
return true;
}
if (getStartDate() == null || startDate == null) {
return true;
}
if (startDate.compareTo(getCriterionSatisfaction().getStartDate()) <= 0) {
return true;
}
return false;
}
public boolean isGreaterStartDate(Date endDate){
if((getStartDate() == null) ||
(endDate == null)) return true;
if(endDate.compareTo(getStartDate()) >= 0) return true;
if (getStartDate() == null || endDate == null) {
return true;
}
if (endDate.compareTo(getStartDate()) >= 0) {
return true;
}
return false;
}
public boolean isPostEndDate(Date endDate){
if(newObject) return true;
if((getEndDate() == null) ||
(endDate == null)) return true;
if(getCriterionSatisfaction().getEndDate() == null)
if (newObject) {
return true;
if(endDate.compareTo(getCriterionSatisfaction().getEndDate()) >= 0)
}
if (getEndDate() == null || endDate == null) {
return true;
}
if (getCriterionSatisfaction().getEndDate() == null) {
return true;
}
if (endDate.compareTo(getCriterionSatisfaction().getEndDate()) >= 0) {
return true;
}
return false;
}
public String getCriterionAndType() {
if(criterionWithItsType == null) return criterionAndType;
if (criterionWithItsType == null) {
return criterionAndType;
}
return criterionWithItsType.getNameAndType();
}

View file

@ -57,8 +57,9 @@ public class CriterionsController extends GenericForwardComposer {
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
if (messagesContainer == null)
if (messagesContainer == null) {
throw new RuntimeException(_("MessagesContainer is needed"));
}
messages = new MessagesForUser(messagesContainer);
comp.setVariable("assignedCriterionsController", this, true);
//comboboxFilter = (Combobox) comp.getFellow("comboboxfilter");
@ -139,8 +140,12 @@ public class CriterionsController extends GenericForwardComposer {
private void validateCriterionWithItsType(CriterionSatisfactionDTO satisfaction,
Component comp) throws WrongValueException{
if(satisfaction.getCriterionWithItsType() == null) return;
if(satisfaction.getStartDate() == null) return;
if(satisfaction.getCriterionWithItsType() == null) {
return;
}
if(satisfaction.getStartDate() == null) {
return;
}
if(assignedCriterionsModel.checkSameCriterionAndSameInterval(satisfaction)){
throw new WrongValueException(comp,
_("Criterion is not valid, the criterion overlap other criterionSatisfaction whith same criterion"));

View file

@ -120,8 +120,12 @@ public class CriterionsMachineController extends GenericForwardComposer {
private void validateCriterionWithItsType(CriterionSatisfactionDTO satisfaction,
Component comp) throws WrongValueException{
if(satisfaction.getCriterionWithItsType() == null) return;
if(satisfaction.getStartDate() == null) return;
if(satisfaction.getCriterionWithItsType() == null) {
return;
}
if(satisfaction.getStartDate() == null) {
return;
}
if (assignedMachineCriterionsModel
.checkSameCriterionAndSameInterval(satisfaction)) {
throw new WrongValueException(comp,

View file

@ -127,8 +127,9 @@ public class WorkerCRUDController extends GenericForwardComposer implements
}
public LocalizationsController getLocalizations() {
if (workerModel.isCreating())
if (workerModel.isCreating()) {
return localizationsForCreationController;
}
return localizationsForEditionController;
}
@ -225,8 +226,9 @@ public class WorkerCRUDController extends GenericForwardComposer implements
localizationsForCreationController = createLocalizationsController(
comp, "editWindow");
comp.setVariable("controller", this, true);
if (messagesContainer == null)
if (messagesContainer == null) {
throw new RuntimeException(_("MessagesContainer is needed"));
}
messages = new MessagesForUser(messagesContainer);
this.addWorkRelationship = new WorkRelationshipsController(
this.workerModel, this, messages);

View file

@ -139,8 +139,9 @@ public class CriterionModelTest {
private CriterionType ensureExists(CriterionType transientType) {
List<CriterionType> found = criterionTypeDAO.findByName(transientType);
if (!found.isEmpty())
if (!found.isEmpty()) {
return found.get(0);
}
criterionTypeDAO.save(transientType);
return criterionTypeDAO.findByName(transientType).get(0);
}