Android Open Source - sloop Util






From Project

Back to project page sloop.

License

The source code is released under:

NON-LICENSE The Sloop data-browser source code is hereby released into the Public Domain. The original author, David Megginson, Megginson Technologies Ltd., and Acclar Open Ltd. provide no warranty:...

If you think the Android project sloop listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.megginson.sloop.model;
/*  w  w w.j a v  a  2 s  . co m*/
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Android-independent static utility methods.
 */
public class Util {

  /**
   * Null-safe hash code calculation.
   * 
   * This is a convenience method to calculate the hash code of an object. If
   * the parameter is null, the method will return a hash code of 0 rather
   * than throwing a {@link NullPointerException}.
   * 
   * This method is useful for implementing the {@link Object#hashCode()}
   * method in a class across a series of embedded objects that might have
   * null values.
   * 
   * @param o
   *            the object from which to obtain a hash code (may be null).
   * @return the object's hash code, or 0 if the argument is null.
   */
  public static int hashCode(Object o) {
    if (o == null) {
      return 0;
    } else {
      return o.hashCode();
    }
  }

  /**
   * Null-safe equality test.
   * 
   * This is a convenience method to test whether two objects are equal.
   * Either may be null, without triggering a {@link NullPointerException}; if
   * both are null, this method will consider them equal.
   * 
   * @param o1
   *            the first object to test for equality (may be null).
   * @param o2
   *            the second object to test for equality (may be null).
   * @return true if the two objects are equal, or if both are null.
   */
  public static boolean equals(Object o1, Object o2) {
    if (o1 == null && o2 == null) {
      return true;
    } else if (o1 == null || o2 == null) {
      return false;
    } else {
      return o1.equals(o2);
    }
  }

  /**
   * Test whether a string is a properly-formed URL.
   * 
   * Sloop uses this method to make URLs into links.
   * 
   * @param s
   *            the string to test.
   * @return true if the string is a URL.
   */
  public static boolean isUrl(String s) {
    try {
      // let Java do the work
      new URL(s);
      return true;
    } catch (MalformedURLException e) {
      return false;
    }
  }

}




Java Source Code List

com.megginson.sloop.activities.ActivitiesUtil.java
com.megginson.sloop.activities.AddressActionProvider.java
com.megginson.sloop.activities.BookmarkEditActivity.java
com.megginson.sloop.activities.BookmarkListActivity.java
com.megginson.sloop.activities.InfoBarFragment.java
com.megginson.sloop.activities.MainActivity.java
com.megginson.sloop.activities.MainDisplayFragment.java
com.megginson.sloop.activities.TextFilterFragment.java
com.megginson.sloop.activities.package-info.java
com.megginson.sloop.model.Bookmark.java
com.megginson.sloop.model.DataCollection.java
com.megginson.sloop.model.DataEntry.java
com.megginson.sloop.model.DataRecord.java
com.megginson.sloop.model.Util.java
com.megginson.sloop.model.ValueFilter.java
com.megginson.sloop.model.impl.ContainsStringFilter.java
com.megginson.sloop.model.impl.DataCollectionIO.java
com.megginson.sloop.model.impl.DataCollectionImpl.java
com.megginson.sloop.model.impl.DataEntryImpl.java
com.megginson.sloop.model.impl.DataRecordImpl.java
com.megginson.sloop.model.impl.EqualsStringFilter.java
com.megginson.sloop.model.impl.package-info.java
com.megginson.sloop.model.package-info.java
com.megginson.sloop.ui.BookmarkListAdapter.java
com.megginson.sloop.ui.DataCollectionLoader.java
com.megginson.sloop.ui.DataCollectionPagerAdapter.java
com.megginson.sloop.ui.DataCollectionResult.java
com.megginson.sloop.ui.DataRecordFragment.java
com.megginson.sloop.ui.DataRecordListAdapter.java
com.megginson.sloop.ui.package-info.java