All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.speedment.common.codegen.internal.model.EnumConstantImpl Maven / Gradle / Ivy

Go to download

A Speedment bundle that shades all dependencies into one jar. This is useful when deploying an application on a server.

The newest version!
/*
 *
 * Copyright (c) 2006-2019, Speedment, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); You may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.speedment.common.codegen.internal.model;

import com.speedment.common.codegen.internal.util.Copier;
import com.speedment.common.codegen.model.*;
import com.speedment.common.codegen.model.Enum;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

/**
 * This is the default implementation of the {@link EnumConstant} interface.
 * This class should not be instantiated directly. Instead you should call the
 * {@link EnumConstant#of(java.lang.String)} method to get an instance. In that way, 
 * you can later change the implementing class without modifying the using code.
 * 
 * @author Emil Forslund
 * @see    EnumConstant
 */
public final class EnumConstantImpl implements EnumConstant {

    private Enum parent;
	private String name;
    private Javadoc javadoc;
    private final List imports;
    private final List> classes;
    private final List initializers;
    private final List methods;
    private final List fields;
	private final List> values;
	private final List annotations;

    /**
     * Initializes this enum constant using a name.
     * 

* Warning! This class should not be instantiated directly but using * the {@link EnumConstant#of(java.lang.String)} method! * * @param name the name */ public EnumConstantImpl(String name) { this.name = requireNonNull(name); this.imports = new ArrayList<>(); this.classes = new ArrayList<>(); this.initializers = new ArrayList<>(); this.methods = new ArrayList<>(); this.fields = new ArrayList<>(); this.values = new ArrayList<>(); this.annotations = new ArrayList<>(); } /** * Copy constructor. * * @param prototype the prototype */ protected EnumConstantImpl(EnumConstant prototype) { name = requireNonNull(prototype).getName(); javadoc = prototype.getJavadoc().orElse(null); imports = Copier.copy(prototype.getImports()); classes = Copier.copy(prototype.getClasses(), c -> c.copy()); initializers = Copier.copy(prototype.getInitializers(), c -> c.copy()); methods = Copier.copy(prototype.getMethods(), c -> c.copy()); fields = Copier.copy(prototype.getFields(), c -> c.copy()); values = Copier.copy(prototype.getValues(), c -> c.copy()); annotations = Copier.copy(prototype.getAnnotations(), c -> c.copy()); } @Override public EnumConstant setParent(Enum parent) { this.parent = parent; return this; } @Override public Optional getParent() { return Optional.ofNullable(parent); } @Override public List getImports() { return imports; } @Override public EnumConstant setName(String name) { this.name = requireNonNull(name); return this; } @Override public String getName() { return name; } @Override public List> getValues() { return values; } @Override public EnumConstant set(Javadoc doc) { this.javadoc = doc.setParent(this); return this; } @Override public Optional getJavadoc() { return Optional.ofNullable(javadoc); } @Override public List> getClasses() { return classes; } @Override public List getInitializers() { return initializers; } @Override public List getMethods() { return methods; } @Override public List getFields() { return fields; } @Override public List getAnnotations() { return annotations; } @Override public EnumConstantImpl copy() { return new EnumConstantImpl(this); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy