PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/twitter_api_me-1.6/src/com/twitterapime/search/Query.java

https://bitbucket.org/gnorris1/twitter-me
Java | 79 lines | 30 code | 6 blank | 43 comment | 9 complexity | 0c17a3060a57354d1eb718d1c6319beb MD5 | raw file
  1. /*
  2. * Query.java
  3. * 16/08/2009
  4. * Twitter API Micro Edition
  5. * Copyright(c) Ernandes Mourao Junior (ernandes@gmail.com)
  6. * All rights reserved
  7. */
  8. package com.twitterapime.search;
  9. import java.io.UnsupportedEncodingException;
  10. /**
  11. * <p>
  12. * This class defines a structure of a query. A Query object represents a query
  13. * statement that is sent to Twitter Search API, so that it can return all the
  14. * tweets that match a criteria.
  15. * </p>
  16. *
  17. * @author Ernandes Mourao Junior (ernandes@gmail.com)
  18. * @version 1.2
  19. * @since 1.0
  20. * @see QueryComposer
  21. * @see SearchDevice
  22. */
  23. public final class Query {
  24. /**
  25. * <p>
  26. * Hold the string that represents a query.
  27. * </p>
  28. */
  29. private String query;
  30. /**
  31. * <p>
  32. * Create an instance of Query class.
  33. * </p>
  34. * @param query The string of query.
  35. * @throws InvalidQueryException If query is not a valid UTF-8 string.
  36. * @throws IllegalArgumentException If query is null.
  37. */
  38. public Query(String query) {
  39. if (query == null) {
  40. throw new IllegalArgumentException("Query must not be null.");
  41. }
  42. //
  43. try {
  44. this.query = new String(query.getBytes(), "UTF-8");
  45. } catch (UnsupportedEncodingException e) {
  46. throw new InvalidQueryException("Invalid UTF-8 string: " + query);
  47. }
  48. }
  49. /**
  50. * @see java.lang.Object#equals(java.lang.Object)
  51. */
  52. public boolean equals(Object o) {
  53. if (o == this) {
  54. return true;
  55. } else if (o == null || !(o instanceof Query)) {
  56. return false;
  57. } else {
  58. return query.equals(((Query)o).query);
  59. }
  60. }
  61. /**
  62. * @see java.lang.Object#hashCode()
  63. */
  64. public int hashCode() {
  65. return query.hashCode();
  66. }
  67. /**
  68. * @see java.lang.Object#toString()
  69. */
  70. public String toString() {
  71. return query;
  72. }
  73. }