Skip to content

Commit

Permalink
Added utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Su committed Sep 30, 2010
1 parent 4ce93da commit 97fc5e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/com/todoroo/andlib/sql/Functions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.todoroo.andlib.sql;



@SuppressWarnings("nls")
public final class Functions {

Expand All @@ -25,4 +26,9 @@ public static Field now() {
return new Field("(strftime('%s','now')*1000)");
}

public static Field cast(Field field, String newType) {
return new Field("CAST(" + field.toString() + " AS " +
newType + ")");
}

}
17 changes: 16 additions & 1 deletion src/com/todoroo/andlib/utility/AndroidUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.URLConnection;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;

import android.app.Activity;
Expand All @@ -27,8 +28,8 @@
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.TextView;

import com.todoroo.andlib.service.ExceptionService;
Expand Down Expand Up @@ -360,6 +361,20 @@ public int compare(File o1, File o2) {
});
}

/**
* Search for the given value in the map, returning key if found
* @param map
* @param value
* @return null if not found, otherwise key
*/
public static <KEY, VALUE> KEY findKeyInMap(Map<KEY, VALUE> map, VALUE value){
for (Entry<KEY, VALUE> entry: map.entrySet()) {
if(entry.getValue().equals(value))
return entry.getKey();
}
return null;
}

/**
* Sleep, ignoring interruption. Before using this method, think carefully
* about why you are ignoring interruptions.
Expand Down

0 comments on commit 97fc5e8

Please sign in to comment.