comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/BindingStatus.d @ 78:0a55d2d5a946

Added file for databinding
author Frank Benoit <benoit@tionex.de>
date Tue, 14 Apr 2009 11:35:29 +0200
parents
children 6be48cf9f95c
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11
12 module org.eclipse.core.internal.databinding.BindingStatus;
13
14 import java.lang.all;
15
16 import java.util.Arrays;
17
18 import org.eclipse.core.databinding.util.Policy;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.MultiStatus;
21
22 /**
23 * A <code>MultiStatus</code> implementation that copies that state of the
24 * added status to this instance if it is >= the current severity.
25 *
26 * @since 1.0
27 */
28 public class BindingStatus : MultiStatus {
29 /**
30 * Constructs a new instance.
31 *
32 * @param pluginId
33 * @param code
34 * @param message
35 * @param exception
36 */
37 public this(String pluginId, int code, String message,
38 Throwable exception) {
39 super(pluginId, code, message, exception);
40 }
41
42 /**
43 * Adds the status to the multi status. The details of the status will be
44 * copied to the multi status if the severity is >= the current severity.
45 *
46 * @see org.eclipse.core.runtime.MultiStatus#add(org.eclipse.core.runtime.IStatus)
47 */
48 public void add(IStatus status) {
49 if (status.getSeverity() >= getSeverity()) {
50 setMessage((status.getMessage() !is null) ? status.getMessage() : ""); //$NON-NLS-1$
51 setException(status.getException());
52 setPlugin(status.getPlugin());
53 setCode(status.getCode());
54 }
55
56 super.add(status);
57 }
58
59 /**
60 * Instance initialized with the following values:
61 * <ul>
62 * <li>plugin = Policy.JFACE_DATABINDING</li>
63 * <li>severity = 0</li>
64 * <li>code = 0</li>
65 * <li>message = ""</li>
66 * <li>exception = null</li>
67 * </ul>
68 *
69 * @return status
70 */
71 public static BindingStatus ok() {
72 return new BindingStatus(Policy.JFACE_DATABINDING, 0, "", null); //$NON-NLS-1$
73 }
74
75 private static int hashCode(Object[] array) {
76 final int prime = 31;
77 if (array is null)
78 return 0;
79 int result = 1;
80 for (int index = 0; index < array.length; index++) {
81 result = prime * result
82 + (array[index] is null ? 0 : array[index].hashCode());
83 }
84 return result;
85 }
86
87 public int hashCode() {
88 final int prime = 31;
89 int result = 1;
90 result = prime * result + BindingStatus.hashCode(getChildren());
91 return result;
92 }
93
94 public override bool opEquals(Object obj) {
95 if (this is obj)
96 return true;
97 if (obj is null)
98 return false;
99 if (getClass() !is obj.getClass())
100 return false;
101 final BindingStatus other = cast(BindingStatus) obj;
102 if (!Arrays.equals(getChildren(), other.getChildren()))
103 return false;
104 return true;
105 }
106 }