CursorTransformer.java revision 23cb1d1297a0807fe827a38a17c54bfe1fd05e2d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2015 ForgeRock AS
*/
/**
* Transforms the keys and values of a cursor from their original types to others. Typically used for
* data serialization,deserialization.
*
* @param
* Original cursor's key type
* @param
* Original cursor's value type
* @param
* Transformed cursor's key type
* @param
* Transformed cursor's value type
*/
{
/**
* Allow to transform a cursor value given the key and the original value
* @param Original type of the cursor's key
* @param Original type of the cursor's value
* @param New transformed type of the value
* @param <E> Possible exception type
*/
{
}
{
{
return value;
}
};
private KO cachedTransformedKey;
private VO cachedTransformedValue;
{
}
@SuppressWarnings("unchecked")
{
return transformKeysAndValues(input, (Function<KI, KI, NeverThrowsException>) NO_TRANSFORM, valueTransformer);
}
private CursorTransformer(Cursor<KI, VI> input, Function<KI, KO, ? extends Exception> keyTransformer,
{
}
public void close()
{
}
{
if (cachedTransformedKey == null)
{
try
{
}
catch (Exception e)
{
}
}
return cachedTransformedKey;
}
{
if (cachedTransformedValue == null)
{
try
{
}
catch (Exception e)
{
}
}
return cachedTransformedValue;
}
public boolean next()
{
clearCache();
}
{
clearCache();
}
{
clearCache();
}
public boolean positionToLastKey()
{
clearCache();
return input.positionToLastKey();
}
public boolean positionToIndex(int index)
{
}
public boolean isDefined()
{
}
private void clearCache()
{
}
/**
* Runtime exception for problems happening during the transformation
*/
@SuppressWarnings("serial")
private static class TransformationException extends RuntimeException
{
private final Object originalKey;
private final Object originalValue;
{
super(e);
this.originalKey = originalKey;
this.originalValue = originalValue;
}
/**
* Get the key of the record which caused the transformation error.
*
* @return The not transformed key of the record.
*/
public Object getOriginalKey()
{
return originalKey;
}
/**
* Get the value of the record which caused the transformation error.
*
* @return The not transformed value of the record.
*/
public Object getOriginalValue()
{
return originalValue;
}
}
}