本文整理汇总了Java中com.helger.commons.lang.GenericReflection类的典型用法代码示例。如果您正苦于以下问题:Java GenericReflection类的具体用法?Java GenericReflection怎么用?Java GenericReflection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericReflection类属于com.helger.commons.lang包,在下文中一共展示了GenericReflection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: take
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
/**
* Take an element from the ring buffer.
*
* @return <code>null</code> if no more element is available or if the current
* element is <code>null</code>.
*/
@Nullable
public ELEMENTTYPE take ()
{
final int nAvailable = m_nAvailable;
if (nAvailable == 0)
return null;
int nIndex = m_nWritePos - nAvailable;
if (nIndex < 0)
nIndex += m_nCapacity;
final Object ret = m_aElements[nIndex];
m_nAvailable--;
return GenericReflection.uncheckedCast (ret);
}
示例2: take
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
/**
* Take an element from the ring buffer.
*
* @return <code>null</code> if no more element is available or if the current
* element is <code>null</code>.
*/
@Nullable
public ELEMENTTYPE take ()
{
final int nAvailable = m_nAvailable;
if (nAvailable == 0)
return null;
int nIndex = m_nWritePos - 1;
if (nIndex < 0)
nIndex += m_nCapacity;
final Object ret = m_aElements[nIndex];
m_nWritePos = nIndex;
m_nAvailable--;
return GenericReflection.uncheckedCast (ret);
}
示例3: toArray
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nonnull
public <ARRAYELEMENTTYPE> ARRAYELEMENTTYPE [] toArray (@Nonnull final ARRAYELEMENTTYPE [] aDest)
{
ValueEnforcer.notNull (aDest, "Dest");
if (!m_bHasElement)
return aDest;
if (m_aElement != null && !aDest.getClass ().getComponentType ().isAssignableFrom (m_aElement.getClass ()))
throw new ArrayStoreException ("The array class " +
aDest.getClass () +
" cannot store the item of class " +
m_aElement.getClass ());
final ARRAYELEMENTTYPE [] ret = aDest.length < 1 ? ArrayHelper.newArraySameType (aDest, 1) : aDest;
ret[0] = GenericReflection.uncheckedCast (m_aElement);
if (ret.length > 1)
ret[1] = null;
return ret;
}
示例4: convertToNative
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nonnull
public T convertToNative (final IMicroElement aElement)
{
// Create new settings object
final String sSettingsName = aElement.getAttributeValue (ATTR_NAME);
final T aSettings = m_aSettingFactory.apply (sSettingsName);
// settings are only on the top-level
aElement.forAllChildElements (eSetting -> {
final String sFieldName = eSetting.getAttributeValue (ATTR_NAME);
final String sClass = eSetting.getAttributeValue (ATTR_CLASS);
final Class <?> aDestClass = GenericReflection.getClassFromNameSafe (sClass);
if (aDestClass == null)
throw new IllegalStateException ("Failed to determine class from '" + sClass + "'");
final Object aValue = MicroTypeConverter.convertToNative (eSetting.getFirstChildElement (ELEMENT_VALUE),
aDestClass);
// Use put instead of putIn to avoid that the callbacks are invoked!
aSettings.put (sFieldName, aValue);
});
return aSettings;
}
示例5: writeSettings
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nonnull
public ESuccess writeSettings (@Nonnull final ISettings aSettings, @Nonnull @WillClose final OutputStream aOS)
{
ValueEnforcer.notNull (aSettings, "Settings");
ValueEnforcer.notNull (aOS, "OutputStream");
try
{
// Inside try so that OS is closed
ValueEnforcer.notNull (aSettings, "Settings");
// No event manager invocation on writing
final SettingsMicroDocumentConverter <T> aConverter = new SettingsMicroDocumentConverter <> (m_aSettingsFactory);
final IMicroDocument aDoc = new MicroDocument ();
aDoc.appendChild (aConverter.convertToMicroElement (GenericReflection.uncheckedCast (aSettings),
getWriteNamespaceURI (),
getWriteElementName ()));
// auto-closes the stream
return MicroWriter.writeToStream (aDoc, aOS, m_aXWS);
}
finally
{
StreamHelper.close (aOS);
}
}
示例6: _getRelationFromLastMatch
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nullable
private static <N extends IMutableBaseGraphNode <N, R>, R extends IMutableBaseGraphRelation <N, R>> R _getRelationFromLastMatch (@Nonnull final WorkElement <N> aLastMatch,
@Nonnull final N aNode)
{
if (aNode.isDirected ())
{
// Directed
// Cast to Object required for JDK command line compiler
final Object aDirectedFromNode = aLastMatch.getToNode ();
final Object aDirectedToNode = aNode;
final IMutableDirectedGraphRelation r = ((IMutableDirectedGraphNode) aDirectedFromNode).getOutgoingRelationTo ((IMutableDirectedGraphNode) aDirectedToNode);
return GenericReflection.uncheckedCast (r);
}
// Undirected
return aLastMatch.getToNode ().getRelation (aNode);
}
示例7: convertToMicroElement
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nullable
public static <T> IMicroElement convertToMicroElement (@Nullable final T aObject,
@Nullable final String sNamespaceURI,
@Nonnull @Nonempty final String sTagName) throws TypeConverterException
{
ValueEnforcer.notEmpty (sTagName, "TagName");
if (aObject == null)
return null;
// Lookup converter
final Class <T> aSrcClass = GenericReflection.uncheckedCast (aObject.getClass ());
final IMicroTypeConverter <T> aConverter = MicroTypeConverterRegistry.getInstance ()
.getConverterToMicroElement (aSrcClass);
if (aConverter == null)
throw new TypeConverterException (aSrcClass, IMicroElement.class, EReason.NO_CONVERTER_FOUND);
// Perform conversion
final IMicroElement ret = aConverter.convertToMicroElement (aObject, sNamespaceURI, sTagName);
if (ret == null)
throw new TypeConverterException (aSrcClass, IMicroElement.class, EReason.CONVERSION_FAILED);
return ret;
}
示例8: CombinationGenerator
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
/**
* Ctor
*
* @param aElements
* the elements to fill into the slots for creating all combinations
* (must not be empty!)
* @param nSlotCount
* the number of slots to use (must not be greater than the element
* count!)
*/
public CombinationGenerator (@Nonnull @Nonempty final ICommonsList <DATATYPE> aElements,
@Nonnegative final int nSlotCount)
{
ValueEnforcer.notEmpty (aElements, "Elements");
ValueEnforcer.isBetweenInclusive (nSlotCount, "SlotCount", 0, aElements.size ());
m_aElements = GenericReflection.uncheckedCast (aElements.toArray ());
m_aIndexResult = new int [nSlotCount];
final BigInteger aElementFactorial = FactorialHelper.getAnyFactorialLinear (m_aElements.length);
final BigInteger aSlotFactorial = FactorialHelper.getAnyFactorialLinear (nSlotCount);
final BigInteger aOverflowFactorial = FactorialHelper.getAnyFactorialLinear (m_aElements.length - nSlotCount);
m_aTotalCombinations = aElementFactorial.divide (aSlotFactorial.multiply (aOverflowFactorial));
// Can we use the fallback to long? Is much faster than using BigInteger
m_bUseLong = m_aTotalCombinations.compareTo (CGlobal.BIGINT_MAX_LONG) < 0;
m_nTotalCombinations = m_bUseLong ? m_aTotalCombinations.longValue () : CGlobal.ILLEGAL_ULONG;
reset ();
}
示例9: writeConvertedObject
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
public static <T> void writeConvertedObject (@Nullable final T aObject,
@Nonnull final ObjectOutputStream aOOS) throws TypeConverterException,
IOException
{
ValueEnforcer.notNull (aOOS, "ObjectOutputStream");
// Write boolean flag indicating null or not
aOOS.writeBoolean (aObject == null);
if (aObject != null)
{
// Lookup converter
final Class <T> aSrcClass = GenericReflection.uncheckedCast (aObject.getClass ());
final ISerializationConverter <T> aConverter = SerializationConverterRegistry.getInstance ()
.getConverter (aSrcClass);
if (aConverter == null)
throw new TypeConverterException (aSrcClass, EReason.NO_CONVERTER_FOUND_SINGLE);
// Perform conversion
aConverter.writeConvertedObject (aObject, aOOS);
}
}
示例10: readConvertedObject
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nullable
public static <DSTTYPE> DSTTYPE readConvertedObject (@Nonnull final ObjectInputStream aOIS,
@Nonnull final Class <DSTTYPE> aDstClass) throws TypeConverterException,
IOException
{
ValueEnforcer.notNull (aOIS, "ObjectInputStream");
ValueEnforcer.notNull (aDstClass, "DestinationClass");
// Was the object null?
final boolean bIsNull = aOIS.readBoolean ();
if (bIsNull)
{
// Don't read anything
return null;
}
// Lookup converter
final ISerializationConverter <DSTTYPE> aConverter = SerializationConverterRegistry.getInstance ()
.getConverter (aDstClass);
if (aConverter == null)
throw new TypeConverterException (aDstClass, EReason.NO_CONVERTER_FOUND_SINGLE);
// Convert
return GenericReflection.uncheckedCast (aConverter.readConvertedObject (aOIS));
}
示例11: getDeserializedObject
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
/**
* Convert the passed byte array to an object using deserialization.
*
* @param aData
* The source serialized byte array. Must contain a single object only.
* May not be <code>null</code>.
* @return The deserialized object. Never <code>null</code>.
* @throws IllegalStateException
* If deserialization failed
* @param <T>
* The type of the deserialized object
*/
@Nonnull
public static <T> T getDeserializedObject (@Nonnull final byte [] aData)
{
ValueEnforcer.notNull (aData, "Data");
// Read new object from byte array
try (final ObjectInputStream aOIS = new ObjectInputStream (new NonBlockingByteArrayInputStream (aData)))
{
return GenericReflection.uncheckedCast (aOIS.readObject ());
}
catch (final Exception ex)
{
throw new IllegalStateException ("Failed to read serializable object", ex);
}
}
示例12: drainQueue
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nonnull
@ReturnsMutableCopy
public final ICommonsList <DATATYPE> drainQueue ()
{
// Drain all objects to this queue
final ICommonsList <Object> aDrainedToList = new CommonsArrayList <> ();
m_aRWLock.writeLocked ( () -> m_aQueue.drainTo (aDrainedToList));
// Change data type
final ICommonsList <DATATYPE> ret = new CommonsArrayList <> ();
for (final Object aObj : aDrainedToList)
if (!EqualsHelper.identityEqual (aObj, STOP_QUEUE_OBJECT))
ret.add (GenericReflection.uncheckedCast (aObj));
else
{
// Re-add the stop object, because loops in derived classes rely on this
// object
m_aRWLock.writeLocked ( () -> m_aQueue.add (aObj));
}
return ret;
}
示例13: collect
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
/**
* This method starts the collector by taking objects from the internal
* {@link BlockingQueue}. So this method blocks and must be invoked from a
* separate thread. This method runs until {@link #stopQueuingNewObjects()} is
* new called and the queue is empty.
*
* @throws IllegalStateException
* if no performer is set - see
* {@link #setPerformer(IConcurrentPerformer)}
*/
public final void collect ()
{
if (m_aPerformer == null)
throw new IllegalStateException ("No performer set!");
try
{
// The temporary list that contains all objects to be delivered
while (true)
{
// Block until the first object is in the queue
final Object aCurrentObject = m_aQueue.take ();
if (aCurrentObject == STOP_QUEUE_OBJECT)
break;
_perform (GenericReflection.uncheckedCast (aCurrentObject));
}
}
catch (final Throwable t)
{
s_aLogger.error ("Error taking elements from queue - queue has been interrupted!!!", t);
}
}
示例14: getTypeConverter
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nullable
public ITypeConverter <Object, Object> getTypeConverter (@Nonnull final Class <?> aSrcClass,
@Nonnull final Class <?> aDstClass)
{
final TypeConverterRegistry aTCR = TypeConverterRegistry.getInstance ();
// Find exact hit first
ITypeConverter <?, ?> ret = aTCR.getExactConverter (aSrcClass, aDstClass);
if (ret == null)
{
// No exact match was found -> try rule based converter
ret = aTCR.getRuleBasedConverter (aSrcClass, aDstClass);
if (ret == null)
{
// No exact match was found -> try fuzzy converter
ret = aTCR.getFuzzyConverter (aSrcClass, aDstClass);
}
}
return GenericReflection.uncheckedCast (ret);
}
示例15: toArray
import com.helger.commons.lang.GenericReflection; //导入依赖的package包/类
@Nonnull
public <T> T [] toArray (@Nullable final T [] a)
{
MapEntry <K, V> [] result = null;
if (a != null && a instanceof MapEntry <?, ?> [] && a.length >= size ())
result = GenericReflection.uncheckedCast (a);
else
result = GenericReflection.uncheckedCast (new MapEntry <?, ?> [size ()]);
final Object [] aSrcArray = m_aSrcEntrySet.toArray ();
for (int i = 0; i < aSrcArray.length; i++)
{
final Map.Entry <K, SoftValue <K, V>> e = GenericReflection.uncheckedCast (aSrcArray[i]);
result[i] = new MapEntry<> (e.getKey (), e.getValue ().get ());
}
return GenericReflection.uncheckedCast (result);
}