org.intermine.metadata.Util.getFriendlyName()方法的使用及代码示例

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

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

Util.getFriendlyName介绍

[英]Creates a friendly name for a given class.
[中]为给定类创建友好名称。

代码示例

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Creates a friendly description of an object - that is, the class and the ID (if it has one).
  3. *
  4. * @param o the object to be described
  5. * @return a String description
  6. */
  7. public static String getFriendlyDesc(Object o) {
  8. if (o instanceof InterMineObject) {
  9. return Util.getFriendlyName(o.getClass()) + ":" + ((InterMineObject) o).getId();
  10. } else {
  11. return o.toString();
  12. }
  13. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Creates a friendly description of an object - that is, the class and the ID (if it has one).
  3. *
  4. * @param o the object to be described
  5. * @return a String description
  6. */
  7. public static String getFriendlyDesc(Object o) {
  8. if (o instanceof InterMineObject) {
  9. return Util.getFriendlyName(o.getClass()) + ":" + ((InterMineObject) o).getId();
  10. } else {
  11. return o.toString();
  12. }
  13. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Returns the result of decomposeClass if that is a single class, or throws an exception if
  3. * there are more than one.
  4. *
  5. * @param clazz the class
  6. * @return the corresponding non-dynamic class
  7. */
  8. @SuppressWarnings("unchecked")
  9. public static Class<? extends FastPathObject> getSimpleClass(
  10. Class<? extends FastPathObject> clazz) {
  11. Set<Class<?>> decomposed = Util.decomposeClass(clazz);
  12. if (decomposed.size() > 1) {
  13. throw new IllegalArgumentException("No simple class for "
  14. + Util.getFriendlyName(clazz));
  15. }
  16. return (Class) decomposed.iterator().next();
  17. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Returns the result of decomposeClass if that is a single class, or throws an exception if
  3. * there are more than one.
  4. *
  5. * @param clazz the class
  6. * @return the corresponding non-dynamic class
  7. */
  8. @SuppressWarnings("unchecked")
  9. public static Class<? extends FastPathObject> getSimpleClass(
  10. Class<? extends FastPathObject> clazz) {
  11. Set<Class<?>> decomposed = Util.decomposeClass(clazz);
  12. if (decomposed.size() > 1) {
  13. throw new IllegalArgumentException("No simple class for "
  14. + Util.getFriendlyName(clazz));
  15. }
  16. return (Class) decomposed.iterator().next();
  17. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Returns the simple class name for the given class or throws an exception if
  3. * there are more than one.
  4. * @param clazz the class
  5. * @return the simple class name
  6. */
  7. public static synchronized String getSimpleClassName(Class<?> clazz) {
  8. String retval = simpleNameMap.get(clazz);
  9. if (retval == null) {
  10. Set<Class<?>> decomposedClass = Util.decomposeClass(clazz);
  11. if (decomposedClass.size() > 1) {
  12. throw new IllegalArgumentException("No simple name for class: "
  13. + Util.getFriendlyName(clazz));
  14. } else {
  15. retval = decomposedClass.iterator().next().getName();
  16. simpleNameMap.put(clazz, retval);
  17. }
  18. }
  19. return retval;
  20. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Returns the simple class name for the given class or throws an exception if
  3. * there are more than one.
  4. * @param clazz the class
  5. * @return the simple class name
  6. */
  7. public static synchronized String getSimpleClassName(Class<?> clazz) {
  8. String retval = simpleNameMap.get(clazz);
  9. if (retval == null) {
  10. Set<Class<?>> decomposedClass = Util.decomposeClass(clazz);
  11. if (decomposedClass.size() > 1) {
  12. throw new IllegalArgumentException("No simple name for class: "
  13. + Util.getFriendlyName(clazz));
  14. } else {
  15. retval = decomposedClass.iterator().next().getName();
  16. simpleNameMap.put(clazz, retval);
  17. }
  18. }
  19. return retval;
  20. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag.
  3. *
  4. * @param types the Set of classes
  5. * @param osb the ObjectStoreBag
  6. */
  7. public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) {
  8. Class<?> clazz;
  9. if (types.size() == 1) {
  10. clazz = types.iterator().next();
  11. } else {
  12. clazz = DynamicUtil.composeClass(types);
  13. }
  14. if (!InterMineObject.class.isAssignableFrom(clazz)) {
  15. throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
  16. + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
  17. clazz));
  18. }
  19. @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  20. this.type = thisType;
  21. this.osb = osb;
  22. this.ids = null;
  23. this.bag = null;
  24. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag.
  3. *
  4. * @param types the Set of classes
  5. * @param osb the ObjectStoreBag
  6. */
  7. public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) {
  8. Class<?> clazz;
  9. if (types.size() == 1) {
  10. clazz = types.iterator().next();
  11. } else {
  12. clazz = DynamicUtil.composeClass(types);
  13. }
  14. if (!InterMineObject.class.isAssignableFrom(clazz)) {
  15. throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
  16. + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
  17. clazz));
  18. }
  19. @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  20. this.type = thisType;
  21. this.osb = osb;
  22. this.ids = null;
  23. this.bag = null;
  24. }

代码示例来源:origin: org.intermine/intermine-model

  1. /**
  2. * Adds an element to a public or protected collection of an Object given the field name.
  3. *
  4. * @param o the Object
  5. * @param fieldName the name of the relevant collection
  6. * @param element the element to add to the collection
  7. */
  8. public static void addCollectionElement(Object o, String fieldName, Object element) {
  9. try {
  10. getAdder(o.getClass(), fieldName).invoke(o, element);
  11. } catch (Exception e) {
  12. String type = null;
  13. try {
  14. type = getFieldInfo(o.getClass(), fieldName).getElementType().getName();
  15. } catch (Exception e3) {
  16. IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
  17. + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
  18. + fieldName + "\"" + " - not an accessible collection");
  19. e2.initCause(e);
  20. throw e2;
  21. }
  22. IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
  23. + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
  24. + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a "
  25. + element.getClass().getName() + ")");
  26. e2.initCause(e);
  27. throw e2;
  28. }
  29. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Adds an element to a public or protected collection of an Object given the field name.
  3. *
  4. * @param o the Object
  5. * @param fieldName the name of the relevant collection
  6. * @param element the element to add to the collection
  7. */
  8. public static void addCollectionElement(Object o, String fieldName, Object element) {
  9. try {
  10. getAdder(o.getClass(), fieldName).invoke(o, element);
  11. } catch (Exception e) {
  12. String type = null;
  13. try {
  14. type = getFieldInfo(o.getClass(), fieldName).getElementType().getName();
  15. } catch (Exception e3) {
  16. IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
  17. + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
  18. + fieldName + "\"" + " - not an accessible collection");
  19. e2.initCause(e);
  20. throw e2;
  21. }
  22. IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
  23. + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
  24. + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a "
  25. + element.getClass().getName() + ")");
  26. e2.initCause(e);
  27. throw e2;
  28. }
  29. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Constructs a QueryClass representing the specified set of classes and bag of objects.
  3. *
  4. * @param types the Set of classes
  5. * @param bag the Collection of objects
  6. */
  7. public QueryClassBag(Set<Class<?>> types, Collection<?> bag) {
  8. Class<?> clazz;
  9. if (types.size() == 1) {
  10. clazz = types.iterator().next();
  11. } else {
  12. clazz = DynamicUtil.composeClass(types);
  13. }
  14. if (!InterMineObject.class.isAssignableFrom(clazz)) {
  15. throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
  16. + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
  17. clazz));
  18. }
  19. @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  20. this.type = thisType;
  21. this.bag = bag;
  22. ids = convertToIds(bag, this.type);
  23. this.osb = null;
  24. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Constructs a QueryClass representing the specified set of classes and bag of objects.
  3. *
  4. * @param types the Set of classes
  5. * @param bag the Collection of objects
  6. */
  7. public QueryClassBag(Set<Class<?>> types, Collection<?> bag) {
  8. Class<?> clazz;
  9. if (types.size() == 1) {
  10. clazz = types.iterator().next();
  11. } else {
  12. clazz = DynamicUtil.composeClass(types);
  13. }
  14. if (!InterMineObject.class.isAssignableFrom(clazz)) {
  15. throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
  16. + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
  17. clazz));
  18. }
  19. @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  20. this.type = thisType;
  21. this.bag = bag;
  22. ids = convertToIds(bag, this.type);
  23. this.osb = null;
  24. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public InterMineObject internalGetObjectById(Integer id,
  6. Class<? extends InterMineObject> clazz) throws ObjectStoreException {
  7. InterMineObject retval = super.internalGetObjectById(id, clazz);
  8. //Exception e = new Exception("internalGetObjectById called for "
  9. // + retval.getClass().toString() + " with id " + id);
  10. //e.fillInStackTrace();
  11. //java.io.StringWriter sw = new java.io.StringWriter();
  12. //java.io.PrintWriter pw = new java.io.PrintWriter(sw);
  13. //e.printStackTrace(pw);
  14. //pw.flush();
  15. //LOG.error(sw.toString());
  16. synchronized (cache) {
  17. Exception e = new Exception();
  18. e.fillInStackTrace();
  19. LOG.warn("Probable inefficiency: internalGetObjectById called "
  20. + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval
  21. .getClass())) + " with id " + id + ", clazz " + clazz.toString()
  22. + ", cache size = " + cache.size() + " - maybe you should use"
  23. + " ObjectStoreFastCollectionsForTranslatorImpl", e);
  24. }
  25. internalGetObjectByIdCount++;
  26. if (internalGetObjectByIdCount % 1000 == 0) {
  27. LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times");
  28. }
  29. return retval;
  30. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public InterMineObject internalGetObjectById(Integer id,
  6. Class<? extends InterMineObject> clazz) throws ObjectStoreException {
  7. InterMineObject retval = super.internalGetObjectById(id, clazz);
  8. //Exception e = new Exception("internalGetObjectById called for "
  9. // + retval.getClass().toString() + " with id " + id);
  10. //e.fillInStackTrace();
  11. //java.io.StringWriter sw = new java.io.StringWriter();
  12. //java.io.PrintWriter pw = new java.io.PrintWriter(sw);
  13. //e.printStackTrace(pw);
  14. //pw.flush();
  15. //LOG.error(sw.toString());
  16. synchronized (cache) {
  17. Exception e = new Exception();
  18. e.fillInStackTrace();
  19. LOG.warn("Probable inefficiency: internalGetObjectById called "
  20. + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval
  21. .getClass())) + " with id " + id + ", clazz " + clazz.toString()
  22. + ", cache size = " + cache.size() + " - maybe you should use"
  23. + " ObjectStoreFastCollectionsForTranslatorImpl", e);
  24. }
  25. internalGetObjectByIdCount++;
  26. if (internalGetObjectByIdCount % 1000 == 0) {
  27. LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times");
  28. }
  29. return retval;
  30. }

代码示例来源:origin: org.intermine/intermine-model

  1. /**
  2. * Returns the element type of a collection given the field name.
  3. *
  4. * @param c the Class
  5. * @param fieldName the name of the relevant collection
  6. * @return the class of the field, or null if the field is not found
  7. * @throws IllegalArgumentException if the field is not a collection
  8. */
  9. public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) {
  10. FieldInfo info = getFieldInfo(c, fieldName);
  11. if (info != null) {
  12. try {
  13. return info.getElementType();
  14. } catch (NullPointerException e) {
  15. IllegalArgumentException e2 = new IllegalArgumentException("Field "
  16. + Util.getFriendlyName(c) + "." + fieldName
  17. + " is not a collection");
  18. e2.initCause(e);
  19. throw e2;
  20. }
  21. }
  22. return null;
  23. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Returns the element type of a collection given the field name.
  3. *
  4. * @param c the Class
  5. * @param fieldName the name of the relevant collection
  6. * @return the class of the field, or null if the field is not found
  7. * @throws IllegalArgumentException if the field is not a collection
  8. */
  9. public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) {
  10. FieldInfo info = getFieldInfo(c, fieldName);
  11. if (info != null) {
  12. try {
  13. return info.getElementType();
  14. } catch (NullPointerException e) {
  15. IllegalArgumentException e2 = new IllegalArgumentException("Field "
  16. + Util.getFriendlyName(c) + "." + fieldName
  17. + " is not a collection");
  18. e2.initCause(e);
  19. throw e2;
  20. }
  21. }
  22. return null;
  23. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\""
  2. + (type == null ? "" : " (a " + type + ")")
  3. + " to \"" + fieldValue + "\" (a " + fieldValue.getClass().getName() + ")");

代码示例来源:origin: intermine/intermine

  1. + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\""
  2. + (type == null ? "" : " (a " + type + ")")
  3. + " to \"" + fieldValue + "\" (a " + fieldValue.getClass().getName() + ")");

代码示例来源:origin: intermine/intermine

  1. throw new TemplatePopulatorException("The constraint of type " + path.getEndType()
  2. + " can't be set to object of type "
  3. + Util.getFriendlyName(obj.getClass())
  4. + " in template query " + template.getName() + ".");

代码示例来源:origin: org.intermine/intermine-api

  1. throw new TemplatePopulatorException("The constraint of type " + path.getEndType()
  2. + " can't be set to object of type "
  3. + Util.getFriendlyName(obj.getClass())
  4. + " in template query " + template.getName() + ".");

相关文章