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

org.jnosql.diana.cassandra.column.IterableUDT Maven / Gradle / Ivy

There is a newer version: 0.0.9
Show newest version
/*
 *  Copyright (c) 2017 Otávio Santana and others
 *   All rights reserved. This program and the accompanying materials
 *   are made available under the terms of the Eclipse Public License v1.0
 *   and Apache License v2.0 which accompanies this distribution.
 *   The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
 *   and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php.
 *
 *   You may elect to redistribute this code under either of these licenses.
 *
 *   Contributors:
 *
 *   Otavio Santana
 */
package org.jnosql.diana.cassandra.column;

import org.jnosql.diana.api.TypeSupplier;
import org.jnosql.diana.api.Value;
import org.jnosql.diana.api.column.Column;

import java.util.Objects;

/**
 * On Cassandra, there is the option to a UDT be part of a list. This implementation holds this option.
 */
class IterableUDT implements UDT {

    private final String name;

    private final String userType;

    private final Iterable> columns;

    IterableUDT(String name, String userType, Iterable> columns) {
        this.name = name;
        this.userType = userType;
        this.columns = columns;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public Value getValue() {
        return Value.of(columns);
    }

    @Override
    public  T get(Class clazz) throws NullPointerException, UnsupportedOperationException {
        Objects.requireNonNull(clazz, "clazz is required");
        return Value.of(columns).get(clazz);
    }

    @Override
    public  T get(TypeSupplier typeSupplier) throws NullPointerException, UnsupportedOperationException {
        Objects.requireNonNull(typeSupplier, "typeSupplier is required");
        return Value.of(columns).get(typeSupplier);

    }

    @Override
    public Object get() {
        return columns;
    }

    @Override
    public String getUserType() {
        return userType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof UDT)) {
            return false;
        }
        UDT udt = (UDT) o;
        return Objects.equals(name, udt.getName()) &&
                Objects.equals(userType, udt.getUserType()) &&
                Objects.equals(columns, udt.get());
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, userType, columns);
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("UDT{");
        sb.append("name='").append(name).append('\'');
        sb.append(", userType='").append(userType).append('\'');
        sb.append(", columns=").append(columns);
        sb.append('}');
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy