/*******************************************************************************
* Copyright (c) 2012, 2015 Willink Transformations and others.
* 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:
* E.D.Willink - initial API and implementation
*******************************************************************************/
package org.eclipse.ocl.pivot.internal.ids;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.pivot.ids.BindingsId;
import org.eclipse.ocl.pivot.ids.CollectionTypeId;
import org.eclipse.ocl.pivot.ids.IdHash;
import org.eclipse.ocl.pivot.ids.IdManager;
import org.eclipse.ocl.pivot.ids.IdVisitor;
import org.eclipse.ocl.pivot.ids.TemplateParameterId;
import org.eclipse.ocl.pivot.ids.TypeId;
public class GeneralizedCollectionTypeIdImpl extends GeneralizedTypeIdImpl<CollectionTypeId> implements CollectionTypeId
{
public GeneralizedCollectionTypeIdImpl(@NonNull IdManager idManager, @NonNull String name) {
super(IdHash.createGlobalHash(CollectionTypeId.class, name), 1, name);
assert !MAP_NAME.equals(name);
}
@Override
public <R> R accept(@NonNull IdVisitor<R> visitor) {
return visitor.visitCollectionTypeId(this);
}
@Override
protected @NonNull CollectionTypeId createSpecializedId(@NonNull BindingsId templateBindings) {
return new SpecializedCollectionTypeIdImpl(this, templateBindings);
}
@Override
public @NonNull String getDisplayName() {
StringBuilder s = new StringBuilder();
s.append(name);
s.append(IdManager.getParametersId(CollectionTypeId.T_1));
return s.toString();
}
@Override
public @NonNull TemplateParameterId getElementTypeId() {
return TypeId.T_1;
}
@Override
public @NonNull CollectionTypeId getGeneralizedId() {
return this;
}
@Override
public @Nullable String getLiteralName() {
if (this == TypeId.BAG) {
return "BAG";
}
else if (this == TypeId.COLLECTION) {
return "COLLECTION";
}
else if (this == TypeId.ORDERED_SET) {
return "ORDERED_SET";
}
else if (this == TypeId.SEQUENCE) {
return "SEQUENCE";
}
else if (this == TypeId.SET) {
return "SET";
}
else if (this == TypeId.UNIQUE_COLLECTION) {
return "UNIQUE_COLLECTION";
}
else {
return null;
}
}
@Override
public @NonNull String getMetaTypeName() {
return name + "Type";
}
@Override
public @NonNull CollectionTypeId specialize(@NonNull BindingsId templateBindings) {
return getSpecializedId(templateBindings);
}
}