当前位置: 首页>>代码示例>>Java>>正文


Java GenericReflection类代码示例

本文整理汇总了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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:RingBufferFifo.java

示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:RingBufferLifo.java

示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:19,代码来源:SingleElementList.java

示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:SettingsMicroDocumentConverter.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:SettingsPersistenceXML.java

示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:19,代码来源:Dijkstra.java

示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:24,代码来源:MicroTypeConverter.java

示例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 ();
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:CombinationGenerator.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:SerializationConverter.java

示例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));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:26,代码来源:SerializationConverter.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:SerializationHelper.java

示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:AbstractConcurrentCollector.java

示例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);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:34,代码来源:ConcurrentCollectorSingle.java

示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:TypeConverterProviderBestMatch.java

示例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);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:18,代码来源:AbstractSoftMap.java


注:本文中的com.helger.commons.lang.GenericReflection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。