You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DebugId.java 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.util;
  5. import java.io.Serializable;
  6. import java.util.HashMap;
  7. import com.vaadin.ui.Component;
  8. public class DebugId implements Serializable {
  9. private static HashMap debugIds = new HashMap();
  10. /**
  11. * Generate static debug id based on package and component type. If
  12. * duplicate package, component type then number of instances count is
  13. * appended to debugId.
  14. *
  15. * @param c
  16. */
  17. public static void set(Component c, String description) {
  18. String debugId = "";
  19. // add package name
  20. StackTraceElement[] st = new Throwable().fillInStackTrace()
  21. .getStackTrace();
  22. try {
  23. debugId += st[3].getClassName();
  24. } catch (Exception e) {
  25. e.printStackTrace();
  26. }
  27. // add component type
  28. debugId += c.getClass();
  29. // add given description
  30. debugId += description;
  31. if (debugIds.containsKey(debugId)) {
  32. int count = ((Integer) debugIds.get(debugId)).intValue();
  33. count++;
  34. debugIds.put(debugId, new Integer(count));
  35. debugId = debugId + "-" + count;
  36. }
  37. c.setDebugId(debugId);
  38. }
  39. }