org.eclipse.sisu.wire.ProviderIterableAdapter Maven / Gradle / Ivy
/*
* Copyright (c) 2010-2024 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stuart McCulloch (Sonatype, Inc.) - initial API and implementation
*/
package org.eclipse.sisu.wire;
import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.Map.Entry;
import javax.inject.Provider;
import org.eclipse.sisu.BeanEntry;
/**
* {@link Iterable} sequence of {@link Provider} entries backed by a sequence of {@link BeanEntry}s.
*/
final class ProviderIterableAdapter
implements Iterable>>
{
// ----------------------------------------------------------------------
// Implementation fields
// ----------------------------------------------------------------------
private final Iterable> delegate;
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
ProviderIterableAdapter( final Iterable> delegate )
{
this.delegate = delegate;
}
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
public Iterator>> iterator()
{
return new ProviderIterator( delegate );
}
// ----------------------------------------------------------------------
// Implementation types
// ----------------------------------------------------------------------
/**
* Iterator of {@link Provider} {@link Entry}s backed by an iterator of {@link BeanEntry}s.
*/
private static final class ProviderIterator
implements Iterator>>
{
// ----------------------------------------------------------------------
// Implementation fields
// ----------------------------------------------------------------------
private final Iterator> iterator;
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
ProviderIterator( final Iterable> iterable )
{
iterator = iterable.iterator();
}
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
public boolean hasNext()
{
return iterator.hasNext();
}
public Entry> next()
{
return new ProviderEntry( iterator.next() );
}
public void remove()
{
throw new UnsupportedOperationException();
}
}
/**
* {@link Provider} {@link Entry} backed by a {@link BeanEntry}.
*/
private static final class ProviderEntry
implements Entry>
{
// ----------------------------------------------------------------------
// Implementation fields
// ----------------------------------------------------------------------
private final BeanEntry entry;
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
ProviderEntry( final BeanEntry entry )
{
this.entry = entry;
}
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
public K getKey()
{
return entry.getKey();
}
public Provider getValue()
{
return entry.getProvider();
}
public Provider setValue( final Provider value )
{
throw new UnsupportedOperationException();
}
@Override
public String toString()
{
return getKey() + "=" + getValue();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy