X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.common%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fcommon%2Fmodifiers%2FEnumeration.java;h=1376e4f1930a22039baf3e6c73aa61905c621046;hp=db5bd5629f3101d9d4208c9b60b961afc3821209;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=06718abb2b3cc780748553811c4857c165499809 diff --git a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/modifiers/Enumeration.java b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/modifiers/Enumeration.java index db5bd5629..1376e4f19 100644 --- a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/modifiers/Enumeration.java +++ b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/modifiers/Enumeration.java @@ -1,140 +1,140 @@ -/******************************************************************************* - * 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.browsing.ui.common.modifiers; - -import java.util.Arrays; -import java.util.List; - -/** - * @author Tuukka Lehtonen - * - * @param - */ -public class Enumeration { - - private final List> values; - private final transient int hash; - - public static Enumeration make(List> values) { - return new Enumeration(values); - } - - @SafeVarargs - public static Enumeration make(EnumeratedValue... values) { - return new Enumeration(Arrays.asList(values)); - } - - public Enumeration(List> values) { - assert values != null; - this.values = values; - hash = values.hashCode(); - } - - public List> values() { - return values; - } - - public boolean contains(EnumeratedValue value) { - return values.contains(value); - } - - public int indexOf(EnumeratedValue value) { - return values.indexOf(value); - } - - public int size() { - return values.size(); - } - - /** - * @param object - * @return the enumerated value matching the specified object - * @throws IllegalArgumentException if matching EnumeratedValue not found - * @throws NullPointerException if null object is specified - */ - public EnumeratedValue get(T object) { - if (object == null) - throw new NullPointerException("null object"); - for (EnumeratedValue value : values) - if (object.equals(value.getObject())) - return value; - throw new IllegalArgumentException("object '" + object + "' not found among enumeration " + values); - } - - /** - * Find an EnumeratedValue matching the specified name. - * - * @param name - * @return null if corresponding EnumeratedValue not found - */ - public EnumeratedValue findByName(String name) { - if (name == null) - return null; - for (EnumeratedValue value : values) - if (name.equals(value.getName())) - return value; - return null; - } - - /** - * Find an EnumeratedValue matching the specified name. - * - * @param name - * @return null if corresponding EnumeratedValue not found - */ - public EnumeratedValue findByNameStartsWith(String name) { - if (name == null) - return null; - for (EnumeratedValue value : values) - if (value.getName().startsWith(name)) - return value; - return null; - } - - /** - * Find an EnumeratedValue matching the specified object. - * - * @param object - * @return null if corresponding EnumeratedValue not found - */ - public EnumeratedValue find(T object) { - if (object == null) - return null; - for (EnumeratedValue value : values) - if (object.equals(value.getObject())) - return value; - return null; - } - - @Override - public String toString() { - return values.toString(); - } - - @Override - public int hashCode() { - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Enumeration other = (Enumeration) obj; - return values.equals(other.values); - } - -} +/******************************************************************************* + * 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.browsing.ui.common.modifiers; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Tuukka Lehtonen + * + * @param + */ +public class Enumeration { + + private final List> values; + private final transient int hash; + + public static Enumeration make(List> values) { + return new Enumeration(values); + } + + @SafeVarargs + public static Enumeration make(EnumeratedValue... values) { + return new Enumeration(Arrays.asList(values)); + } + + public Enumeration(List> values) { + assert values != null; + this.values = values; + hash = values.hashCode(); + } + + public List> values() { + return values; + } + + public boolean contains(EnumeratedValue value) { + return values.contains(value); + } + + public int indexOf(EnumeratedValue value) { + return values.indexOf(value); + } + + public int size() { + return values.size(); + } + + /** + * @param object + * @return the enumerated value matching the specified object + * @throws IllegalArgumentException if matching EnumeratedValue not found + * @throws NullPointerException if null object is specified + */ + public EnumeratedValue get(T object) { + if (object == null) + throw new NullPointerException("null object"); + for (EnumeratedValue value : values) + if (object.equals(value.getObject())) + return value; + throw new IllegalArgumentException("object '" + object + "' not found among enumeration " + values); + } + + /** + * Find an EnumeratedValue matching the specified name. + * + * @param name + * @return null if corresponding EnumeratedValue not found + */ + public EnumeratedValue findByName(String name) { + if (name == null) + return null; + for (EnumeratedValue value : values) + if (name.equals(value.getName())) + return value; + return null; + } + + /** + * Find an EnumeratedValue matching the specified name. + * + * @param name + * @return null if corresponding EnumeratedValue not found + */ + public EnumeratedValue findByNameStartsWith(String name) { + if (name == null) + return null; + for (EnumeratedValue value : values) + if (value.getName().startsWith(name)) + return value; + return null; + } + + /** + * Find an EnumeratedValue matching the specified object. + * + * @param object + * @return null if corresponding EnumeratedValue not found + */ + public EnumeratedValue find(T object) { + if (object == null) + return null; + for (EnumeratedValue value : values) + if (object.equals(value.getObject())) + return value; + return null; + } + + @Override + public String toString() { + return values.toString(); + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Enumeration other = (Enumeration) obj; + return values.equals(other.values); + } + +}