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

com.github.dm.rf.android.internal.TranslatedSimpleArrayMapIterator Maven / Gradle / Ivy

/**
 * 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.github.dm.rf.android.internal;

import com.github.dm.rf.android.entry.ObjectSparseObjectEntry;
import com.github.dm.rf.android.entry.ParcelableObjectSparseObjectEntry;
import com.github.dm.rf.android.entry.SimpleArrayMapEntry;
import com.github.dm.rf.android.entry.SparseEntries;
import com.github.dm.rf.android.translator.FullTranslator;

/**
 * Implementation of {@link SparseIterator} of
 * {@link SimpleArrayMapEntry} elements whose keys and values are
 * transformed through the specified translators.
 * 

* Created by davide-maestroni on 3/31/14. * * @param the translated element key type. * @param the original element key type. * @param the translated element value type. * @param the original element value type. */ class TranslatedSimpleArrayMapIterator implements SparseIterator>, SimpleArrayMapEntry { private final SparseIterator> mIterator; private final FullTranslator mKeyTranslator; private final FullTranslator mValueTranslator; private SimpleArrayMapEntry mEntry; public TranslatedSimpleArrayMapIterator(final SparseIterator> wrapped, final FullTranslator keyTranslator, final FullTranslator valueTranslator) { mIterator = wrapped; mKeyTranslator = keyTranslator; mValueTranslator = valueTranslator; } @Override public int getIndex() { return mEntry.getIndex(); } @Override public TK getKey() { return mKeyTranslator.translate(mEntry.getKey()); } @Override public TV getValue() { return mValueTranslator.translate(mEntry.getValue()); } @Override public void setValue(final TV value) { mEntry.setValue(mValueTranslator.revert(value)); } @Override public ObjectSparseObjectEntry toImmutable() { return SparseEntries.entry(getKey(), getValue()); } @Override public ParcelableObjectSparseObjectEntry toParcelable() { return SparseEntries.parcelableEntry(getKey(), getValue()); } @Override public boolean hasNext() { return mIterator.hasNext(); } @Override public SimpleArrayMapEntry next() { mEntry = mIterator.next(); return this; } @Override public void remove() { mIterator.remove(); } @Override public int originalIndex() { return mIterator.originalIndex(); } @Override public void reset() { mIterator.reset(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy