weka.core.Utils.cast()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中weka.core.Utils.cast()方法的一些代码示例,展示了Utils.cast()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.cast()方法的具体详情如下:
包路径:weka.core.Utils
类名称:Utils
方法名:cast

Utils.cast介绍

[英]Casting an object without "unchecked" compile-time warnings. Use only when absolutely necessary (e.g. when using clone()).
[中]在没有“未选中”编译时警告的情况下强制转换对象。仅在绝对必要时使用(例如,在使用clone()时)。

代码示例

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Adds an attribute value. Creates a fresh list of attribute values before
 * adding it.
 * 
 * @param value the attribute value
 */
final void addValue(String value) {
 ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
 ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.clone());
 forceAddValue(value);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Adds an attribute value. Creates a fresh list of attribute values before
 * adding it.
 * 
 * @param value the attribute value
 */
final void addValue(String value) {
 ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
 ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.clone());
 forceAddValue(value);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Produces a shallow copy of this vector.
 * 
 * @return the new vector
 */
@Override
public final FastVector<E> copy() {
 return Utils.cast(clone());
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Produces a shallow copy of this vector.
 * 
 * @return the new vector
 */
@Override
public final FastVector<E> copy() {
 return Utils.cast(clone());
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns an array containing all of the elements in this collection; the
 * runtime type of the returned array is that of the specified array.
 * 
 * @param a the array into which the elements of this collection are to be
 *          stored
 * @return an array containing the elements of this collection
 */
@Override
public <T> T[] toArray(T[] a) {
 T[] result;
 Iterator<T> iter;
 Vector<T> list;
 int i;
 list = new Vector<T>();
 iter = Utils.<Iterator<T>> cast(iterator());
 while (iter.hasNext()) {
  list.add(iter.next());
 }
 if (Array.getLength(a) != list.size()) {
  result = Utils.<T[]> cast(Array.newInstance(a.getClass()
   .getComponentType(), list.size()));
 } else {
  result = a;
 }
 for (i = 0; i < list.size(); i++) {
  result[i] = list.get(i);
 }
 return result;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Returns an array containing all of the elements in this collection; the
 * runtime type of the returned array is that of the specified array.
 * 
 * @param a the array into which the elements of this collection are to be
 *          stored
 * @return an array containing the elements of this collection
 */
@Override
public <T> T[] toArray(T[] a) {
 T[] result;
 Iterator<T> iter;
 Vector<T> list;
 int i;
 list = new Vector<T>();
 iter = Utils.<Iterator<T>> cast(iterator());
 while (iter.hasNext()) {
  list.add(iter.next());
 }
 if (Array.getLength(a) != list.size()) {
  result = Utils.<T[]> cast(Array.newInstance(a.getClass()
   .getComponentType(), list.size()));
 } else {
  result = a;
 }
 for (i = 0; i < list.size(); i++) {
  result[i] = list.get(i);
 }
 return result;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

case STRING:
 ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
 ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.clone());
 Object store = string;
 if (string.length() > STRING_COMPRESS_THRESHOLD) {

代码示例来源:origin: Waikato/weka-trunk

case STRING:
 ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
 ((NominalAttributeInfo)m_AttributeInfo).m_Hashtable = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Hashtable.clone());
 Object store = string;
 if (string.length() > STRING_COMPRESS_THRESHOLD) {

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Sets a value of a relation-valued attribute. Creates a fresh list of
 * attribute values before it is set.
 * 
 * @param index the value's index
 * @param data the value
 * @throws IllegalArgumentException if the attribute is not relation-valued.
 */
final void setValue(int index, Instances data) {
 if (isRelationValued()) {
  if (!data.equalHeaders(((RelationalAttributeInfo)m_AttributeInfo).m_Header)) {
   throw new IllegalArgumentException("Can't set relational value. "
    + "Headers not compatible.\n" + data.equalHeadersMsg(((RelationalAttributeInfo)m_AttributeInfo).m_Header));
  }
  ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
   Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
  ((NominalAttributeInfo)m_AttributeInfo).m_Values.set(index, data);
 } else {
  throw new IllegalArgumentException("Can only set value for"
   + " relation-valued attributes!");
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

} else {
 ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
 ((NominalAttributeInfo)m_AttributeInfo).m_Values.remove(index);
 if (!isRelationValued()) {

代码示例来源:origin: Waikato/weka-trunk

/**
 * Sets a value of a relation-valued attribute. Creates a fresh list of
 * attribute values before it is set.
 * 
 * @param index the value's index
 * @param data the value
 * @throws IllegalArgumentException if the attribute is not relation-valued.
 */
final void setValue(int index, Instances data) {
 if (isRelationValued()) {
  if (!data.equalHeaders(((RelationalAttributeInfo)m_AttributeInfo).m_Header)) {
   throw new IllegalArgumentException("Can't set relational value. "
    + "Headers not compatible.\n" + data.equalHeadersMsg(((RelationalAttributeInfo)m_AttributeInfo).m_Header));
  }
  ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
   Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
  ((NominalAttributeInfo)m_AttributeInfo).m_Values.set(index, data);
 } else {
  throw new IllegalArgumentException("Can only set value for"
   + " relation-valued attributes!");
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

Utils.cast(Class.forName(node.getAttribute(ATT_CLASS)).newInstance());
coll.addAll(v);

代码示例来源:origin: Waikato/weka-trunk

Utils.cast(Class.forName(node.getAttribute(ATT_CLASS)).newInstance());
coll.addAll(v);

代码示例来源:origin: Waikato/weka-trunk

} else {
 ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
  Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
 ((NominalAttributeInfo)m_AttributeInfo).m_Values.remove(index);
 if (!isRelationValued()) {

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

map = Utils.cast(Class.forName(node.getAttribute(ATT_CLASS)).newInstance());
children = XMLDocument.getChildTags(node);

代码示例来源:origin: Waikato/weka-trunk

map = Utils.cast(Class.forName(node.getAttribute(ATT_CLASS)).newInstance());
children = XMLDocument.getChildTags(node);

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Clones the vector and shallow copies all its elements. The elements have to
 * implement the Copyable interface.
 * 
 * @return the new vector
 */
public final FastVector<E> copyElements() {
 FastVector<E> copy = copy();
 for (int i = 0; i < size(); i++) {
  copy.set(i, Utils.<E> cast(((Copyable) get(i)).copy()));
 }
 return copy;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Clones the vector and shallow copies all its elements. The elements have to
 * implement the Copyable interface.
 * 
 * @return the new vector
 */
public final FastVector<E> copyElements() {
 FastVector<E> copy = copy();
 for (int i = 0; i < size(); i++) {
  copy.set(i, Utils.<E> cast(((Copyable) get(i)).copy()));
 }
 return copy;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Create a copy of the structure. If the data has string or relational
 * attributes, theses are replaced by empty copies. Other attributes are left
 * unmodified, but the underlying list structure holding references to the attributes
 * is shallow-copied, so that other Instances objects with a reference to this list are not affected.
 * 
 * @return a copy of the instance structure.
 */
public Instances stringFreeStructure() {
 ArrayList<Attribute> newAtts = new ArrayList<Attribute>();
 for (Attribute att : m_Attributes) {
  if (att.type() == Attribute.STRING) {
   newAtts.add(new Attribute(att.name(), (List<String>) null, att.index()));
  } else if (att.type() == Attribute.RELATIONAL) {
   newAtts.add(new Attribute(att.name(), new Instances(att.relation(), 0),
    att.index()));
  }
 }
 if (newAtts.size() == 0) {
  return new Instances(this, 0);
 }
 ArrayList<Attribute> atts = Utils.cast(m_Attributes.clone());
 for (Attribute att : newAtts) {
  atts.set(att.index(), att);
 }
 Instances result = new Instances(this, 0);
 result.m_Attributes = atts;
 return result;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Create a copy of the structure. If the data has string or relational
 * attributes, theses are replaced by empty copies. Other attributes are left
 * unmodified, but the underlying list structure holding references to the attributes
 * is shallow-copied, so that other Instances objects with a reference to this list are not affected.
 * 
 * @return a copy of the instance structure.
 */
public Instances stringFreeStructure() {
 ArrayList<Attribute> newAtts = new ArrayList<Attribute>();
 for (Attribute att : m_Attributes) {
  if (att.type() == Attribute.STRING) {
   newAtts.add(new Attribute(att.name(), (List<String>) null, att.index()));
  } else if (att.type() == Attribute.RELATIONAL) {
   newAtts.add(new Attribute(att.name(), new Instances(att.relation(), 0),
    att.index()));
  }
 }
 if (newAtts.size() == 0) {
  return new Instances(this, 0);
 }
 ArrayList<Attribute> atts = Utils.cast(m_Attributes.clone());
 for (Attribute att : newAtts) {
  atts.set(att.index(), att);
 }
 Instances result = new Instances(this, 0);
 result.m_Attributes = atts;
 return result;
}

相关文章