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

io.katharsis.jpa.internal.query.backend.querydsl.ObjectArrayTupleImpl Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package io.katharsis.jpa.internal.query.backend.querydsl;

import java.util.Arrays;
import java.util.List;

import javax.persistence.TupleElement;

import com.querydsl.core.types.Expression;

import io.katharsis.jpa.query.criteria.JpaCriteriaTuple;
import io.katharsis.jpa.query.querydsl.QuerydslTuple;

public class ObjectArrayTupleImpl implements QuerydslTuple, JpaCriteriaTuple {

	private Object[] data;
	private int numEntriesToIgnore;

	public ObjectArrayTupleImpl(Object entity) {
		if (entity instanceof Object[]) {
			data = (Object[]) entity;
		}
		else {
			data = new Object[] { entity };
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public  T get(int index, Class type) {
		return (T) data[index + numEntriesToIgnore];
	}

	@Override
	public  T get(Expression expr) {
		throw new UnsupportedOperationException();
	}

	@Override
	public int size() {
		return data.length - numEntriesToIgnore;
	}

	@Override
	public Object[] toArray() {
		if(numEntriesToIgnore > 0){
			return Arrays.copyOfRange(data, numEntriesToIgnore, data.length - numEntriesToIgnore);
		}else{
			return data;
		}
	}

	@Override
	public  T get(String name, Class clazz) {
		throw new UnsupportedOperationException();
	}

	@Override
	public  X get(TupleElement element) {
		throw new UnsupportedOperationException();
	}

	@Override
	public Object get(String name) {
		throw new UnsupportedOperationException();
	}

	@Override
	public Object get(int index) {
		return get(index, Object.class);
	}

	@Override
	public List> getElements() {
		throw new UnsupportedOperationException();
	}

	@Override
	public void reduce(int numEntriesToIgnore) {
		this.numEntriesToIgnore = numEntriesToIgnore;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy