X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.utils%2Fsrc%2Forg%2Fsimantics%2Futils%2FGroupException.java;h=e077a4f00bb1acac5b030d76433138205dbeb4b8;hb=refs%2Fchanges%2F38%2F238%2F2;hp=af44a137f288f8c592e888b3f28714f97cad5c3b;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/GroupException.java b/bundles/org.simantics.utils/src/org/simantics/utils/GroupException.java index af44a137f..e077a4f00 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/GroupException.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/GroupException.java @@ -1,64 +1,64 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.utils; - -import java.util.Collection; - -/** - * GroupException is a Exception container for a set of exceptions. - * - *

- * Use {@link #group(Collection)} or {@link #group(Exception...)} to construct - * it. - * - * @author Toni Kalajainen - */ -public class GroupException extends Exception { - - private static final long serialVersionUID = 1L; - - private final Throwable errors[]; - - private GroupException(Throwable[] errors) { - super(GroupException.getAsText(errors)); - this.errors = errors; - } - - public static Exception group(Exception... errors) { - if (errors.length == 0) - throw new IllegalArgumentException("zero exceptions for GroupException"); - if (errors.length == 1) - return errors[0]; - return new GroupException(errors); - } - - public static Throwable group(Collection collection) { - if (collection.size() == 0) - throw new IllegalArgumentException("zero exceptions for GroupException"); - if (collection.size() == 1) - return collection.iterator().next(); - return new GroupException(collection.toArray(new Exception[collection.size()])); - } - - private static String getAsText(Throwable errors[]) { - String result = ""; - for (Throwable error : errors) { - result += error.getClass().getName()+": "+error.getMessage() + "\n"; - } - return result; - } - - public Throwable[] getErrors() { - return errors; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.utils; + +import java.util.Collection; + +/** + * GroupException is a Exception container for a set of exceptions. + * + *

+ * Use {@link #group(Collection)} or {@link #group(Exception...)} to construct + * it. + * + * @author Toni Kalajainen + */ +public class GroupException extends Exception { + + private static final long serialVersionUID = 1L; + + private final Throwable errors[]; + + private GroupException(Throwable[] errors) { + super(GroupException.getAsText(errors)); + this.errors = errors; + } + + public static Exception group(Exception... errors) { + if (errors.length == 0) + throw new IllegalArgumentException("zero exceptions for GroupException"); + if (errors.length == 1) + return errors[0]; + return new GroupException(errors); + } + + public static Throwable group(Collection collection) { + if (collection.size() == 0) + throw new IllegalArgumentException("zero exceptions for GroupException"); + if (collection.size() == 1) + return collection.iterator().next(); + return new GroupException(collection.toArray(new Exception[collection.size()])); + } + + private static String getAsText(Throwable errors[]) { + String result = ""; + for (Throwable error : errors) { + result += error.getClass().getName()+": "+error.getMessage() + "\n"; + } + return result; + } + + public Throwable[] getErrors() { + return errors; + } + +}