repo_name
stringlengths 7
104
| file_path
stringlengths 13
198
| context
stringlengths 67
7.15k
| import_statement
stringlengths 16
4.43k
| code
stringlengths 40
6.98k
| prompt
stringlengths 227
8.27k
| next_line
stringlengths 8
795
|
---|---|---|---|---|---|---|
android-jian/topnews
|
app/src/main/java/com/topnews/android/adapter/IconAdapter.java
|
// Path: app/src/main/java/com/topnews/android/gson/IconBean.java
// public class IconBean {
//
// private String iconUri;
//
// private String iconDes;
//
// public String getIconDes() {
// return iconDes;
// }
//
// public void setIconDes(String iconDes) {
// this.iconDes = iconDes;
// }
//
// public String getIconUri() {
// return iconUri;
// }
//
// public void setIconUri(String iconUri) {
// this.iconUri = iconUri;
// }
//
// }
|
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.topnews.android.R;
import com.topnews.android.gson.IconBean;
import java.util.List;
|
package com.topnews.android.adapter;
/**
* Created by dell on 2017/3/5.
*/
public class IconAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final int PULLUP_LOAD_MORE=0; //上拉加载更多
public static final int LOADING_MORE=1; //玩命加载中
public static final int LOAD_MORE_FAIL=2; //加载失败
public static final int LOAD_MORE_NONE=3; //没有更多数据了
private int load_more_status=PULLUP_LOAD_MORE; //默认状态为上拉加载更多
private static final int TYPE_ITEM = 0; //普通Item View
private static final int TYPE_FOOTER = 1; //底部FootView
|
// Path: app/src/main/java/com/topnews/android/gson/IconBean.java
// public class IconBean {
//
// private String iconUri;
//
// private String iconDes;
//
// public String getIconDes() {
// return iconDes;
// }
//
// public void setIconDes(String iconDes) {
// this.iconDes = iconDes;
// }
//
// public String getIconUri() {
// return iconUri;
// }
//
// public void setIconUri(String iconUri) {
// this.iconUri = iconUri;
// }
//
// }
// Path: app/src/main/java/com/topnews/android/adapter/IconAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.topnews.android.R;
import com.topnews.android.gson.IconBean;
import java.util.List;
package com.topnews.android.adapter;
/**
* Created by dell on 2017/3/5.
*/
public class IconAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public static final int PULLUP_LOAD_MORE=0; //上拉加载更多
public static final int LOADING_MORE=1; //玩命加载中
public static final int LOAD_MORE_FAIL=2; //加载失败
public static final int LOAD_MORE_NONE=3; //没有更多数据了
private int load_more_status=PULLUP_LOAD_MORE; //默认状态为上拉加载更多
private static final int TYPE_ITEM = 0; //普通Item View
private static final int TYPE_FOOTER = 1; //底部FootView
|
private List<IconBean> mDatas;
|
android-jian/topnews
|
magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/SimplePagerTitleView.java
|
// Path: magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/UIUtil.java
// public final class UIUtil {
//
// public static int dip2px(Context context, double dpValue) {
// float density = context.getResources().getDisplayMetrics().density;
// return (int) (dpValue * density + 0.5);
// }
//
// public static int getScreenWidth(Context context) {
// return context.getResources().getDisplayMetrics().widthPixels;
// }
// }
//
// Path: magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/abs/IMeasurablePagerTitleView.java
// public interface IMeasurablePagerTitleView extends IPagerTitleView {
// int getContentLeft();
//
// int getContentTop();
//
// int getContentRight();
//
// int getContentBottom();
// }
|
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.TextView;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView;
|
package net.lucode.hackware.magicindicator.buildins.commonnavigator.titles;
/**
* 带文本的指示器标题
* 博客: http://hackware.lucode.net
* Created by hackware on 2016/6/26.
*/
public class SimplePagerTitleView extends TextView implements IMeasurablePagerTitleView {
protected int mSelectedColor;
protected int mNormalColor;
public SimplePagerTitleView(Context context) {
super(context, null);
init(context);
}
private void init(Context context) {
setGravity(Gravity.CENTER);
|
// Path: magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/UIUtil.java
// public final class UIUtil {
//
// public static int dip2px(Context context, double dpValue) {
// float density = context.getResources().getDisplayMetrics().density;
// return (int) (dpValue * density + 0.5);
// }
//
// public static int getScreenWidth(Context context) {
// return context.getResources().getDisplayMetrics().widthPixels;
// }
// }
//
// Path: magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/abs/IMeasurablePagerTitleView.java
// public interface IMeasurablePagerTitleView extends IPagerTitleView {
// int getContentLeft();
//
// int getContentTop();
//
// int getContentRight();
//
// int getContentBottom();
// }
// Path: magicindicator/src/main/java/net/lucode/hackware/magicindicator/buildins/commonnavigator/titles/SimplePagerTitleView.java
import android.content.Context;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextUtils;
import android.view.Gravity;
import android.widget.TextView;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView;
package net.lucode.hackware.magicindicator.buildins.commonnavigator.titles;
/**
* 带文本的指示器标题
* 博客: http://hackware.lucode.net
* Created by hackware on 2016/6/26.
*/
public class SimplePagerTitleView extends TextView implements IMeasurablePagerTitleView {
protected int mSelectedColor;
protected int mNormalColor;
public SimplePagerTitleView(Context context) {
super(context, null);
init(context);
}
private void init(Context context) {
setGravity(Gravity.CENTER);
|
int padding = UIUtil.dip2px(context, 10);
|
android-jian/topnews
|
app/src/main/java/com/topnews/android/fragment/SportFragment.java
|
// Path: app/src/main/java/com/topnews/android/view/LoadingPage.java
// public abstract class LoadingPage extends FrameLayout {
//
// private static final int PAGE_LOAD_UNDO=1;
// private static final int PAGE_LOAD_LOADING=2;
// private static final int PAGE_LOAD_NONE=3;
// private static final int PAGE_LOAD_FAIL=4;
// private static final int PAGE_LOAD_SUCCESS=5;
//
// private int currentState=PAGE_LOAD_UNDO; //当前状态
//
// private View pageLoading;
// private View pageError;
// private View pageEmpty;
// private View pageSuccess;
//
// public LoadingPage(Context context) {
// super(context);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int currentState) {
// super(context, attrs, defStyleAttr, defStyleRes);
//
// initView();
// }
//
// /**
// * 初始化布局
// * @return
// */
// public void initView(){
//
// if(pageLoading==null){ //初始化加载中的布局
// pageLoading = View.inflate(UIUtils.getContext(), R.layout.page_loading,null);
// addView(pageLoading);
// }
//
// if(pageError==null){ //初始化页面加载失败的布局
// pageError = View.inflate(UIUtils.getContext(), R.layout.page_error,null);
//
// Button btn_error= (Button) pageError.findViewById(R.id.btn_error);
// btn_error.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// onLoad();
// }
// });
//
// addView(pageError);
// }
//
// if (pageEmpty==null){ //初始化加载数据为空的布局
// pageEmpty=View.inflate(UIUtils.getContext(),R.layout.page_empty,null);
// addView(pageEmpty);
// }
//
// showRightPage();
//
// }
//
// /**
// * 根据当前状态决定显示哪个布局
// */
// public void showRightPage(){
//
// pageLoading.setVisibility((currentState==PAGE_LOAD_UNDO || currentState==PAGE_LOAD_LOADING)?View.VISIBLE:View.GONE);
//
// pageEmpty.setVisibility((currentState==PAGE_LOAD_NONE)?View.VISIBLE:View.GONE);
//
// pageError.setVisibility((currentState==PAGE_LOAD_FAIL)?View.VISIBLE:View.GONE);
//
// if (pageSuccess==null && currentState==PAGE_LOAD_SUCCESS){ //初始化加载数据成功的布局
// pageSuccess=onCreateSuccessView();
//
// if (pageSuccess!=null){
// addView(pageSuccess);
// }
// }
//
// if (pageSuccess!=null){
// pageSuccess.setVisibility((currentState==PAGE_LOAD_SUCCESS)?View.VISIBLE:View.GONE);
// }
// }
//
// /**
// * 数据加载
// */
// public void onLoad(){
//
// if (currentState!=PAGE_LOAD_LOADING){ //如果当前没有正在加载数据,就开始加载数据
// currentState=PAGE_LOAD_LOADING;
// new Thread(){
//
// @Override
// public void run() {
// final ResultState mState=dataLoad();
//
// UIUtils.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (mState!=null){
// currentState=mState.getState();
// showRightPage();
// }
// }
// });
// }
// }.start();
// }
// }
//
// /**
// * 初始化加载数据成功的布局
// * @return
// */
// public abstract View onCreateSuccessView();
//
// /**
// * 数据加载 返回值表示请求网络结束后的状态
// * @return
// */
// public abstract ResultState dataLoad();
//
// public enum ResultState{
//
// STATE_SUCCESS(PAGE_LOAD_SUCCESS),STATE_ERROR(PAGE_LOAD_FAIL),STATE_EMPTY(PAGE_LOAD_NONE);
//
// private int state;
// private ResultState(int state){
// this.state=state;
// }
//
// public int getState(){
// return this.state;
// }
// }
//
// }
|
import android.view.View;
import com.topnews.android.view.LoadingPage;
|
package com.topnews.android.fragment;
/**
* Created by dell on 2017/2/25.
*/
public class SportFragment extends BaseFragment {
@Override
public View onCreateSuccessView() {
return null;
}
@Override
|
// Path: app/src/main/java/com/topnews/android/view/LoadingPage.java
// public abstract class LoadingPage extends FrameLayout {
//
// private static final int PAGE_LOAD_UNDO=1;
// private static final int PAGE_LOAD_LOADING=2;
// private static final int PAGE_LOAD_NONE=3;
// private static final int PAGE_LOAD_FAIL=4;
// private static final int PAGE_LOAD_SUCCESS=5;
//
// private int currentState=PAGE_LOAD_UNDO; //当前状态
//
// private View pageLoading;
// private View pageError;
// private View pageEmpty;
// private View pageSuccess;
//
// public LoadingPage(Context context) {
// super(context);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int currentState) {
// super(context, attrs, defStyleAttr, defStyleRes);
//
// initView();
// }
//
// /**
// * 初始化布局
// * @return
// */
// public void initView(){
//
// if(pageLoading==null){ //初始化加载中的布局
// pageLoading = View.inflate(UIUtils.getContext(), R.layout.page_loading,null);
// addView(pageLoading);
// }
//
// if(pageError==null){ //初始化页面加载失败的布局
// pageError = View.inflate(UIUtils.getContext(), R.layout.page_error,null);
//
// Button btn_error= (Button) pageError.findViewById(R.id.btn_error);
// btn_error.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// onLoad();
// }
// });
//
// addView(pageError);
// }
//
// if (pageEmpty==null){ //初始化加载数据为空的布局
// pageEmpty=View.inflate(UIUtils.getContext(),R.layout.page_empty,null);
// addView(pageEmpty);
// }
//
// showRightPage();
//
// }
//
// /**
// * 根据当前状态决定显示哪个布局
// */
// public void showRightPage(){
//
// pageLoading.setVisibility((currentState==PAGE_LOAD_UNDO || currentState==PAGE_LOAD_LOADING)?View.VISIBLE:View.GONE);
//
// pageEmpty.setVisibility((currentState==PAGE_LOAD_NONE)?View.VISIBLE:View.GONE);
//
// pageError.setVisibility((currentState==PAGE_LOAD_FAIL)?View.VISIBLE:View.GONE);
//
// if (pageSuccess==null && currentState==PAGE_LOAD_SUCCESS){ //初始化加载数据成功的布局
// pageSuccess=onCreateSuccessView();
//
// if (pageSuccess!=null){
// addView(pageSuccess);
// }
// }
//
// if (pageSuccess!=null){
// pageSuccess.setVisibility((currentState==PAGE_LOAD_SUCCESS)?View.VISIBLE:View.GONE);
// }
// }
//
// /**
// * 数据加载
// */
// public void onLoad(){
//
// if (currentState!=PAGE_LOAD_LOADING){ //如果当前没有正在加载数据,就开始加载数据
// currentState=PAGE_LOAD_LOADING;
// new Thread(){
//
// @Override
// public void run() {
// final ResultState mState=dataLoad();
//
// UIUtils.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (mState!=null){
// currentState=mState.getState();
// showRightPage();
// }
// }
// });
// }
// }.start();
// }
// }
//
// /**
// * 初始化加载数据成功的布局
// * @return
// */
// public abstract View onCreateSuccessView();
//
// /**
// * 数据加载 返回值表示请求网络结束后的状态
// * @return
// */
// public abstract ResultState dataLoad();
//
// public enum ResultState{
//
// STATE_SUCCESS(PAGE_LOAD_SUCCESS),STATE_ERROR(PAGE_LOAD_FAIL),STATE_EMPTY(PAGE_LOAD_NONE);
//
// private int state;
// private ResultState(int state){
// this.state=state;
// }
//
// public int getState(){
// return this.state;
// }
// }
//
// }
// Path: app/src/main/java/com/topnews/android/fragment/SportFragment.java
import android.view.View;
import com.topnews.android.view.LoadingPage;
package com.topnews.android.fragment;
/**
* Created by dell on 2017/2/25.
*/
public class SportFragment extends BaseFragment {
@Override
public View onCreateSuccessView() {
return null;
}
@Override
|
public LoadingPage.ResultState dataLoad() {
|
android-jian/topnews
|
app/src/main/java/com/topnews/android/protocol/BaseProtocol.java
|
// Path: app/src/main/java/com/topnews/android/utils/IOUtils.java
// public class IOUtils {
// /** 关闭流 */
// public static boolean close(Closeable io) {
// if (io != null) {
// try {
// io.close();
// } catch (IOException e) {
// LogUtils.e(e);
// }
// }
// return true;
// }
// }
//
// Path: app/src/main/java/com/topnews/android/utils/UIUtils.java
// public class UIUtils {
//
// /**
// * 获取上下文对象
// * @return
// */
// public static Context getContext(){
//
// return BaseApplication.getmContext();
// }
//
// /**
// * 获取主线程id
// * @return
// */
// public static int getMainThreadId(){
// return BaseApplication.getMainThreadId();
// }
//
// /**
// * 获取handler实例
// * @return
// */
// public static Handler getHandler(){
// return BaseApplication.getmHandler();
// }
//
// /**
// * 判断当前是否运行在主线程
// * @return
// */
// public static boolean isRunOnUiThread(){
// return getMainThreadId()==android.os.Process.myTid();
// }
//
// /**
// * 确保当前的操作运行在UI主线程
// * @param runnable
// */
// public static void runOnUiThread(Runnable runnable){
// if(isRunOnUiThread()){
// runOnUiThread(runnable);
// }else{
// getHandler().post(runnable);
// }
// }
//
// /**
// * 获取字符串数组
// * @param id
// * @return
// */
// public static String[] getStringArray(int id){
// return getContext().getResources().getStringArray(id);
// }
//
// /**
// * dp转px
// * @param dp
// * @return
// */
// public static int dip2px(int dp){
// int mDensity=(int) getContext().getResources().getDisplayMetrics().density;
// return dp*mDensity;
// }
//
// /**
// * px转dp
// * @param px
// * @return
// */
// public static float px2dip(int px){
// float mDensity=getContext().getResources().getDisplayMetrics().density;
// return px/mDensity;
// }
// }
|
import com.topnews.android.utils.IOUtils;
import com.topnews.android.utils.UIUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
|
try {
OkHttpClient client=new OkHttpClient();
Request request=new Request.Builder().url(url).build();
Response response=client.newCall(request).execute();
if (response!=null){
String mData=response.body().string();
if (!mData.isEmpty()){
//写入缓存
setCache(index,mData);
return mData;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 向本地文件缓存写入数据
*
* 以url为文件名,以json为文件内容,保存在本地
*/
public void setCache(int index,String result){
//获取系统缓存目录
|
// Path: app/src/main/java/com/topnews/android/utils/IOUtils.java
// public class IOUtils {
// /** 关闭流 */
// public static boolean close(Closeable io) {
// if (io != null) {
// try {
// io.close();
// } catch (IOException e) {
// LogUtils.e(e);
// }
// }
// return true;
// }
// }
//
// Path: app/src/main/java/com/topnews/android/utils/UIUtils.java
// public class UIUtils {
//
// /**
// * 获取上下文对象
// * @return
// */
// public static Context getContext(){
//
// return BaseApplication.getmContext();
// }
//
// /**
// * 获取主线程id
// * @return
// */
// public static int getMainThreadId(){
// return BaseApplication.getMainThreadId();
// }
//
// /**
// * 获取handler实例
// * @return
// */
// public static Handler getHandler(){
// return BaseApplication.getmHandler();
// }
//
// /**
// * 判断当前是否运行在主线程
// * @return
// */
// public static boolean isRunOnUiThread(){
// return getMainThreadId()==android.os.Process.myTid();
// }
//
// /**
// * 确保当前的操作运行在UI主线程
// * @param runnable
// */
// public static void runOnUiThread(Runnable runnable){
// if(isRunOnUiThread()){
// runOnUiThread(runnable);
// }else{
// getHandler().post(runnable);
// }
// }
//
// /**
// * 获取字符串数组
// * @param id
// * @return
// */
// public static String[] getStringArray(int id){
// return getContext().getResources().getStringArray(id);
// }
//
// /**
// * dp转px
// * @param dp
// * @return
// */
// public static int dip2px(int dp){
// int mDensity=(int) getContext().getResources().getDisplayMetrics().density;
// return dp*mDensity;
// }
//
// /**
// * px转dp
// * @param px
// * @return
// */
// public static float px2dip(int px){
// float mDensity=getContext().getResources().getDisplayMetrics().density;
// return px/mDensity;
// }
// }
// Path: app/src/main/java/com/topnews/android/protocol/BaseProtocol.java
import com.topnews.android.utils.IOUtils;
import com.topnews.android.utils.UIUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
try {
OkHttpClient client=new OkHttpClient();
Request request=new Request.Builder().url(url).build();
Response response=client.newCall(request).execute();
if (response!=null){
String mData=response.body().string();
if (!mData.isEmpty()){
//写入缓存
setCache(index,mData);
return mData;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 向本地文件缓存写入数据
*
* 以url为文件名,以json为文件内容,保存在本地
*/
public void setCache(int index,String result){
//获取系统缓存目录
|
File cacheDir=UIUtils.getContext().getCacheDir();
|
android-jian/topnews
|
app/src/main/java/com/topnews/android/protocol/BaseProtocol.java
|
// Path: app/src/main/java/com/topnews/android/utils/IOUtils.java
// public class IOUtils {
// /** 关闭流 */
// public static boolean close(Closeable io) {
// if (io != null) {
// try {
// io.close();
// } catch (IOException e) {
// LogUtils.e(e);
// }
// }
// return true;
// }
// }
//
// Path: app/src/main/java/com/topnews/android/utils/UIUtils.java
// public class UIUtils {
//
// /**
// * 获取上下文对象
// * @return
// */
// public static Context getContext(){
//
// return BaseApplication.getmContext();
// }
//
// /**
// * 获取主线程id
// * @return
// */
// public static int getMainThreadId(){
// return BaseApplication.getMainThreadId();
// }
//
// /**
// * 获取handler实例
// * @return
// */
// public static Handler getHandler(){
// return BaseApplication.getmHandler();
// }
//
// /**
// * 判断当前是否运行在主线程
// * @return
// */
// public static boolean isRunOnUiThread(){
// return getMainThreadId()==android.os.Process.myTid();
// }
//
// /**
// * 确保当前的操作运行在UI主线程
// * @param runnable
// */
// public static void runOnUiThread(Runnable runnable){
// if(isRunOnUiThread()){
// runOnUiThread(runnable);
// }else{
// getHandler().post(runnable);
// }
// }
//
// /**
// * 获取字符串数组
// * @param id
// * @return
// */
// public static String[] getStringArray(int id){
// return getContext().getResources().getStringArray(id);
// }
//
// /**
// * dp转px
// * @param dp
// * @return
// */
// public static int dip2px(int dp){
// int mDensity=(int) getContext().getResources().getDisplayMetrics().density;
// return dp*mDensity;
// }
//
// /**
// * px转dp
// * @param px
// * @return
// */
// public static float px2dip(int px){
// float mDensity=getContext().getResources().getDisplayMetrics().density;
// return px/mDensity;
// }
// }
|
import com.topnews.android.utils.IOUtils;
import com.topnews.android.utils.UIUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
|
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 向本地文件缓存写入数据
*
* 以url为文件名,以json为文件内容,保存在本地
*/
public void setCache(int index,String result){
//获取系统缓存目录
File cacheDir=UIUtils.getContext().getCacheDir();
File cacheFile=new File(cacheDir,"index=" + index);
FileWriter writer=null;
try {
writer=new FileWriter(cacheFile);
long deadTime=System.currentTimeMillis()+30*60*1000; //设置数据缓存时间
writer.write(deadTime+"\n"); //将数据缓存时间写在文件第一行
writer.write(result);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
|
// Path: app/src/main/java/com/topnews/android/utils/IOUtils.java
// public class IOUtils {
// /** 关闭流 */
// public static boolean close(Closeable io) {
// if (io != null) {
// try {
// io.close();
// } catch (IOException e) {
// LogUtils.e(e);
// }
// }
// return true;
// }
// }
//
// Path: app/src/main/java/com/topnews/android/utils/UIUtils.java
// public class UIUtils {
//
// /**
// * 获取上下文对象
// * @return
// */
// public static Context getContext(){
//
// return BaseApplication.getmContext();
// }
//
// /**
// * 获取主线程id
// * @return
// */
// public static int getMainThreadId(){
// return BaseApplication.getMainThreadId();
// }
//
// /**
// * 获取handler实例
// * @return
// */
// public static Handler getHandler(){
// return BaseApplication.getmHandler();
// }
//
// /**
// * 判断当前是否运行在主线程
// * @return
// */
// public static boolean isRunOnUiThread(){
// return getMainThreadId()==android.os.Process.myTid();
// }
//
// /**
// * 确保当前的操作运行在UI主线程
// * @param runnable
// */
// public static void runOnUiThread(Runnable runnable){
// if(isRunOnUiThread()){
// runOnUiThread(runnable);
// }else{
// getHandler().post(runnable);
// }
// }
//
// /**
// * 获取字符串数组
// * @param id
// * @return
// */
// public static String[] getStringArray(int id){
// return getContext().getResources().getStringArray(id);
// }
//
// /**
// * dp转px
// * @param dp
// * @return
// */
// public static int dip2px(int dp){
// int mDensity=(int) getContext().getResources().getDisplayMetrics().density;
// return dp*mDensity;
// }
//
// /**
// * px转dp
// * @param px
// * @return
// */
// public static float px2dip(int px){
// float mDensity=getContext().getResources().getDisplayMetrics().density;
// return px/mDensity;
// }
// }
// Path: app/src/main/java/com/topnews/android/protocol/BaseProtocol.java
import com.topnews.android.utils.IOUtils;
import com.topnews.android.utils.UIUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 向本地文件缓存写入数据
*
* 以url为文件名,以json为文件内容,保存在本地
*/
public void setCache(int index,String result){
//获取系统缓存目录
File cacheDir=UIUtils.getContext().getCacheDir();
File cacheFile=new File(cacheDir,"index=" + index);
FileWriter writer=null;
try {
writer=new FileWriter(cacheFile);
long deadTime=System.currentTimeMillis()+30*60*1000; //设置数据缓存时间
writer.write(deadTime+"\n"); //将数据缓存时间写在文件第一行
writer.write(result);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
|
IOUtils.close(writer);
|
android-jian/topnews
|
app/src/main/java/com/topnews/android/fragment/MoneyFragment.java
|
// Path: app/src/main/java/com/topnews/android/view/LoadingPage.java
// public abstract class LoadingPage extends FrameLayout {
//
// private static final int PAGE_LOAD_UNDO=1;
// private static final int PAGE_LOAD_LOADING=2;
// private static final int PAGE_LOAD_NONE=3;
// private static final int PAGE_LOAD_FAIL=4;
// private static final int PAGE_LOAD_SUCCESS=5;
//
// private int currentState=PAGE_LOAD_UNDO; //当前状态
//
// private View pageLoading;
// private View pageError;
// private View pageEmpty;
// private View pageSuccess;
//
// public LoadingPage(Context context) {
// super(context);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int currentState) {
// super(context, attrs, defStyleAttr, defStyleRes);
//
// initView();
// }
//
// /**
// * 初始化布局
// * @return
// */
// public void initView(){
//
// if(pageLoading==null){ //初始化加载中的布局
// pageLoading = View.inflate(UIUtils.getContext(), R.layout.page_loading,null);
// addView(pageLoading);
// }
//
// if(pageError==null){ //初始化页面加载失败的布局
// pageError = View.inflate(UIUtils.getContext(), R.layout.page_error,null);
//
// Button btn_error= (Button) pageError.findViewById(R.id.btn_error);
// btn_error.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// onLoad();
// }
// });
//
// addView(pageError);
// }
//
// if (pageEmpty==null){ //初始化加载数据为空的布局
// pageEmpty=View.inflate(UIUtils.getContext(),R.layout.page_empty,null);
// addView(pageEmpty);
// }
//
// showRightPage();
//
// }
//
// /**
// * 根据当前状态决定显示哪个布局
// */
// public void showRightPage(){
//
// pageLoading.setVisibility((currentState==PAGE_LOAD_UNDO || currentState==PAGE_LOAD_LOADING)?View.VISIBLE:View.GONE);
//
// pageEmpty.setVisibility((currentState==PAGE_LOAD_NONE)?View.VISIBLE:View.GONE);
//
// pageError.setVisibility((currentState==PAGE_LOAD_FAIL)?View.VISIBLE:View.GONE);
//
// if (pageSuccess==null && currentState==PAGE_LOAD_SUCCESS){ //初始化加载数据成功的布局
// pageSuccess=onCreateSuccessView();
//
// if (pageSuccess!=null){
// addView(pageSuccess);
// }
// }
//
// if (pageSuccess!=null){
// pageSuccess.setVisibility((currentState==PAGE_LOAD_SUCCESS)?View.VISIBLE:View.GONE);
// }
// }
//
// /**
// * 数据加载
// */
// public void onLoad(){
//
// if (currentState!=PAGE_LOAD_LOADING){ //如果当前没有正在加载数据,就开始加载数据
// currentState=PAGE_LOAD_LOADING;
// new Thread(){
//
// @Override
// public void run() {
// final ResultState mState=dataLoad();
//
// UIUtils.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (mState!=null){
// currentState=mState.getState();
// showRightPage();
// }
// }
// });
// }
// }.start();
// }
// }
//
// /**
// * 初始化加载数据成功的布局
// * @return
// */
// public abstract View onCreateSuccessView();
//
// /**
// * 数据加载 返回值表示请求网络结束后的状态
// * @return
// */
// public abstract ResultState dataLoad();
//
// public enum ResultState{
//
// STATE_SUCCESS(PAGE_LOAD_SUCCESS),STATE_ERROR(PAGE_LOAD_FAIL),STATE_EMPTY(PAGE_LOAD_NONE);
//
// private int state;
// private ResultState(int state){
// this.state=state;
// }
//
// public int getState(){
// return this.state;
// }
// }
//
// }
|
import android.view.View;
import com.topnews.android.view.LoadingPage;
|
package com.topnews.android.fragment;
/**
* Created by dell on 2017/2/25.
*/
public class MoneyFragment extends BaseFragment {
@Override
public View onCreateSuccessView() {
return null;
}
@Override
|
// Path: app/src/main/java/com/topnews/android/view/LoadingPage.java
// public abstract class LoadingPage extends FrameLayout {
//
// private static final int PAGE_LOAD_UNDO=1;
// private static final int PAGE_LOAD_LOADING=2;
// private static final int PAGE_LOAD_NONE=3;
// private static final int PAGE_LOAD_FAIL=4;
// private static final int PAGE_LOAD_SUCCESS=5;
//
// private int currentState=PAGE_LOAD_UNDO; //当前状态
//
// private View pageLoading;
// private View pageError;
// private View pageEmpty;
// private View pageSuccess;
//
// public LoadingPage(Context context) {
// super(context);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr) {
// super(context, attrs, defStyleAttr);
//
// initView();
// }
//
// public LoadingPage(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes, int currentState) {
// super(context, attrs, defStyleAttr, defStyleRes);
//
// initView();
// }
//
// /**
// * 初始化布局
// * @return
// */
// public void initView(){
//
// if(pageLoading==null){ //初始化加载中的布局
// pageLoading = View.inflate(UIUtils.getContext(), R.layout.page_loading,null);
// addView(pageLoading);
// }
//
// if(pageError==null){ //初始化页面加载失败的布局
// pageError = View.inflate(UIUtils.getContext(), R.layout.page_error,null);
//
// Button btn_error= (Button) pageError.findViewById(R.id.btn_error);
// btn_error.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// onLoad();
// }
// });
//
// addView(pageError);
// }
//
// if (pageEmpty==null){ //初始化加载数据为空的布局
// pageEmpty=View.inflate(UIUtils.getContext(),R.layout.page_empty,null);
// addView(pageEmpty);
// }
//
// showRightPage();
//
// }
//
// /**
// * 根据当前状态决定显示哪个布局
// */
// public void showRightPage(){
//
// pageLoading.setVisibility((currentState==PAGE_LOAD_UNDO || currentState==PAGE_LOAD_LOADING)?View.VISIBLE:View.GONE);
//
// pageEmpty.setVisibility((currentState==PAGE_LOAD_NONE)?View.VISIBLE:View.GONE);
//
// pageError.setVisibility((currentState==PAGE_LOAD_FAIL)?View.VISIBLE:View.GONE);
//
// if (pageSuccess==null && currentState==PAGE_LOAD_SUCCESS){ //初始化加载数据成功的布局
// pageSuccess=onCreateSuccessView();
//
// if (pageSuccess!=null){
// addView(pageSuccess);
// }
// }
//
// if (pageSuccess!=null){
// pageSuccess.setVisibility((currentState==PAGE_LOAD_SUCCESS)?View.VISIBLE:View.GONE);
// }
// }
//
// /**
// * 数据加载
// */
// public void onLoad(){
//
// if (currentState!=PAGE_LOAD_LOADING){ //如果当前没有正在加载数据,就开始加载数据
// currentState=PAGE_LOAD_LOADING;
// new Thread(){
//
// @Override
// public void run() {
// final ResultState mState=dataLoad();
//
// UIUtils.runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if (mState!=null){
// currentState=mState.getState();
// showRightPage();
// }
// }
// });
// }
// }.start();
// }
// }
//
// /**
// * 初始化加载数据成功的布局
// * @return
// */
// public abstract View onCreateSuccessView();
//
// /**
// * 数据加载 返回值表示请求网络结束后的状态
// * @return
// */
// public abstract ResultState dataLoad();
//
// public enum ResultState{
//
// STATE_SUCCESS(PAGE_LOAD_SUCCESS),STATE_ERROR(PAGE_LOAD_FAIL),STATE_EMPTY(PAGE_LOAD_NONE);
//
// private int state;
// private ResultState(int state){
// this.state=state;
// }
//
// public int getState(){
// return this.state;
// }
// }
//
// }
// Path: app/src/main/java/com/topnews/android/fragment/MoneyFragment.java
import android.view.View;
import com.topnews.android.view.LoadingPage;
package com.topnews.android.fragment;
/**
* Created by dell on 2017/2/25.
*/
public class MoneyFragment extends BaseFragment {
@Override
public View onCreateSuccessView() {
return null;
}
@Override
|
public LoadingPage.ResultState dataLoad() {
|
idealo/mongodb-slow-operations-profiler
|
src/main/java/de/idealo/mongodb/slowops/util/Terminator.java
|
// Path: src/main/java/de/idealo/mongodb/slowops/collector/Terminable.java
// public interface Terminable {
//
// void terminate();
// long getDoneJobs();
// }
|
import de.idealo.mongodb.slowops.collector.Terminable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Callable;
|
package de.idealo.mongodb.slowops.util;
public class Terminator implements Callable<Long> {
private static final Logger LOG = LoggerFactory.getLogger(Terminator.class);
|
// Path: src/main/java/de/idealo/mongodb/slowops/collector/Terminable.java
// public interface Terminable {
//
// void terminate();
// long getDoneJobs();
// }
// Path: src/main/java/de/idealo/mongodb/slowops/util/Terminator.java
import de.idealo.mongodb.slowops.collector.Terminable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Callable;
package de.idealo.mongodb.slowops.util;
public class Terminator implements Callable<Long> {
private static final Logger LOG = LoggerFactory.getLogger(Terminator.class);
|
private final Terminable terminable;
|
idealo/mongodb-slow-operations-profiler
|
src/main/java/de/idealo/mongodb/slowops/collector/CollectorManagerInstance.java
|
// Path: src/main/java/de/idealo/mongodb/slowops/dto/ApplicationStatusDto.java
// public class ApplicationStatusDto {
//
// private static final Logger LOG = LoggerFactory.getLogger(ApplicationStatusDto.class);
//
// public static final long DEFAULT_MAX_WEBLOG_ENTRIES = 100;
//
// private static final ConcurrentLinkedDeque<String> WEBLOG = new ConcurrentLinkedDeque<String>();
// private static long MAX_WEBLOG_ENTRIES = DEFAULT_MAX_WEBLOG_ENTRIES;
// private static final String DATEFORMAT = ("yyyy/MM/dd HH:mm:ss,SSS");
//
// private volatile List<CollectorStatusDto> collectorStatuses = Collections.synchronizedList(Lists.newLinkedList());
// private CollectorServerDto collectorServerDto;
// private Date collectorRunningSince;
// private long numberOfReads;
// private long numberOfWrites;
// private long numberOfReadsOfRemovedReaders;
// private long numberOfWritesOfRemovedWriters;
// private String config;
// private Date lastRefresh=null;
//
//
// public synchronized void addCollectorStatus(CollectorStatusDto collectorStatusDto){
// collectorStatuses.add(collectorStatusDto);
// }
//
//
// public synchronized List<CollectorStatusDto> getCollectorStatuses(){
// LOG.debug("getCollectorStatuses size:" + collectorStatuses.size());
// return collectorStatuses;
// }
//
//
//
// public CollectorServerDto getCollectorServerDto() {
// return collectorServerDto;
// }
//
// public void setCollectorServerDto(CollectorServerDto collectorServerDto) {
// this.collectorServerDto = collectorServerDto;
// }
//
// public Date getCollectorRunningSince() {
// return collectorRunningSince;
// }
//
// public void setCollectorRunningSince(Date collectorRunningSince) { this.collectorRunningSince = collectorRunningSince; }
//
// public long getNumberOfReads() {
// return numberOfReads;
// }
//
// public void setNumberOfReads(long numberOfReads) {
// this.numberOfReads = numberOfReads;
// }
//
// public long getNumberOfWrites() {
// return numberOfWrites;
// }
//
// public void setNumberOfWrites(long numberOfWrites) {
// this.numberOfWrites = numberOfWrites;
// }
//
// public long getNumberOfReadsOfRemovedReaders() {
// return numberOfReadsOfRemovedReaders;
// }
//
// public void setNumberOfReadsOfRemovedReaders(long numberOfReadsOfRemovedReaders) {
// this.numberOfReadsOfRemovedReaders = numberOfReadsOfRemovedReaders;
// }
// public long getNumberOfWritesOfRemovedWriters() {
// return numberOfWritesOfRemovedWriters;
// }
//
// public void setNumberOfWritesOfRemovedWriters(long numberOfWritesOfRemovedWriters) {
// this.numberOfWritesOfRemovedWriters = numberOfWritesOfRemovedWriters;
// }
//
//
// public String getConfig() { return config; }
//
// public void setConfig(String config) { this.config = config; }
//
//
// public Date getLastRefresh() {return lastRefresh; }
//
// public void setLastRefresh(Date lastRefresh) {this.lastRefresh = lastRefresh; }
//
// public synchronized CollectorStatusDto getCollectorStatus(int id) {
// for(CollectorStatusDto collectorStatus : collectorStatuses){
// if(collectorStatus.getInstanceId() == id) return collectorStatus;
// }
// return null;
// }
//
// public static void setMaxWebLogEntries(long n){
// MAX_WEBLOG_ENTRIES = n;
// while(WEBLOG.size() > MAX_WEBLOG_ENTRIES){
// WEBLOG.poll();
// }
// }
//
// public static void addWebLog(String msg){
// while(WEBLOG.size() > MAX_WEBLOG_ENTRIES){
// WEBLOG.poll();
// }
// final SimpleDateFormat df = new SimpleDateFormat(DATEFORMAT);
// final long now = System.currentTimeMillis();
// WEBLOG.offer(df.format(now) + " " + msg);
// }
//
// public String getWebLog(){
// final StringBuilder sb = new StringBuilder();
// for(String entry : WEBLOG){
// sb.append(entry).append(System.lineSeparator());
// }
//
// return sb.toString();
// }
//
// }
|
import java.util.Set;
import de.idealo.mongodb.slowops.dto.ApplicationStatusDto;
import java.util.List;
|
/*
* Copyright (c) 2013 idealo internet GmbH -- all rights reserved.
*/
package de.idealo.mongodb.slowops.collector;
/**
*
*
* @author kay.agahd
* @since 02.04.2013
* @version $Id: $
* @copyright idealo internet GmbH
*/
public final class CollectorManagerInstance {
private static final CollectorManager INSTANCE = new CollectorManager();
private CollectorManagerInstance(){};//no Instances of this!
public static void init(){
INSTANCE.startup();
}
public static void terminate(){
INSTANCE.terminate();
}
|
// Path: src/main/java/de/idealo/mongodb/slowops/dto/ApplicationStatusDto.java
// public class ApplicationStatusDto {
//
// private static final Logger LOG = LoggerFactory.getLogger(ApplicationStatusDto.class);
//
// public static final long DEFAULT_MAX_WEBLOG_ENTRIES = 100;
//
// private static final ConcurrentLinkedDeque<String> WEBLOG = new ConcurrentLinkedDeque<String>();
// private static long MAX_WEBLOG_ENTRIES = DEFAULT_MAX_WEBLOG_ENTRIES;
// private static final String DATEFORMAT = ("yyyy/MM/dd HH:mm:ss,SSS");
//
// private volatile List<CollectorStatusDto> collectorStatuses = Collections.synchronizedList(Lists.newLinkedList());
// private CollectorServerDto collectorServerDto;
// private Date collectorRunningSince;
// private long numberOfReads;
// private long numberOfWrites;
// private long numberOfReadsOfRemovedReaders;
// private long numberOfWritesOfRemovedWriters;
// private String config;
// private Date lastRefresh=null;
//
//
// public synchronized void addCollectorStatus(CollectorStatusDto collectorStatusDto){
// collectorStatuses.add(collectorStatusDto);
// }
//
//
// public synchronized List<CollectorStatusDto> getCollectorStatuses(){
// LOG.debug("getCollectorStatuses size:" + collectorStatuses.size());
// return collectorStatuses;
// }
//
//
//
// public CollectorServerDto getCollectorServerDto() {
// return collectorServerDto;
// }
//
// public void setCollectorServerDto(CollectorServerDto collectorServerDto) {
// this.collectorServerDto = collectorServerDto;
// }
//
// public Date getCollectorRunningSince() {
// return collectorRunningSince;
// }
//
// public void setCollectorRunningSince(Date collectorRunningSince) { this.collectorRunningSince = collectorRunningSince; }
//
// public long getNumberOfReads() {
// return numberOfReads;
// }
//
// public void setNumberOfReads(long numberOfReads) {
// this.numberOfReads = numberOfReads;
// }
//
// public long getNumberOfWrites() {
// return numberOfWrites;
// }
//
// public void setNumberOfWrites(long numberOfWrites) {
// this.numberOfWrites = numberOfWrites;
// }
//
// public long getNumberOfReadsOfRemovedReaders() {
// return numberOfReadsOfRemovedReaders;
// }
//
// public void setNumberOfReadsOfRemovedReaders(long numberOfReadsOfRemovedReaders) {
// this.numberOfReadsOfRemovedReaders = numberOfReadsOfRemovedReaders;
// }
// public long getNumberOfWritesOfRemovedWriters() {
// return numberOfWritesOfRemovedWriters;
// }
//
// public void setNumberOfWritesOfRemovedWriters(long numberOfWritesOfRemovedWriters) {
// this.numberOfWritesOfRemovedWriters = numberOfWritesOfRemovedWriters;
// }
//
//
// public String getConfig() { return config; }
//
// public void setConfig(String config) { this.config = config; }
//
//
// public Date getLastRefresh() {return lastRefresh; }
//
// public void setLastRefresh(Date lastRefresh) {this.lastRefresh = lastRefresh; }
//
// public synchronized CollectorStatusDto getCollectorStatus(int id) {
// for(CollectorStatusDto collectorStatus : collectorStatuses){
// if(collectorStatus.getInstanceId() == id) return collectorStatus;
// }
// return null;
// }
//
// public static void setMaxWebLogEntries(long n){
// MAX_WEBLOG_ENTRIES = n;
// while(WEBLOG.size() > MAX_WEBLOG_ENTRIES){
// WEBLOG.poll();
// }
// }
//
// public static void addWebLog(String msg){
// while(WEBLOG.size() > MAX_WEBLOG_ENTRIES){
// WEBLOG.poll();
// }
// final SimpleDateFormat df = new SimpleDateFormat(DATEFORMAT);
// final long now = System.currentTimeMillis();
// WEBLOG.offer(df.format(now) + " " + msg);
// }
//
// public String getWebLog(){
// final StringBuilder sb = new StringBuilder();
// for(String entry : WEBLOG){
// sb.append(entry).append(System.lineSeparator());
// }
//
// return sb.toString();
// }
//
// }
// Path: src/main/java/de/idealo/mongodb/slowops/collector/CollectorManagerInstance.java
import java.util.Set;
import de.idealo.mongodb.slowops.dto.ApplicationStatusDto;
import java.util.List;
/*
* Copyright (c) 2013 idealo internet GmbH -- all rights reserved.
*/
package de.idealo.mongodb.slowops.collector;
/**
*
*
* @author kay.agahd
* @since 02.04.2013
* @version $Id: $
* @copyright idealo internet GmbH
*/
public final class CollectorManagerInstance {
private static final CollectorManager INSTANCE = new CollectorManager();
private CollectorManagerInstance(){};//no Instances of this!
public static void init(){
INSTANCE.startup();
}
public static void terminate(){
INSTANCE.terminate();
}
|
public static ApplicationStatusDto getApplicationStatus(boolean isAuthenticated){ return INSTANCE.getApplicationStatus(isAuthenticated); }
|
rwitzel/streamflyer
|
streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/regexj6/RegexModifierJava6Test.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/OnStreamMatcher.java
// public interface OnStreamMatcher extends MatchResult {
//
// // * <p>
// // * What is the technical idea behind this matcher? The purpose of this
// // matcher
// // * is too extend the class {@link Matcher} with the following code.
// // <code><pre>
// // private int lastFrom;
// //
// // public boolean findUntilMatchOrHitEnd(int from, int to) {
// // this.hitEnd = false;
// // this.requireEnd = false;
// // from = from < 0 ? 0 : from;
// // this.first = from;
// // this.oldLast = oldLast < 0 ? from : oldLast;
// // for (int i = 0; i < groups.length; i++)
// // groups[i] = -1;
// // acceptMode = NOANCHOR;
// // boolean result = false;
// // for (this.lastFrom = from; lastFrom <= to; lastFrom++) {
// // result = parentPattern.matchRoot.match(this, lastFrom, text);
// // if (result || hitEnd()) {
// // break;
// // }
// // }
// // if (!result)
// // this.first = -1;
// // this.oldLast = this.last;
// // return result;
// // }
// //
// // public int lastFrom() {
// // return lastFrom;
// // }
// // </pre></code>
// // * <p>
// // * Unfortunately, {@link Matcher} cannot by extended via subclassing
// // because
// // * {@link Matcher} is a final type. The new interface {@link
// // OnStreamMatcher}
// // * provides all methods necessary to do match regular expresions on
// // character
// // * stream including the method {@link #findUnlessHitEnd(int, int)}.
//
// /**
// * @see Matcher#reset(CharSequence)
// */
// public void reset(CharSequence input);
//
// /**
// * Looks for the first position that could be the start of a match that starts in the range [ <code>from</code>
// * (including), <code>maxFrom</code> (including)]. If such a position is found, then the method stops and returns
// * true if the input provides enough characters to make a match.
// * <p>
// * ATTENTION! maxFrom can be the position behind(!) the last character of the input.
// * <p>
// * This first position can retrieved via {@link #lastFrom()}.
// *
// * @param minFrom
// * @param maxFrom
// * @return Returns true if the method found a match at the position {@link #lastFrom()}.
// */
// public boolean findUnlessHitEnd(int minFrom, int maxFrom);
//
// /**
// * @see Matcher#hitEnd()
// */
// public boolean hitEnd();
//
// /**
// * @see Matcher#requireEnd()
// */
// public boolean requireEnd();
//
// /**
// * This property is set by calling {@link #findUnlessHitEnd(int, int)} .
// * <p>
// * ATTENTION! This property returns maxFrom + 1, if {@link #findUnlessHitEnd(int, int)} neither has found a match
// * nor has hit the end of input as long it looked for matches that started somewhere in the interval [minFrom,
// * maxFrom].
// * <p>
// * ATTENTION! This information is not really helpful when the buffer size is equal to maxFrom. In this case you
// * cannot say whether the position of lastFrom is the start of a potential match or not.
// *
// * @return Returns the last position {@link #findUnlessHitEnd(int, int)} has investigated before it returned.
// */
// public int lastFrom();
// }
|
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.rwitzel.streamflyer.regex.OnStreamMatcher;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.regexj6;
/**
* Tests {@link OnStreamJava6Matcher}.
*
* @author rwoo
*
* @since 28.06.2011
*/
public class RegexModifierJava6Test extends com.github.rwitzel.streamflyer.regex.RegexModifierTest {
@Override
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/OnStreamMatcher.java
// public interface OnStreamMatcher extends MatchResult {
//
// // * <p>
// // * What is the technical idea behind this matcher? The purpose of this
// // matcher
// // * is too extend the class {@link Matcher} with the following code.
// // <code><pre>
// // private int lastFrom;
// //
// // public boolean findUntilMatchOrHitEnd(int from, int to) {
// // this.hitEnd = false;
// // this.requireEnd = false;
// // from = from < 0 ? 0 : from;
// // this.first = from;
// // this.oldLast = oldLast < 0 ? from : oldLast;
// // for (int i = 0; i < groups.length; i++)
// // groups[i] = -1;
// // acceptMode = NOANCHOR;
// // boolean result = false;
// // for (this.lastFrom = from; lastFrom <= to; lastFrom++) {
// // result = parentPattern.matchRoot.match(this, lastFrom, text);
// // if (result || hitEnd()) {
// // break;
// // }
// // }
// // if (!result)
// // this.first = -1;
// // this.oldLast = this.last;
// // return result;
// // }
// //
// // public int lastFrom() {
// // return lastFrom;
// // }
// // </pre></code>
// // * <p>
// // * Unfortunately, {@link Matcher} cannot by extended via subclassing
// // because
// // * {@link Matcher} is a final type. The new interface {@link
// // OnStreamMatcher}
// // * provides all methods necessary to do match regular expresions on
// // character
// // * stream including the method {@link #findUnlessHitEnd(int, int)}.
//
// /**
// * @see Matcher#reset(CharSequence)
// */
// public void reset(CharSequence input);
//
// /**
// * Looks for the first position that could be the start of a match that starts in the range [ <code>from</code>
// * (including), <code>maxFrom</code> (including)]. If such a position is found, then the method stops and returns
// * true if the input provides enough characters to make a match.
// * <p>
// * ATTENTION! maxFrom can be the position behind(!) the last character of the input.
// * <p>
// * This first position can retrieved via {@link #lastFrom()}.
// *
// * @param minFrom
// * @param maxFrom
// * @return Returns true if the method found a match at the position {@link #lastFrom()}.
// */
// public boolean findUnlessHitEnd(int minFrom, int maxFrom);
//
// /**
// * @see Matcher#hitEnd()
// */
// public boolean hitEnd();
//
// /**
// * @see Matcher#requireEnd()
// */
// public boolean requireEnd();
//
// /**
// * This property is set by calling {@link #findUnlessHitEnd(int, int)} .
// * <p>
// * ATTENTION! This property returns maxFrom + 1, if {@link #findUnlessHitEnd(int, int)} neither has found a match
// * nor has hit the end of input as long it looked for matches that started somewhere in the interval [minFrom,
// * maxFrom].
// * <p>
// * ATTENTION! This information is not really helpful when the buffer size is equal to maxFrom. In this case you
// * cannot say whether the position of lastFrom is the start of a potential match or not.
// *
// * @return Returns the last position {@link #findUnlessHitEnd(int, int)} has investigated before it returned.
// */
// public int lastFrom();
// }
// Path: streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/regexj6/RegexModifierJava6Test.java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.rwitzel.streamflyer.regex.OnStreamMatcher;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.regexj6;
/**
* Tests {@link OnStreamJava6Matcher}.
*
* @author rwoo
*
* @since 28.06.2011
*/
public class RegexModifierJava6Test extends com.github.rwitzel.streamflyer.regex.RegexModifierTest {
@Override
|
protected OnStreamMatcher createMatcher(String regex, int flags) {
|
rwitzel/streamflyer
|
streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShiftedTest.java
|
// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShifted.java
// public class MatchResultShifted implements MatchResult {
//
// private MatchResult delegate;
//
// private StringBuilder input;
//
// private int shift;
//
// /**
// *
// * @param delegate
// * the original match result
// * @param input
// * the input where some character before the match have been inserted or removed
// * @param shift
// * the number of characters that are inserted or removed. If the characters are removed, the shift must
// * be negative number.
// */
// public MatchResultShifted(MatchResult delegate, StringBuilder input, int shift) {
// super();
// this.delegate = delegate;
// this.input = input;
// this.shift = shift;
// }
//
// @Override
// public int start() {
// int result = delegate.start();
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public int start(int group) {
// int result = delegate.start(group);
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public int end() {
// int result = delegate.end();
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public int end(int group) {
// int result = delegate.end(group);
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public String group() {
// int start = start();
// int end = end();
// if (start == -1 || end == -1) {
// return null;
// } else {
// return input.substring(start, end);
// }
// }
//
// @Override
// public String group(int group) {
// int start = start(group);
// int end = end(group);
// if (start == -1 || end == -1) {
// return null;
// } else {
// return input.substring(start, end);
// }
// }
//
// @Override
// public int groupCount() {
// return delegate.groupCount();
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return "MatchResultShifted [group=" + group() + ", start=" + start() + ", end=" + end() + "]";
// }
//
// }
|
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.github.rwitzel.streamflyer.experimental.range2.MatchResultShifted;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.range2;
/**
* Tests {@link MatchResultShifted}.
*
* @author rwoo
*
*/
public class MatchResultShiftedTest {
@Test
public void testGroupCountAndMore() throws Exception {
StringBuilder input = new StringBuilder("1234567890123451xx2yy5aa6bb");
String regex = "(1xx(2yy((4zz)|(5aa)))(6bb))";
Matcher matcher = Pattern.compile(regex).matcher(input);
assertTrue(matcher.find());
assertEquals(6, matcher.groupCount());
assertEquals("1xx2yy5aa6bb", matcher.group());
{
assertGroups(matcher, 0);
}
// delete the first ten characters from the input
input.delete(0, 10);
assertEquals(6, matcher.groupCount());
try {
// learning test: the matcher works directly on the string builder (it does not cache groups)
assertEquals("1xx2yy5aa6bb", matcher.group());
fail("StringIndexOutOfBoundsException expected");
} catch (StringIndexOutOfBoundsException e) {
}
{
// offset = 0 -> "1xx2yy5aa6bb" will be the match result
|
// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShifted.java
// public class MatchResultShifted implements MatchResult {
//
// private MatchResult delegate;
//
// private StringBuilder input;
//
// private int shift;
//
// /**
// *
// * @param delegate
// * the original match result
// * @param input
// * the input where some character before the match have been inserted or removed
// * @param shift
// * the number of characters that are inserted or removed. If the characters are removed, the shift must
// * be negative number.
// */
// public MatchResultShifted(MatchResult delegate, StringBuilder input, int shift) {
// super();
// this.delegate = delegate;
// this.input = input;
// this.shift = shift;
// }
//
// @Override
// public int start() {
// int result = delegate.start();
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public int start(int group) {
// int result = delegate.start(group);
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public int end() {
// int result = delegate.end();
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public int end(int group) {
// int result = delegate.end(group);
// if (result == -1) {
// return result;
// } else {
// return result + shift;
// }
// }
//
// @Override
// public String group() {
// int start = start();
// int end = end();
// if (start == -1 || end == -1) {
// return null;
// } else {
// return input.substring(start, end);
// }
// }
//
// @Override
// public String group(int group) {
// int start = start(group);
// int end = end(group);
// if (start == -1 || end == -1) {
// return null;
// } else {
// return input.substring(start, end);
// }
// }
//
// @Override
// public int groupCount() {
// return delegate.groupCount();
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return "MatchResultShifted [group=" + group() + ", start=" + start() + ", end=" + end() + "]";
// }
//
// }
// Path: streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/MatchResultShiftedTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.github.rwitzel.streamflyer.experimental.range2.MatchResultShifted;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.range2;
/**
* Tests {@link MatchResultShifted}.
*
* @author rwoo
*
*/
public class MatchResultShiftedTest {
@Test
public void testGroupCountAndMore() throws Exception {
StringBuilder input = new StringBuilder("1234567890123451xx2yy5aa6bb");
String regex = "(1xx(2yy((4zz)|(5aa)))(6bb))";
Matcher matcher = Pattern.compile(regex).matcher(input);
assertTrue(matcher.find());
assertEquals(6, matcher.groupCount());
assertEquals("1xx2yy5aa6bb", matcher.group());
{
assertGroups(matcher, 0);
}
// delete the first ten characters from the input
input.delete(0, 10);
assertEquals(6, matcher.groupCount());
try {
// learning test: the matcher works directly on the string builder (it does not cache groups)
assertEquals("1xx2yy5aa6bb", matcher.group());
fail("StringIndexOutOfBoundsException expected");
} catch (StringIndexOutOfBoundsException e) {
}
{
// offset = 0 -> "1xx2yy5aa6bb" will be the match result
|
MatchResult result = new MatchResultShifted(matcher, input, -10);
|
rwitzel/streamflyer
|
streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/xml/XmlVersionReaderTest.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/xml/XmlVersionReader.java
// public class XmlVersionReader extends BufferedReader {
//
// private String xmlVersion;
//
// //
// // constructors
// //
//
// public XmlVersionReader(Reader in) throws IOException {
// super(in);
//
// String prolog = prolog();
// xmlVersion = xmlVersion(prolog);
// }
//
// //
// // private methods
// //
//
// private String xmlVersion(String prolog) {
//
// // (Should we do aware of BOMs here? No. I consider it the
// // responsibility of the caller to provide characters without BOM.)
//
// Matcher matcher = Pattern.compile("<\\?xml[^>]*version\\s*=\\s*['\"]((1.0)|(1.1))['\"].*").matcher(prolog);
// if (matcher.matches()) {
// return matcher.group(1);
// } else {
// // the default, see class comment.
// return "1.0";
// }
// }
//
// private String prolog() throws IOException {
//
// // the prolog may contain many, many whitespace characters -> 4096
// final int MAX_SNIFFED_CHARACTERS = 4096;
//
// mark(MAX_SNIFFED_CHARACTERS);
// try {
//
// char[] cbuf = new char[MAX_SNIFFED_CHARACTERS];
// int read = read(cbuf);
// if (read == -1) {
// return "";
// } else {
// return new String(cbuf, 0, read);
// }
// } finally {
// reset();
// }
// }
//
// //
// // public methods
// //
//
// /**
// * @return Returns the XML version read from the character stream. If there is XML prolog given, then version "1.0"
// * is assumed and returned.
// */
// public String getXmlVersion() {
// return xmlVersion;
// }
// }
|
import org.junit.Test;
import com.github.rwitzel.streamflyer.xml.XmlVersionReader;
import static org.junit.Assert.*;
import java.io.StringReader;
import junit.framework.TestCase;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.xml;
/**
* Tests {@link XmlVersionReader}.
*
* @author rwoo
* @since 27.06.2011
*/
public class XmlVersionReaderTest {
@Test
public void testNoXmlVersionInProlog() throws Exception {
assertXmlVersion("1.0", "<html>");
assertXmlVersion("1.0", "<html version='1.1'>");
assertXmlVersion("1.1", "<?xml version='1.1'><html version='1.0'>");
assertXmlVersion("1.0", "");
}
@Test
public void testXmlVersion10InProlog() throws Exception {
assertXmlVersion("1.0", "<?xml encoding='hossa' version='1.0' standalone='true'");
assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version=\"1.0\" standalone=\"true\"");
assertXmlVersion("1.0", "<?xml encoding='hossa' version = '1.0' standalone='true'");
assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version = \"1.0\" standalone=\"true\"");
}
@Test
public void testXmlVersion11InProlog() throws Exception {
assertXmlVersion("1.1", "<?xml encoding='hossa' version='1.1' standalone='true'");
assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version=\"1.1\" standalone=\"true\"");
assertXmlVersion("1.1", "<?xml encoding='hossa' version = '1.1' standalone='true'");
assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version = \"1.1\" standalone=\"true\"");
}
private void assertXmlVersion(String expectedXmlVersion, String xml) throws Exception {
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/xml/XmlVersionReader.java
// public class XmlVersionReader extends BufferedReader {
//
// private String xmlVersion;
//
// //
// // constructors
// //
//
// public XmlVersionReader(Reader in) throws IOException {
// super(in);
//
// String prolog = prolog();
// xmlVersion = xmlVersion(prolog);
// }
//
// //
// // private methods
// //
//
// private String xmlVersion(String prolog) {
//
// // (Should we do aware of BOMs here? No. I consider it the
// // responsibility of the caller to provide characters without BOM.)
//
// Matcher matcher = Pattern.compile("<\\?xml[^>]*version\\s*=\\s*['\"]((1.0)|(1.1))['\"].*").matcher(prolog);
// if (matcher.matches()) {
// return matcher.group(1);
// } else {
// // the default, see class comment.
// return "1.0";
// }
// }
//
// private String prolog() throws IOException {
//
// // the prolog may contain many, many whitespace characters -> 4096
// final int MAX_SNIFFED_CHARACTERS = 4096;
//
// mark(MAX_SNIFFED_CHARACTERS);
// try {
//
// char[] cbuf = new char[MAX_SNIFFED_CHARACTERS];
// int read = read(cbuf);
// if (read == -1) {
// return "";
// } else {
// return new String(cbuf, 0, read);
// }
// } finally {
// reset();
// }
// }
//
// //
// // public methods
// //
//
// /**
// * @return Returns the XML version read from the character stream. If there is XML prolog given, then version "1.0"
// * is assumed and returned.
// */
// public String getXmlVersion() {
// return xmlVersion;
// }
// }
// Path: streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/xml/XmlVersionReaderTest.java
import org.junit.Test;
import com.github.rwitzel.streamflyer.xml.XmlVersionReader;
import static org.junit.Assert.*;
import java.io.StringReader;
import junit.framework.TestCase;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.xml;
/**
* Tests {@link XmlVersionReader}.
*
* @author rwoo
* @since 27.06.2011
*/
public class XmlVersionReaderTest {
@Test
public void testNoXmlVersionInProlog() throws Exception {
assertXmlVersion("1.0", "<html>");
assertXmlVersion("1.0", "<html version='1.1'>");
assertXmlVersion("1.1", "<?xml version='1.1'><html version='1.0'>");
assertXmlVersion("1.0", "");
}
@Test
public void testXmlVersion10InProlog() throws Exception {
assertXmlVersion("1.0", "<?xml encoding='hossa' version='1.0' standalone='true'");
assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version=\"1.0\" standalone=\"true\"");
assertXmlVersion("1.0", "<?xml encoding='hossa' version = '1.0' standalone='true'");
assertXmlVersion("1.0", "<?xml encoding=\"hossa\" version = \"1.0\" standalone=\"true\"");
}
@Test
public void testXmlVersion11InProlog() throws Exception {
assertXmlVersion("1.1", "<?xml encoding='hossa' version='1.1' standalone='true'");
assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version=\"1.1\" standalone=\"true\"");
assertXmlVersion("1.1", "<?xml encoding='hossa' version = '1.1' standalone='true'");
assertXmlVersion("1.1", "<?xml encoding=\"hossa\" version = \"1.1\" standalone=\"true\"");
}
private void assertXmlVersion(String expectedXmlVersion, String xml) throws Exception {
|
XmlVersionReader reader = new XmlVersionReader(new StringReader(xml));
|
rwitzel/streamflyer
|
streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/regex/addons/tokens/TokenTest.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/addons/tokens/Token.java
// public class Token {
//
// /**
// * An ID for the token. The ID shall be unique among all tokens used with the {@link TokenProcessor}. Immutable.
// */
// private String name;
//
// /**
// * This regular expression describes how a token can be matched. Flags should be embedded via
// * {@link EmbeddedFlagUtil}. Immutable.
// */
// private String regex;
//
// /**
// * The number of capturing groups that are contained in the {@link #regex}. Immutable.
// * <p>
// * Calculated from {@link #regex} and saved here to improve the performance of a {@link TokenProcessor}.
// */
// private int capturingGroupCount;
//
// /**
// * This object processes the match if the token is matched.
// */
// private MatchProcessor matchProcessor;
//
// /**
// * This constructor should be used only in tests!
// *
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// */
// public Token(String regex) {
// this("" + System.currentTimeMillis(), regex, new DoNothingProcessor());
// }
//
// /**
// * This token matches the given regex but the match processor does {@link DoNothingProcessor nothing}.
// *
// * @param name
// * See {@link #name}.
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// */
// public Token(String name, String regex) {
// this(name, regex, new DoNothingProcessor());
// }
//
// /**
// * This token matches the given regex and {@link ReplacingProcessor replaces} the match with the replacement.
// *
// * @param name
// * See {@link #name}.
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// * @param replacement
// */
// public Token(String name, String regex, String replacement) {
// this(name, regex, new ReplacingProcessor(replacement));
// }
//
// /**
// * This token matches the given regex and the match will be processed with the given {@link MatchProcessor}.
// *
// * @param name
// * See {@link #name}
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// * @param matchProcessor
// */
// public Token(String name, String regex, MatchProcessor matchProcessor) {
// super();
//
// ZzzValidate.notNull(matchProcessor, "matchProcessor must not be null");
//
// this.name = name;
// this.regex = regex;
// this.matchProcessor = matchProcessor;
// this.capturingGroupCount = Pattern.compile(regex).matcher("").groupCount();
// }
//
// public String getName() {
// return name;
// }
//
// public String getRegex() {
// return regex;
// }
//
// public int getCapturingGroupCount() {
// return capturingGroupCount;
// }
//
// public MatchProcessor getMatchProcessor() {
// return matchProcessor;
// }
//
// @Override
// public String toString() {
// return "Token [name=" + name + ", regex=" + regex + ", capturingGroupCount=" + capturingGroupCount
// + ", matchProcessor=" + matchProcessor + "]";
// }
//
// }
|
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.github.rwitzel.streamflyer.regex.addons.tokens.Token;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.regex.addons.tokens;
/**
* Tests {@link Token}.
*
* @author rwoo
*
*/
public class TokenTest {
@Test
public void testGetCapturingGroupCount() throws Exception {
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/addons/tokens/Token.java
// public class Token {
//
// /**
// * An ID for the token. The ID shall be unique among all tokens used with the {@link TokenProcessor}. Immutable.
// */
// private String name;
//
// /**
// * This regular expression describes how a token can be matched. Flags should be embedded via
// * {@link EmbeddedFlagUtil}. Immutable.
// */
// private String regex;
//
// /**
// * The number of capturing groups that are contained in the {@link #regex}. Immutable.
// * <p>
// * Calculated from {@link #regex} and saved here to improve the performance of a {@link TokenProcessor}.
// */
// private int capturingGroupCount;
//
// /**
// * This object processes the match if the token is matched.
// */
// private MatchProcessor matchProcessor;
//
// /**
// * This constructor should be used only in tests!
// *
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// */
// public Token(String regex) {
// this("" + System.currentTimeMillis(), regex, new DoNothingProcessor());
// }
//
// /**
// * This token matches the given regex but the match processor does {@link DoNothingProcessor nothing}.
// *
// * @param name
// * See {@link #name}.
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// */
// public Token(String name, String regex) {
// this(name, regex, new DoNothingProcessor());
// }
//
// /**
// * This token matches the given regex and {@link ReplacingProcessor replaces} the match with the replacement.
// *
// * @param name
// * See {@link #name}.
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// * @param replacement
// */
// public Token(String name, String regex, String replacement) {
// this(name, regex, new ReplacingProcessor(replacement));
// }
//
// /**
// * This token matches the given regex and the match will be processed with the given {@link MatchProcessor}.
// *
// * @param name
// * See {@link #name}
// * @param regex
// * The regex describes how a token can be matched. Embed flags via {@link EmbeddedFlagUtil}.
// * @param matchProcessor
// */
// public Token(String name, String regex, MatchProcessor matchProcessor) {
// super();
//
// ZzzValidate.notNull(matchProcessor, "matchProcessor must not be null");
//
// this.name = name;
// this.regex = regex;
// this.matchProcessor = matchProcessor;
// this.capturingGroupCount = Pattern.compile(regex).matcher("").groupCount();
// }
//
// public String getName() {
// return name;
// }
//
// public String getRegex() {
// return regex;
// }
//
// public int getCapturingGroupCount() {
// return capturingGroupCount;
// }
//
// public MatchProcessor getMatchProcessor() {
// return matchProcessor;
// }
//
// @Override
// public String toString() {
// return "Token [name=" + name + ", regex=" + regex + ", capturingGroupCount=" + capturingGroupCount
// + ", matchProcessor=" + matchProcessor + "]";
// }
//
// }
// Path: streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/regex/addons/tokens/TokenTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.github.rwitzel.streamflyer.regex.addons.tokens.Token;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.regex.addons.tokens;
/**
* Tests {@link Token}.
*
* @author rwoo
*
*/
public class TokenTest {
@Test
public void testGetCapturingGroupCount() throws Exception {
|
assertEquals(0, new Token("").getCapturingGroupCount());
|
rwitzel/streamflyer
|
streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/addons/util/DoNothingProcessor.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/AbstractMatchProcessor.java
// public abstract class AbstractMatchProcessor implements MatchProcessor {
//
// /**
// * @param matchResult
// * the {@link MatchResult} given to the {@link MatchProcessor}.
// * @param newMatchEnd
// * the position of the end of the matched string after the character buffer is modified.
// * @param continueMatching
// * See {@link MatchProcessorResult#isContinueMatching()}
// * @return Returns a {@link MatchProcessorResult} that cannot cause an endless loop.
// */
// protected MatchProcessorResult createResult(MatchResult matchResult, int newMatchEnd, boolean continueMatching) {
//
// int matchStart = matchResult.start();
// int matchEnd = matchResult.end();
//
// // if the empty string is matched, then we increase the position
// // to avoid endless loops
// // (compare to Matcher.find() where we see the following code:
// // int i = last; if(i == first) i++;
// // in words: set the *from* for the next match at the
// // end of the last match. if this is equal to the start
// // of the last match (a match on the empty string(, then
// // increase the *from* to avoid endless loops)
// int offset = matchStart == matchEnd ? 1 : 0;
//
// return new MatchProcessorResult(newMatchEnd + offset, continueMatching);
// }
//
// }
//
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/MatchProcessor.java
// public interface MatchProcessor {
//
// /**
// * Processes the given match. The match processor is allowed to modify the given character buffer but it must not
// * modify the characters before the first modifiable character in the buffer because the characters before that
// * position are considered unmodifiable.
// *
// * @param characterBuffer
// * Must not be <code>null</code>.
// * @param firstModifiableCharacterInBuffer
// * In comparison to the parameter with the same name in
// * {@link Modifier#modify(StringBuilder, int, boolean)} this parameter might be the position at the end
// * of the previous match if there is one. (TODO should we rather pass two parameters like 'first char'
// * and 'end of previous match' instead of this single parameter?)
// * @param matchResult
// * The match that is found in the given character buffer. Must not be <code>null</code>.
// * @return Returns an {@link MatchProcessorResult object} that describes where to continue the matching.
// */
// public MatchProcessorResult process(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
// MatchResult matchResult);
//
// }
//
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/MatchProcessorResult.java
// public class MatchProcessorResult {
//
// /**
// * A position in the character buffer. The characters before this position shall be considered unmodifiable by the
// * {@link RegexModifier}.
// * <p>
// * This position must not be smaller than the (originally) first modifiable character in the buffer.
// * <p>
// * This position must not be greater than the size of the buffer plus one.
// * <p>
// * EXAMPLE: This position is equal to the size of the buffer plus one if the empty string is matched (and processed)
// * and the matching shall be continued after the first character after the empty match. This avoids endless loops.
// */
// private int firstModifiableCharacterInBuffer;
//
// /**
// * True if the matching shall be continued using the characters that already available in the buffer.
// */
// private boolean continueMatching;
//
// /**
// * @param firstModifiableCharacterInBuffer
// * @param continueMatching
// */
// public MatchProcessorResult(int firstModifiableCharacterInBuffer, boolean continueMatching) {
// super();
// this.firstModifiableCharacterInBuffer = firstModifiableCharacterInBuffer;
// this.continueMatching = continueMatching;
// }
//
// /**
// * @return Returns the {@link #firstModifiableCharacterInBuffer}.
// */
// public int getFirstModifiableCharacterInBuffer() {
// return firstModifiableCharacterInBuffer;
// }
//
// /**
// * @return Returns the {@link #continueMatching}.
// */
// public boolean isContinueMatching() {
// return continueMatching;
// }
// }
|
import java.util.regex.MatchResult;
import com.github.rwitzel.streamflyer.regex.AbstractMatchProcessor;
import com.github.rwitzel.streamflyer.regex.MatchProcessor;
import com.github.rwitzel.streamflyer.regex.MatchProcessorResult;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.regex.addons.util;
/**
* This {@link MatchProcessor} does not modify the stream.
*
* @author rwoo
* @since 1.1.0
*/
public class DoNothingProcessor extends AbstractMatchProcessor implements MatchProcessor {
@Override
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/AbstractMatchProcessor.java
// public abstract class AbstractMatchProcessor implements MatchProcessor {
//
// /**
// * @param matchResult
// * the {@link MatchResult} given to the {@link MatchProcessor}.
// * @param newMatchEnd
// * the position of the end of the matched string after the character buffer is modified.
// * @param continueMatching
// * See {@link MatchProcessorResult#isContinueMatching()}
// * @return Returns a {@link MatchProcessorResult} that cannot cause an endless loop.
// */
// protected MatchProcessorResult createResult(MatchResult matchResult, int newMatchEnd, boolean continueMatching) {
//
// int matchStart = matchResult.start();
// int matchEnd = matchResult.end();
//
// // if the empty string is matched, then we increase the position
// // to avoid endless loops
// // (compare to Matcher.find() where we see the following code:
// // int i = last; if(i == first) i++;
// // in words: set the *from* for the next match at the
// // end of the last match. if this is equal to the start
// // of the last match (a match on the empty string(, then
// // increase the *from* to avoid endless loops)
// int offset = matchStart == matchEnd ? 1 : 0;
//
// return new MatchProcessorResult(newMatchEnd + offset, continueMatching);
// }
//
// }
//
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/MatchProcessor.java
// public interface MatchProcessor {
//
// /**
// * Processes the given match. The match processor is allowed to modify the given character buffer but it must not
// * modify the characters before the first modifiable character in the buffer because the characters before that
// * position are considered unmodifiable.
// *
// * @param characterBuffer
// * Must not be <code>null</code>.
// * @param firstModifiableCharacterInBuffer
// * In comparison to the parameter with the same name in
// * {@link Modifier#modify(StringBuilder, int, boolean)} this parameter might be the position at the end
// * of the previous match if there is one. (TODO should we rather pass two parameters like 'first char'
// * and 'end of previous match' instead of this single parameter?)
// * @param matchResult
// * The match that is found in the given character buffer. Must not be <code>null</code>.
// * @return Returns an {@link MatchProcessorResult object} that describes where to continue the matching.
// */
// public MatchProcessorResult process(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
// MatchResult matchResult);
//
// }
//
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/MatchProcessorResult.java
// public class MatchProcessorResult {
//
// /**
// * A position in the character buffer. The characters before this position shall be considered unmodifiable by the
// * {@link RegexModifier}.
// * <p>
// * This position must not be smaller than the (originally) first modifiable character in the buffer.
// * <p>
// * This position must not be greater than the size of the buffer plus one.
// * <p>
// * EXAMPLE: This position is equal to the size of the buffer plus one if the empty string is matched (and processed)
// * and the matching shall be continued after the first character after the empty match. This avoids endless loops.
// */
// private int firstModifiableCharacterInBuffer;
//
// /**
// * True if the matching shall be continued using the characters that already available in the buffer.
// */
// private boolean continueMatching;
//
// /**
// * @param firstModifiableCharacterInBuffer
// * @param continueMatching
// */
// public MatchProcessorResult(int firstModifiableCharacterInBuffer, boolean continueMatching) {
// super();
// this.firstModifiableCharacterInBuffer = firstModifiableCharacterInBuffer;
// this.continueMatching = continueMatching;
// }
//
// /**
// * @return Returns the {@link #firstModifiableCharacterInBuffer}.
// */
// public int getFirstModifiableCharacterInBuffer() {
// return firstModifiableCharacterInBuffer;
// }
//
// /**
// * @return Returns the {@link #continueMatching}.
// */
// public boolean isContinueMatching() {
// return continueMatching;
// }
// }
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/addons/util/DoNothingProcessor.java
import java.util.regex.MatchResult;
import com.github.rwitzel.streamflyer.regex.AbstractMatchProcessor;
import com.github.rwitzel.streamflyer.regex.MatchProcessor;
import com.github.rwitzel.streamflyer.regex.MatchProcessorResult;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.regex.addons.util;
/**
* This {@link MatchProcessor} does not modify the stream.
*
* @author rwoo
* @since 1.1.0
*/
public class DoNothingProcessor extends AbstractMatchProcessor implements MatchProcessor {
@Override
|
public MatchProcessorResult process(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
|
rwitzel/streamflyer
|
streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/regex/addons/tokens/MatchResultWithOffsetTest.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/addons/tokens/MatchResultWithOffset.java
// public class MatchResultWithOffset implements MatchResult {
//
// private MatchResult delegate;
//
// private int groupOffset;
//
// /**
// * Calculated on demand.
// */
// private Integer groupCount;
//
// public MatchResultWithOffset(MatchResult delegate, int groupOffset) {
// super();
//
// if (groupOffset > delegate.groupCount() || groupOffset < 0) {
// throw new IndexOutOfBoundsException("No group " + groupOffset);
// }
//
// this.delegate = delegate;
// this.groupOffset = groupOffset;
// }
//
// @Override
// public int start() {
// return delegate.start(groupOffset);
// }
//
// @Override
// public int start(int group) {
// return delegate.start(groupOffset + group);
// }
//
// @Override
// public int end() {
// return delegate.end(groupOffset);
// }
//
// @Override
// public int end(int group) {
// return delegate.end(groupOffset + group);
// }
//
// @Override
// public String group() {
// return delegate.group(groupOffset);
// }
//
// @Override
// public String group(int group) {
// return delegate.group(groupOffset + group);
// }
//
// /**
// * Attention! Without Java reflection we cannot find out whether an unmatched or empty group immediately placed
// * before or after the end of a group is within or outside the other group. That is the returned group count might
// * be to high because it includes additional unmatched or empty groups.
// */
// @Override
// public int groupCount() {
// if (groupCount == null) {
// int groupIndex = groupOffset + 1;
// while (groupIndex <= delegate.groupCount() && delegate.end(groupIndex) <= delegate.end(groupOffset)) {
// groupIndex++;
// }
// groupCount = (groupIndex - 1) - groupOffset;
// }
// return groupCount;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return "MatchResultWithOffset [delegate=" + delegate + ", groupOffset=" + groupOffset + ", groupCount="
// + groupCount + "]";
// }
//
// }
|
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.github.rwitzel.streamflyer.regex.addons.tokens.MatchResultWithOffset;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.regex.addons.tokens;
/**
* Tests {@link MatchResultWithOffset}.
*
* @author rwoo
*
*/
public class MatchResultWithOffsetTest {
/**
* Test for the unexpected behaviour of empty groups
*
* @throws Exception
*/
@Test
public void testGroupCountAndMore_UNEXPECTED_emptyGroupsAfterEndOfTargetGroupIncluded() throws Exception {
String input = "1xxnnnnnnnnnn";
String regex = "(1xx())()";
Matcher matcher = Pattern.compile(regex).matcher(input);
assertTrue(matcher.find());
assertEquals(3, matcher.groupCount()); // principle of the longest possible match
{
// offset = 1 -> "1xx" will be the match result
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/regex/addons/tokens/MatchResultWithOffset.java
// public class MatchResultWithOffset implements MatchResult {
//
// private MatchResult delegate;
//
// private int groupOffset;
//
// /**
// * Calculated on demand.
// */
// private Integer groupCount;
//
// public MatchResultWithOffset(MatchResult delegate, int groupOffset) {
// super();
//
// if (groupOffset > delegate.groupCount() || groupOffset < 0) {
// throw new IndexOutOfBoundsException("No group " + groupOffset);
// }
//
// this.delegate = delegate;
// this.groupOffset = groupOffset;
// }
//
// @Override
// public int start() {
// return delegate.start(groupOffset);
// }
//
// @Override
// public int start(int group) {
// return delegate.start(groupOffset + group);
// }
//
// @Override
// public int end() {
// return delegate.end(groupOffset);
// }
//
// @Override
// public int end(int group) {
// return delegate.end(groupOffset + group);
// }
//
// @Override
// public String group() {
// return delegate.group(groupOffset);
// }
//
// @Override
// public String group(int group) {
// return delegate.group(groupOffset + group);
// }
//
// /**
// * Attention! Without Java reflection we cannot find out whether an unmatched or empty group immediately placed
// * before or after the end of a group is within or outside the other group. That is the returned group count might
// * be to high because it includes additional unmatched or empty groups.
// */
// @Override
// public int groupCount() {
// if (groupCount == null) {
// int groupIndex = groupOffset + 1;
// while (groupIndex <= delegate.groupCount() && delegate.end(groupIndex) <= delegate.end(groupOffset)) {
// groupIndex++;
// }
// groupCount = (groupIndex - 1) - groupOffset;
// }
// return groupCount;
// }
//
// /*
// * (non-Javadoc)
// *
// * @see java.lang.Object#toString()
// */
// @Override
// public String toString() {
// return "MatchResultWithOffset [delegate=" + delegate + ", groupOffset=" + groupOffset + ", groupCount="
// + groupCount + "]";
// }
//
// }
// Path: streamflyer-core/src/test/java/com/github/rwitzel/streamflyer/regex/addons/tokens/MatchResultWithOffsetTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import com.github.rwitzel.streamflyer.regex.addons.tokens.MatchResultWithOffset;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.regex.addons.tokens;
/**
* Tests {@link MatchResultWithOffset}.
*
* @author rwoo
*
*/
public class MatchResultWithOffsetTest {
/**
* Test for the unexpected behaviour of empty groups
*
* @throws Exception
*/
@Test
public void testGroupCountAndMore_UNEXPECTED_emptyGroupsAfterEndOfTargetGroupIncluded() throws Exception {
String input = "1xxnnnnnnnnnn";
String regex = "(1xx())()";
Matcher matcher = Pattern.compile(regex).matcher(input);
assertTrue(matcher.find());
assertEquals(3, matcher.groupCount()); // principle of the longest possible match
{
// offset = 1 -> "1xx" will be the match result
|
MatchResultWithOffset mo = new MatchResultWithOffset(matcher, 1);
|
rwitzel/streamflyer
|
streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifierTest.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/core/Modifier.java
// public interface Modifier {
//
// /**
// * Processes the characters in the given character buffer, i.e. deletes or replaces or inserts characters, or keeps
// * the characters as they are.
// *
// * @param characterBuffer
// * The next characters provided from the modifiable stream. It contains the modifiable characters,
// * (optionally) preceded by unmodifiable characters.
// * <p>
// * The modifier can modify the content of the buffer as appropriate the modifier must not modify the
// * unmodifiable characters, i.e. the characters before position
// * <code>firstModifiableCharacterInBufferIndex</code> must not be modified.
// * <p>
// * Your modifier should manage the {@link StringBuilder#capacity() capacity} of the buffer on its own -
// * as the optimal management of the capacity depends on the specific purpose of the modifier.
// * <p>
// * The given buffer must be never null.
// * @param firstModifiableCharacterInBuffer
// * index of the first modifiable character in the buffer. The index of the first character in the buffer
// * is zero. If there is not modifiable character in the buffer, then this value is equal the length of
// * the buffer.
// * @param endOfStreamHit
// * True if no more characters can be read from the stream, i.e. the character buffer contains the all the
// * characters up to the end of the stream.
// * @return Returns an object that defines how {@link ModifyingReader} or {@link ModifyingWriter} shall behave before
// * calling {@link Modifier#modify(StringBuilder, int, boolean)} again.
// */
// public AfterModification modify(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
// boolean endOfStreamHit);
// }
//
// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifier.java
// @Deprecated
// public class RangeFilterModifier extends HandlerAwareModifier {
//
// public RangeFilterModifier(String startRegex, String endRegex, boolean includeStartToken, boolean includeEndToken,
// boolean initiallyBetweenStartAndEnd, int minimumLengthOfLookBehind, int newNumberOfChars) {
// super();
//
// // define the behaviour for matched tokens and noMatches
// RangeFilterHandler handler = new RangeFilterHandler(initiallyBetweenStartAndEnd, includeStartToken,
// includeEndToken, minimumLengthOfLookBehind, newNumberOfChars);
//
// // define the tokens
// List<Token> tokens = new ArrayList<Token>();
// tokens.add(new Token("Start", startRegex));
// tokens.add(new Token("End", endRegex));
//
// // initialize the handler aware modifier
// initialize(tokens, handler, minimumLengthOfLookBehind, newNumberOfChars);
// }
//
// }
|
import com.github.rwitzel.streamflyer.core.Modifier;
import com.github.rwitzel.streamflyer.experimental.range2.RangeFilterModifier;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.range2;
/**
* Tests {@link RangeFilterModifier}.
*
* @author rwoo
*
*/
public class RangeFilterModifierTest extends com.github.rwitzel.streamflyer.experimental.range.RangeFilterModifierTest {
@Override
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/core/Modifier.java
// public interface Modifier {
//
// /**
// * Processes the characters in the given character buffer, i.e. deletes or replaces or inserts characters, or keeps
// * the characters as they are.
// *
// * @param characterBuffer
// * The next characters provided from the modifiable stream. It contains the modifiable characters,
// * (optionally) preceded by unmodifiable characters.
// * <p>
// * The modifier can modify the content of the buffer as appropriate the modifier must not modify the
// * unmodifiable characters, i.e. the characters before position
// * <code>firstModifiableCharacterInBufferIndex</code> must not be modified.
// * <p>
// * Your modifier should manage the {@link StringBuilder#capacity() capacity} of the buffer on its own -
// * as the optimal management of the capacity depends on the specific purpose of the modifier.
// * <p>
// * The given buffer must be never null.
// * @param firstModifiableCharacterInBuffer
// * index of the first modifiable character in the buffer. The index of the first character in the buffer
// * is zero. If there is not modifiable character in the buffer, then this value is equal the length of
// * the buffer.
// * @param endOfStreamHit
// * True if no more characters can be read from the stream, i.e. the character buffer contains the all the
// * characters up to the end of the stream.
// * @return Returns an object that defines how {@link ModifyingReader} or {@link ModifyingWriter} shall behave before
// * calling {@link Modifier#modify(StringBuilder, int, boolean)} again.
// */
// public AfterModification modify(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
// boolean endOfStreamHit);
// }
//
// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifier.java
// @Deprecated
// public class RangeFilterModifier extends HandlerAwareModifier {
//
// public RangeFilterModifier(String startRegex, String endRegex, boolean includeStartToken, boolean includeEndToken,
// boolean initiallyBetweenStartAndEnd, int minimumLengthOfLookBehind, int newNumberOfChars) {
// super();
//
// // define the behaviour for matched tokens and noMatches
// RangeFilterHandler handler = new RangeFilterHandler(initiallyBetweenStartAndEnd, includeStartToken,
// includeEndToken, minimumLengthOfLookBehind, newNumberOfChars);
//
// // define the tokens
// List<Token> tokens = new ArrayList<Token>();
// tokens.add(new Token("Start", startRegex));
// tokens.add(new Token("End", endRegex));
//
// // initialize the handler aware modifier
// initialize(tokens, handler, minimumLengthOfLookBehind, newNumberOfChars);
// }
//
// }
// Path: streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifierTest.java
import com.github.rwitzel.streamflyer.core.Modifier;
import com.github.rwitzel.streamflyer.experimental.range2.RangeFilterModifier;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.range2;
/**
* Tests {@link RangeFilterModifier}.
*
* @author rwoo
*
*/
public class RangeFilterModifierTest extends com.github.rwitzel.streamflyer.experimental.range.RangeFilterModifierTest {
@Override
|
protected Modifier createModifier(String startTag, String endTag, boolean includeStart, boolean includeEnd,
|
rwitzel/streamflyer
|
streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifierTest.java
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/core/Modifier.java
// public interface Modifier {
//
// /**
// * Processes the characters in the given character buffer, i.e. deletes or replaces or inserts characters, or keeps
// * the characters as they are.
// *
// * @param characterBuffer
// * The next characters provided from the modifiable stream. It contains the modifiable characters,
// * (optionally) preceded by unmodifiable characters.
// * <p>
// * The modifier can modify the content of the buffer as appropriate the modifier must not modify the
// * unmodifiable characters, i.e. the characters before position
// * <code>firstModifiableCharacterInBufferIndex</code> must not be modified.
// * <p>
// * Your modifier should manage the {@link StringBuilder#capacity() capacity} of the buffer on its own -
// * as the optimal management of the capacity depends on the specific purpose of the modifier.
// * <p>
// * The given buffer must be never null.
// * @param firstModifiableCharacterInBuffer
// * index of the first modifiable character in the buffer. The index of the first character in the buffer
// * is zero. If there is not modifiable character in the buffer, then this value is equal the length of
// * the buffer.
// * @param endOfStreamHit
// * True if no more characters can be read from the stream, i.e. the character buffer contains the all the
// * characters up to the end of the stream.
// * @return Returns an object that defines how {@link ModifyingReader} or {@link ModifyingWriter} shall behave before
// * calling {@link Modifier#modify(StringBuilder, int, boolean)} again.
// */
// public AfterModification modify(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
// boolean endOfStreamHit);
// }
//
// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifier.java
// @Deprecated
// public class RangeFilterModifier extends HandlerAwareModifier {
//
// public RangeFilterModifier(String startRegex, String endRegex, boolean includeStartToken, boolean includeEndToken,
// boolean initiallyBetweenStartAndEnd, int minimumLengthOfLookBehind, int newNumberOfChars) {
// super();
//
// // define the behaviour for matched tokens and noMatches
// RangeFilterHandler handler = new RangeFilterHandler(initiallyBetweenStartAndEnd, includeStartToken,
// includeEndToken, minimumLengthOfLookBehind, newNumberOfChars);
//
// // define the tokens
// List<Token> tokens = new ArrayList<Token>();
// tokens.add(new Token("Start", startRegex));
// tokens.add(new Token("End", endRegex));
//
// // initialize the handler aware modifier
// initialize(tokens, handler, minimumLengthOfLookBehind, newNumberOfChars);
// }
//
// }
|
import com.github.rwitzel.streamflyer.core.Modifier;
import com.github.rwitzel.streamflyer.experimental.range2.RangeFilterModifier;
|
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.range2;
/**
* Tests {@link RangeFilterModifier}.
*
* @author rwoo
*
*/
public class RangeFilterModifierTest extends com.github.rwitzel.streamflyer.experimental.range.RangeFilterModifierTest {
@Override
protected Modifier createModifier(String startTag, String endTag, boolean includeStart, boolean includeEnd,
boolean initiallyOn) {
|
// Path: streamflyer-core/src/main/java/com/github/rwitzel/streamflyer/core/Modifier.java
// public interface Modifier {
//
// /**
// * Processes the characters in the given character buffer, i.e. deletes or replaces or inserts characters, or keeps
// * the characters as they are.
// *
// * @param characterBuffer
// * The next characters provided from the modifiable stream. It contains the modifiable characters,
// * (optionally) preceded by unmodifiable characters.
// * <p>
// * The modifier can modify the content of the buffer as appropriate the modifier must not modify the
// * unmodifiable characters, i.e. the characters before position
// * <code>firstModifiableCharacterInBufferIndex</code> must not be modified.
// * <p>
// * Your modifier should manage the {@link StringBuilder#capacity() capacity} of the buffer on its own -
// * as the optimal management of the capacity depends on the specific purpose of the modifier.
// * <p>
// * The given buffer must be never null.
// * @param firstModifiableCharacterInBuffer
// * index of the first modifiable character in the buffer. The index of the first character in the buffer
// * is zero. If there is not modifiable character in the buffer, then this value is equal the length of
// * the buffer.
// * @param endOfStreamHit
// * True if no more characters can be read from the stream, i.e. the character buffer contains the all the
// * characters up to the end of the stream.
// * @return Returns an object that defines how {@link ModifyingReader} or {@link ModifyingWriter} shall behave before
// * calling {@link Modifier#modify(StringBuilder, int, boolean)} again.
// */
// public AfterModification modify(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
// boolean endOfStreamHit);
// }
//
// Path: streamflyer-experimental/src/main/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifier.java
// @Deprecated
// public class RangeFilterModifier extends HandlerAwareModifier {
//
// public RangeFilterModifier(String startRegex, String endRegex, boolean includeStartToken, boolean includeEndToken,
// boolean initiallyBetweenStartAndEnd, int minimumLengthOfLookBehind, int newNumberOfChars) {
// super();
//
// // define the behaviour for matched tokens and noMatches
// RangeFilterHandler handler = new RangeFilterHandler(initiallyBetweenStartAndEnd, includeStartToken,
// includeEndToken, minimumLengthOfLookBehind, newNumberOfChars);
//
// // define the tokens
// List<Token> tokens = new ArrayList<Token>();
// tokens.add(new Token("Start", startRegex));
// tokens.add(new Token("End", endRegex));
//
// // initialize the handler aware modifier
// initialize(tokens, handler, minimumLengthOfLookBehind, newNumberOfChars);
// }
//
// }
// Path: streamflyer-experimental/src/test/java/com/github/rwitzel/streamflyer/experimental/range2/RangeFilterModifierTest.java
import com.github.rwitzel.streamflyer.core.Modifier;
import com.github.rwitzel.streamflyer.experimental.range2.RangeFilterModifier;
/**
* Copyright (C) 2011 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.rwitzel.streamflyer.experimental.range2;
/**
* Tests {@link RangeFilterModifier}.
*
* @author rwoo
*
*/
public class RangeFilterModifierTest extends com.github.rwitzel.streamflyer.experimental.range.RangeFilterModifierTest {
@Override
protected Modifier createModifier(String startTag, String endTag, boolean includeStart, boolean includeEnd,
boolean initiallyOn) {
|
return new RangeFilterModifier(startTag, endTag, includeStart, includeEnd, initiallyOn, 1, 2048);
|
okumin/influent
|
influent-transport/src/main/java/influent/internal/nio/NioUdpChannel.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/util/Exceptions.java
// public final class Exceptions {
// /**
// * A callable block.
// *
// * <p>This is the same as {@code Runnable} except that {@code Block#run} may throw some {@code
// * Exception}.
// */
// @FunctionalInterface
// public interface Block {
// void run() throws Exception;
// }
//
// /** Boolean specialized callable. */
// @FunctionalInterface
// public interface BooleanCallable {
// boolean call() throws Exception;
// }
//
// private static final Logger logger = LoggerFactory.getLogger(Exceptions.class);
//
// private Exceptions() {
// throw new AssertionError();
// }
//
// /**
// * Executes the given processing and discards the error when some error occurs.
// *
// * @param f the processing
// * @param messageOnError the error message to be logged on an error
// */
// public static void ignore(final Block f, final String messageOnError) {
// try {
// f.run();
// } catch (final Exception e) {
// logger.error(messageOnError, e);
// }
// }
//
// /**
// * Executes the given processing and return null if the processing throws an exception.
// *
// * @param f the processing
// * @param <T> the type of the {@code Callable}
// * @return the return value of {@code f} or null when {@code f} fails
// */
// public static <T> T orNull(final Callable<T> f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return null;
// }
// }
//
// /**
// * Executes the given processing and return false if the processing throws an exception.
// *
// * @param f the processing
// * @return true if {@code f} returns true
// */
// public static boolean orFalse(final BooleanCallable f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return false;
// }
// }
// }
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import influent.exception.InfluentIOException;
import influent.internal.util.Exceptions;
import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.AlreadyBoundException;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.Optional;
import java.util.Set;
|
*/
public void register(final Set<Op> ops, final NioAttachment attachment) {
eventLoop.register(channel, key, Op.bits(ops), attachment);
}
/**
* Enables the given operation.
*
* <p>Operations are done asynchronously.
*
* @param op the operation to be enabled
*/
public void enable(final Op op) {
eventLoop.enableInterestSet(key, op.getBit());
}
/**
* Disables the given operation.
*
* <p>Operations are done asynchronously.
*
* @param op the operation to be enabled
*/
public void disable(final Op op) {
eventLoop.disableInterestSet(key, op.getBit());
}
/** Closes the {@code DatagramChannel}. */
@Override
public void close() {
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/util/Exceptions.java
// public final class Exceptions {
// /**
// * A callable block.
// *
// * <p>This is the same as {@code Runnable} except that {@code Block#run} may throw some {@code
// * Exception}.
// */
// @FunctionalInterface
// public interface Block {
// void run() throws Exception;
// }
//
// /** Boolean specialized callable. */
// @FunctionalInterface
// public interface BooleanCallable {
// boolean call() throws Exception;
// }
//
// private static final Logger logger = LoggerFactory.getLogger(Exceptions.class);
//
// private Exceptions() {
// throw new AssertionError();
// }
//
// /**
// * Executes the given processing and discards the error when some error occurs.
// *
// * @param f the processing
// * @param messageOnError the error message to be logged on an error
// */
// public static void ignore(final Block f, final String messageOnError) {
// try {
// f.run();
// } catch (final Exception e) {
// logger.error(messageOnError, e);
// }
// }
//
// /**
// * Executes the given processing and return null if the processing throws an exception.
// *
// * @param f the processing
// * @param <T> the type of the {@code Callable}
// * @return the return value of {@code f} or null when {@code f} fails
// */
// public static <T> T orNull(final Callable<T> f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return null;
// }
// }
//
// /**
// * Executes the given processing and return false if the processing throws an exception.
// *
// * @param f the processing
// * @return true if {@code f} returns true
// */
// public static boolean orFalse(final BooleanCallable f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return false;
// }
// }
// }
// Path: influent-transport/src/main/java/influent/internal/nio/NioUdpChannel.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import influent.exception.InfluentIOException;
import influent.internal.util.Exceptions;
import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.AlreadyBoundException;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.UnsupportedAddressTypeException;
import java.util.Optional;
import java.util.Set;
*/
public void register(final Set<Op> ops, final NioAttachment attachment) {
eventLoop.register(channel, key, Op.bits(ops), attachment);
}
/**
* Enables the given operation.
*
* <p>Operations are done asynchronously.
*
* @param op the operation to be enabled
*/
public void enable(final Op op) {
eventLoop.enableInterestSet(key, op.getBit());
}
/**
* Disables the given operation.
*
* <p>Operations are done asynchronously.
*
* @param op the operation to be enabled
*/
public void disable(final Op op) {
eventLoop.disableInterestSet(key, op.getBit());
}
/** Closes the {@code DatagramChannel}. */
@Override
public void close() {
|
Exceptions.ignore(
|
okumin/influent
|
influent-transport/src/main/java/influent/internal/nio/NioTcpPlaintextChannel.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/util/Exceptions.java
// public final class Exceptions {
// /**
// * A callable block.
// *
// * <p>This is the same as {@code Runnable} except that {@code Block#run} may throw some {@code
// * Exception}.
// */
// @FunctionalInterface
// public interface Block {
// void run() throws Exception;
// }
//
// /** Boolean specialized callable. */
// @FunctionalInterface
// public interface BooleanCallable {
// boolean call() throws Exception;
// }
//
// private static final Logger logger = LoggerFactory.getLogger(Exceptions.class);
//
// private Exceptions() {
// throw new AssertionError();
// }
//
// /**
// * Executes the given processing and discards the error when some error occurs.
// *
// * @param f the processing
// * @param messageOnError the error message to be logged on an error
// */
// public static void ignore(final Block f, final String messageOnError) {
// try {
// f.run();
// } catch (final Exception e) {
// logger.error(messageOnError, e);
// }
// }
//
// /**
// * Executes the given processing and return null if the processing throws an exception.
// *
// * @param f the processing
// * @param <T> the type of the {@code Callable}
// * @return the return value of {@code f} or null when {@code f} fails
// */
// public static <T> T orNull(final Callable<T> f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return null;
// }
// }
//
// /**
// * Executes the given processing and return false if the processing throws an exception.
// *
// * @param f the processing
// * @return true if {@code f} returns true
// */
// public static boolean orFalse(final BooleanCallable f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return false;
// }
// }
// }
|
import influent.exception.InfluentIOException;
import influent.internal.util.Exceptions;
import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.SocketChannel;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.nio;
/** A non-blocking {@code SocketChannel}. */
public final class NioTcpPlaintextChannel implements NioTcpChannel {
private static final Logger logger = LoggerFactory.getLogger(NioTcpPlaintextChannel.class);
private final SocketChannel channel;
private final NioEventLoop eventLoop;
private final SocketAddress remoteAddress;
final NioSelectionKey key = NioSelectionKey.create();
NioTcpPlaintextChannel(
final SocketChannel channel,
final NioEventLoop eventLoop,
final SocketAddress remoteAddress) {
this.channel = channel;
this.eventLoop = eventLoop;
this.remoteAddress = remoteAddress;
}
private static SocketAddress getRemoteAddress(final SocketChannel channel) {
try {
return channel.getRemoteAddress();
} catch (final IOException e) {
// ClosedChannelException is an IOException
throw new InfluentIOException("SocketChannel#getRemoteAddress failed", e);
}
}
private static <T> void setOption(
final SocketChannel channel, final SocketOption<T> name, final T value) {
try {
channel.setOption(name, value);
} catch (final UnsupportedOperationException | IllegalArgumentException e) {
throw new AssertionError(e);
} catch (final IOException e) {
// ClosedChannelException is an IOException
throw new InfluentIOException("SocketChannel#setOption failed", e);
}
}
/**
* Creates a new {@code NioTcpPlaintextChannel}.
*
* @param channel the accepted {@code SocketChannel}
* @param eventLoop the {@code NioEventLoop}
* @param tcpConfig the {@code NioTcpConfig}
* @throws InfluentIOException if some IO error occurs
*/
public static NioTcpPlaintextChannel open(
final SocketChannel channel, final NioEventLoop eventLoop, final NioTcpConfig tcpConfig) {
try {
final SocketAddress remoteAddress = getRemoteAddress(channel);
tcpConfig
.getSendBufferSize()
.ifPresent(
(sendBufferSize) ->
setOption(channel, StandardSocketOptions.SO_SNDBUF, sendBufferSize));
setOption(channel, StandardSocketOptions.SO_KEEPALIVE, tcpConfig.getKeepAliveEnabled());
setOption(channel, StandardSocketOptions.TCP_NODELAY, tcpConfig.getTcpNoDelayEnabled());
return new NioTcpPlaintextChannel(channel, eventLoop, remoteAddress);
} catch (final Exception e) {
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/util/Exceptions.java
// public final class Exceptions {
// /**
// * A callable block.
// *
// * <p>This is the same as {@code Runnable} except that {@code Block#run} may throw some {@code
// * Exception}.
// */
// @FunctionalInterface
// public interface Block {
// void run() throws Exception;
// }
//
// /** Boolean specialized callable. */
// @FunctionalInterface
// public interface BooleanCallable {
// boolean call() throws Exception;
// }
//
// private static final Logger logger = LoggerFactory.getLogger(Exceptions.class);
//
// private Exceptions() {
// throw new AssertionError();
// }
//
// /**
// * Executes the given processing and discards the error when some error occurs.
// *
// * @param f the processing
// * @param messageOnError the error message to be logged on an error
// */
// public static void ignore(final Block f, final String messageOnError) {
// try {
// f.run();
// } catch (final Exception e) {
// logger.error(messageOnError, e);
// }
// }
//
// /**
// * Executes the given processing and return null if the processing throws an exception.
// *
// * @param f the processing
// * @param <T> the type of the {@code Callable}
// * @return the return value of {@code f} or null when {@code f} fails
// */
// public static <T> T orNull(final Callable<T> f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return null;
// }
// }
//
// /**
// * Executes the given processing and return false if the processing throws an exception.
// *
// * @param f the processing
// * @return true if {@code f} returns true
// */
// public static boolean orFalse(final BooleanCallable f) {
// try {
// return f.call();
// } catch (final Exception e) {
// return false;
// }
// }
// }
// Path: influent-transport/src/main/java/influent/internal/nio/NioTcpPlaintextChannel.java
import influent.exception.InfluentIOException;
import influent.internal.util.Exceptions;
import java.io.IOException;
import java.net.SocketAddress;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.NotYetConnectedException;
import java.nio.channels.SocketChannel;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.nio;
/** A non-blocking {@code SocketChannel}. */
public final class NioTcpPlaintextChannel implements NioTcpChannel {
private static final Logger logger = LoggerFactory.getLogger(NioTcpPlaintextChannel.class);
private final SocketChannel channel;
private final NioEventLoop eventLoop;
private final SocketAddress remoteAddress;
final NioSelectionKey key = NioSelectionKey.create();
NioTcpPlaintextChannel(
final SocketChannel channel,
final NioEventLoop eventLoop,
final SocketAddress remoteAddress) {
this.channel = channel;
this.eventLoop = eventLoop;
this.remoteAddress = remoteAddress;
}
private static SocketAddress getRemoteAddress(final SocketChannel channel) {
try {
return channel.getRemoteAddress();
} catch (final IOException e) {
// ClosedChannelException is an IOException
throw new InfluentIOException("SocketChannel#getRemoteAddress failed", e);
}
}
private static <T> void setOption(
final SocketChannel channel, final SocketOption<T> name, final T value) {
try {
channel.setOption(name, value);
} catch (final UnsupportedOperationException | IllegalArgumentException e) {
throw new AssertionError(e);
} catch (final IOException e) {
// ClosedChannelException is an IOException
throw new InfluentIOException("SocketChannel#setOption failed", e);
}
}
/**
* Creates a new {@code NioTcpPlaintextChannel}.
*
* @param channel the accepted {@code SocketChannel}
* @param eventLoop the {@code NioEventLoop}
* @param tcpConfig the {@code NioTcpConfig}
* @throws InfluentIOException if some IO error occurs
*/
public static NioTcpPlaintextChannel open(
final SocketChannel channel, final NioEventLoop eventLoop, final NioTcpConfig tcpConfig) {
try {
final SocketAddress remoteAddress = getRemoteAddress(channel);
tcpConfig
.getSendBufferSize()
.ifPresent(
(sendBufferSize) ->
setOption(channel, StandardSocketOptions.SO_SNDBUF, sendBufferSize));
setOption(channel, StandardSocketOptions.SO_KEEPALIVE, tcpConfig.getKeepAliveEnabled());
setOption(channel, StandardSocketOptions.TCP_NODELAY, tcpConfig.getTcpNoDelayEnabled());
return new NioTcpPlaintextChannel(channel, eventLoop, remoteAddress);
} catch (final Exception e) {
|
closeChannel(channel, Exceptions.orNull(channel::getRemoteAddress));
|
okumin/influent
|
influent-java/src/main/java/influent/internal/msgpack/MsgpackStreamUnpacker.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/nio/NioTcpChannel.java
// public interface NioTcpChannel extends AutoCloseable {
// enum Op {
// /** OP_READ */
// READ(SelectionKey.OP_READ),
// /** OP_WRITE */
// WRITE(SelectionKey.OP_WRITE);
//
// private final int bit;
//
// Op(final int bit) {
// this.bit = bit;
// }
//
// int getBit() {
// return bit;
// }
//
// static int bits(final Set<Op> ops) {
// return ops.stream().mapToInt(Op::getBit).reduce(0, (x, y) -> x | y);
// }
// }
//
// /**
// * Writes bytes to the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param src the buffer
// * @return true when some bytes are written
// * @throws InfluentIOException if some IO error occurs
// */
// boolean write(final ByteBuffer src);
//
// /**
// * Reads bytes from the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param dst the buffer
// * @return true when some bytes are read
// * @throws InfluentIOException if some IO error occurs
// */
// boolean read(final ByteBuffer dst);
//
// /**
// * Registers the this channel to the given {@code NioEventLoop}.
// *
// * <p>This method is thread-safe.
// *
// * @param ops the operations to be enabled
// * @param attachment the {@code NioAttachment}
// */
// void register(final Set<Op> ops, final NioAttachment attachment);
//
// /**
// * Enables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be enabled
// */
// void enable(final Op op);
//
// /**
// * Disables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be disabled
// */
// void disable(final Op op);
//
// /**
// * Closes the {@code SocketChannel}.
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// @Override
// void close();
//
// /**
// * Returns true if this channel is open
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// boolean isOpen();
//
// /**
// * Returns the remote address
// *
// * <p>This method is thread-safe.
// */
// SocketAddress getRemoteAddress();
// }
|
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.function.Supplier;
import org.msgpack.value.ImmutableValue;
import influent.exception.InfluentIOException;
import influent.internal.nio.NioTcpChannel;
|
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.msgpack;
/**
* An unpacker for a MessagePack stream.
*
* <p>This is expected to be used in only Influent project.
*
* <p>{@code MsgpackStreamUnpacker} is not thread-safe.
*/
public final class MsgpackStreamUnpacker {
private final InfluentByteBuffer buffer;
private final long chunkSizeLimit;
private final Queue<ImmutableValue> unpackedValues = new LinkedList<>();
private MsgpackIncrementalUnpacker currentUnpacker = FormatUnpacker.getInstance();
private long currentChunkSize = 0;
/**
* Constructs a new {@code MsgpackStreamUnpacker}.
*
* @param chunkSizeLimit the allowable chunk size {@code feed} fails when the size of reading
* chunk exceeds the limit
*/
public MsgpackStreamUnpacker(final long chunkSizeLimit) {
this.buffer = new InfluentByteBuffer(chunkSizeLimit);
this.chunkSizeLimit = chunkSizeLimit;
}
/**
* Reads buffers from a {@code ReadableByteChannel}.
*
* @param supplier supplier to produce ByteBuffer
* @param channel channel
* @throws InfluentIOException when it fails reading from the channel or the chunk size exceeds
* the limit
*/
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/nio/NioTcpChannel.java
// public interface NioTcpChannel extends AutoCloseable {
// enum Op {
// /** OP_READ */
// READ(SelectionKey.OP_READ),
// /** OP_WRITE */
// WRITE(SelectionKey.OP_WRITE);
//
// private final int bit;
//
// Op(final int bit) {
// this.bit = bit;
// }
//
// int getBit() {
// return bit;
// }
//
// static int bits(final Set<Op> ops) {
// return ops.stream().mapToInt(Op::getBit).reduce(0, (x, y) -> x | y);
// }
// }
//
// /**
// * Writes bytes to the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param src the buffer
// * @return true when some bytes are written
// * @throws InfluentIOException if some IO error occurs
// */
// boolean write(final ByteBuffer src);
//
// /**
// * Reads bytes from the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param dst the buffer
// * @return true when some bytes are read
// * @throws InfluentIOException if some IO error occurs
// */
// boolean read(final ByteBuffer dst);
//
// /**
// * Registers the this channel to the given {@code NioEventLoop}.
// *
// * <p>This method is thread-safe.
// *
// * @param ops the operations to be enabled
// * @param attachment the {@code NioAttachment}
// */
// void register(final Set<Op> ops, final NioAttachment attachment);
//
// /**
// * Enables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be enabled
// */
// void enable(final Op op);
//
// /**
// * Disables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be disabled
// */
// void disable(final Op op);
//
// /**
// * Closes the {@code SocketChannel}.
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// @Override
// void close();
//
// /**
// * Returns true if this channel is open
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// boolean isOpen();
//
// /**
// * Returns the remote address
// *
// * <p>This method is thread-safe.
// */
// SocketAddress getRemoteAddress();
// }
// Path: influent-java/src/main/java/influent/internal/msgpack/MsgpackStreamUnpacker.java
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.function.Supplier;
import org.msgpack.value.ImmutableValue;
import influent.exception.InfluentIOException;
import influent.internal.nio.NioTcpChannel;
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.msgpack;
/**
* An unpacker for a MessagePack stream.
*
* <p>This is expected to be used in only Influent project.
*
* <p>{@code MsgpackStreamUnpacker} is not thread-safe.
*/
public final class MsgpackStreamUnpacker {
private final InfluentByteBuffer buffer;
private final long chunkSizeLimit;
private final Queue<ImmutableValue> unpackedValues = new LinkedList<>();
private MsgpackIncrementalUnpacker currentUnpacker = FormatUnpacker.getInstance();
private long currentChunkSize = 0;
/**
* Constructs a new {@code MsgpackStreamUnpacker}.
*
* @param chunkSizeLimit the allowable chunk size {@code feed} fails when the size of reading
* chunk exceeds the limit
*/
public MsgpackStreamUnpacker(final long chunkSizeLimit) {
this.buffer = new InfluentByteBuffer(chunkSizeLimit);
this.chunkSizeLimit = chunkSizeLimit;
}
/**
* Reads buffers from a {@code ReadableByteChannel}.
*
* @param supplier supplier to produce ByteBuffer
* @param channel channel
* @throws InfluentIOException when it fails reading from the channel or the chunk size exceeds
* the limit
*/
|
public void feed(final Supplier<ByteBuffer> supplier, final NioTcpChannel channel) {
|
okumin/influent
|
influent-java/src/main/java/influent/internal/msgpack/MsgpackStreamUnpacker.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/nio/NioTcpChannel.java
// public interface NioTcpChannel extends AutoCloseable {
// enum Op {
// /** OP_READ */
// READ(SelectionKey.OP_READ),
// /** OP_WRITE */
// WRITE(SelectionKey.OP_WRITE);
//
// private final int bit;
//
// Op(final int bit) {
// this.bit = bit;
// }
//
// int getBit() {
// return bit;
// }
//
// static int bits(final Set<Op> ops) {
// return ops.stream().mapToInt(Op::getBit).reduce(0, (x, y) -> x | y);
// }
// }
//
// /**
// * Writes bytes to the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param src the buffer
// * @return true when some bytes are written
// * @throws InfluentIOException if some IO error occurs
// */
// boolean write(final ByteBuffer src);
//
// /**
// * Reads bytes from the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param dst the buffer
// * @return true when some bytes are read
// * @throws InfluentIOException if some IO error occurs
// */
// boolean read(final ByteBuffer dst);
//
// /**
// * Registers the this channel to the given {@code NioEventLoop}.
// *
// * <p>This method is thread-safe.
// *
// * @param ops the operations to be enabled
// * @param attachment the {@code NioAttachment}
// */
// void register(final Set<Op> ops, final NioAttachment attachment);
//
// /**
// * Enables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be enabled
// */
// void enable(final Op op);
//
// /**
// * Disables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be disabled
// */
// void disable(final Op op);
//
// /**
// * Closes the {@code SocketChannel}.
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// @Override
// void close();
//
// /**
// * Returns true if this channel is open
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// boolean isOpen();
//
// /**
// * Returns the remote address
// *
// * <p>This method is thread-safe.
// */
// SocketAddress getRemoteAddress();
// }
|
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.function.Supplier;
import org.msgpack.value.ImmutableValue;
import influent.exception.InfluentIOException;
import influent.internal.nio.NioTcpChannel;
|
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.msgpack;
/**
* An unpacker for a MessagePack stream.
*
* <p>This is expected to be used in only Influent project.
*
* <p>{@code MsgpackStreamUnpacker} is not thread-safe.
*/
public final class MsgpackStreamUnpacker {
private final InfluentByteBuffer buffer;
private final long chunkSizeLimit;
private final Queue<ImmutableValue> unpackedValues = new LinkedList<>();
private MsgpackIncrementalUnpacker currentUnpacker = FormatUnpacker.getInstance();
private long currentChunkSize = 0;
/**
* Constructs a new {@code MsgpackStreamUnpacker}.
*
* @param chunkSizeLimit the allowable chunk size {@code feed} fails when the size of reading
* chunk exceeds the limit
*/
public MsgpackStreamUnpacker(final long chunkSizeLimit) {
this.buffer = new InfluentByteBuffer(chunkSizeLimit);
this.chunkSizeLimit = chunkSizeLimit;
}
/**
* Reads buffers from a {@code ReadableByteChannel}.
*
* @param supplier supplier to produce ByteBuffer
* @param channel channel
* @throws InfluentIOException when it fails reading from the channel or the chunk size exceeds
* the limit
*/
public void feed(final Supplier<ByteBuffer> supplier, final NioTcpChannel channel) {
boolean toBeContinued = true;
while (toBeContinued) {
toBeContinued = buffer.feed(supplier);
unpack(channel);
}
}
// fails when the chunk size exceeds the limit
private void unpack(final NioTcpChannel channel) {
while (buffer.hasRemaining()) {
try {
currentChunkSize += buffer.remaining();
final DecodeResult result = currentUnpacker.unpack(buffer);
currentChunkSize -= buffer.remaining();
if (result.isCompleted()) {
unpackedValues.offer(result.value());
currentUnpacker = FormatUnpacker.getInstance();
currentChunkSize = 0;
} else if (currentChunkSize >= chunkSizeLimit) {
channel.close();
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/nio/NioTcpChannel.java
// public interface NioTcpChannel extends AutoCloseable {
// enum Op {
// /** OP_READ */
// READ(SelectionKey.OP_READ),
// /** OP_WRITE */
// WRITE(SelectionKey.OP_WRITE);
//
// private final int bit;
//
// Op(final int bit) {
// this.bit = bit;
// }
//
// int getBit() {
// return bit;
// }
//
// static int bits(final Set<Op> ops) {
// return ops.stream().mapToInt(Op::getBit).reduce(0, (x, y) -> x | y);
// }
// }
//
// /**
// * Writes bytes to the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param src the buffer
// * @return true when some bytes are written
// * @throws InfluentIOException if some IO error occurs
// */
// boolean write(final ByteBuffer src);
//
// /**
// * Reads bytes from the socket buffer.
// *
// * <p>This method is not guaranteed to be thread-safe.
// *
// * @param dst the buffer
// * @return true when some bytes are read
// * @throws InfluentIOException if some IO error occurs
// */
// boolean read(final ByteBuffer dst);
//
// /**
// * Registers the this channel to the given {@code NioEventLoop}.
// *
// * <p>This method is thread-safe.
// *
// * @param ops the operations to be enabled
// * @param attachment the {@code NioAttachment}
// */
// void register(final Set<Op> ops, final NioAttachment attachment);
//
// /**
// * Enables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be enabled
// */
// void enable(final Op op);
//
// /**
// * Disables the given operation.
// *
// * <p>This method is thread-safe and operations are done asynchronously.
// *
// * @param op the operation to be disabled
// */
// void disable(final Op op);
//
// /**
// * Closes the {@code SocketChannel}.
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// @Override
// void close();
//
// /**
// * Returns true if this channel is open
// *
// * <p>This method is not guaranteed to be thread-safe.
// */
// boolean isOpen();
//
// /**
// * Returns the remote address
// *
// * <p>This method is thread-safe.
// */
// SocketAddress getRemoteAddress();
// }
// Path: influent-java/src/main/java/influent/internal/msgpack/MsgpackStreamUnpacker.java
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.function.Supplier;
import org.msgpack.value.ImmutableValue;
import influent.exception.InfluentIOException;
import influent.internal.nio.NioTcpChannel;
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.msgpack;
/**
* An unpacker for a MessagePack stream.
*
* <p>This is expected to be used in only Influent project.
*
* <p>{@code MsgpackStreamUnpacker} is not thread-safe.
*/
public final class MsgpackStreamUnpacker {
private final InfluentByteBuffer buffer;
private final long chunkSizeLimit;
private final Queue<ImmutableValue> unpackedValues = new LinkedList<>();
private MsgpackIncrementalUnpacker currentUnpacker = FormatUnpacker.getInstance();
private long currentChunkSize = 0;
/**
* Constructs a new {@code MsgpackStreamUnpacker}.
*
* @param chunkSizeLimit the allowable chunk size {@code feed} fails when the size of reading
* chunk exceeds the limit
*/
public MsgpackStreamUnpacker(final long chunkSizeLimit) {
this.buffer = new InfluentByteBuffer(chunkSizeLimit);
this.chunkSizeLimit = chunkSizeLimit;
}
/**
* Reads buffers from a {@code ReadableByteChannel}.
*
* @param supplier supplier to produce ByteBuffer
* @param channel channel
* @throws InfluentIOException when it fails reading from the channel or the chunk size exceeds
* the limit
*/
public void feed(final Supplier<ByteBuffer> supplier, final NioTcpChannel channel) {
boolean toBeContinued = true;
while (toBeContinued) {
toBeContinued = buffer.feed(supplier);
unpack(channel);
}
}
// fails when the chunk size exceeds the limit
private void unpack(final NioTcpChannel channel) {
while (buffer.hasRemaining()) {
try {
currentChunkSize += buffer.remaining();
final DecodeResult result = currentUnpacker.unpack(buffer);
currentChunkSize -= buffer.remaining();
if (result.isCompleted()) {
unpackedValues.offer(result.value());
currentUnpacker = FormatUnpacker.getInstance();
currentChunkSize = 0;
} else if (currentChunkSize >= chunkSizeLimit) {
channel.close();
|
throw new InfluentIOException(
|
okumin/influent
|
influent-transport/src/main/java/influent/internal/nio/NioChannelConfig.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
|
import javax.net.ssl.SSLException;
import influent.exception.InfluentIOException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
|
this.host = host;
this.port = port;
this.sslEnabled = sslEnabled;
this.tlsVersions = tlsVersions;
this.ciphers = ciphers;
try {
if (isSslEnabled()) {
context = SSLContext.getInstance("TLS");
context.init(
createKeyManagers(keystorePath, keystorePassword, keyPassword),
null,
new SecureRandom());
}
} catch (final NoSuchAlgorithmException e) {
throw new AssertionError(e);
} catch (final KeyManagementException e) {
e.printStackTrace();
}
}
public SSLEngine createSSLEngine() {
final SSLEngine engine = context.createSSLEngine(host, port);
engine.setUseClientMode(false);
engine.setEnabledProtocols(tlsVersions);
if (ciphers != null) {
engine.setEnabledCipherSuites(ciphers);
}
try {
engine.beginHandshake();
} catch (final SSLException e) {
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
// Path: influent-transport/src/main/java/influent/internal/nio/NioChannelConfig.java
import javax.net.ssl.SSLException;
import influent.exception.InfluentIOException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
this.host = host;
this.port = port;
this.sslEnabled = sslEnabled;
this.tlsVersions = tlsVersions;
this.ciphers = ciphers;
try {
if (isSslEnabled()) {
context = SSLContext.getInstance("TLS");
context.init(
createKeyManagers(keystorePath, keystorePassword, keyPassword),
null,
new SecureRandom());
}
} catch (final NoSuchAlgorithmException e) {
throw new AssertionError(e);
} catch (final KeyManagementException e) {
e.printStackTrace();
}
}
public SSLEngine createSSLEngine() {
final SSLEngine engine = context.createSSLEngine(host, port);
engine.setUseClientMode(false);
engine.setEnabledProtocols(tlsVersions);
if (ciphers != null) {
engine.setEnabledCipherSuites(ciphers);
}
try {
engine.beginHandshake();
} catch (final SSLException e) {
|
throw new InfluentIOException("Failed beginning a handshake.", e);
|
okumin/influent
|
influent-transport/src/main/java/influent/internal/nio/NioTcpTlsChannel.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/util/ThreadSafeQueue.java
// public final class ThreadSafeQueue<E> {
// private final BlockingQueue<E> queue = new LinkedBlockingQueue<>();
//
// /**
// * Adds an element to this {@code ThreadSafeQueue}.
// *
// * @param element the element to add
// * @return {@code true} if the element was added to this queue, else {@code false}
// * @throws ClassCastException if the class of the specified element prevents it from being added
// * to this queue
// * @throws NullPointerException if the specified element is null
// * @throws IllegalArgumentException if some property of the specified element prevents it from
// * being added to this queue
// */
// public boolean enqueue(final E element) {
// return queue.offer(element);
// }
//
// /**
// * Removes the head element from this {@code ThreadSafeQueue}.
// *
// * @return the head element if this queue is non-empty, otherwise {@code null}
// */
// public E dequeue() {
// return queue.poll();
// }
//
// /**
// * Peeks the head element.
// *
// * @return the head element if this queue is non-empty, otherwise {@code null}
// */
// public E peek() {
// return queue.peek();
// }
//
// /**
// * Tests that this {@code ThreadSafeQueue} is empty.
// *
// * @return true if this {@code ThreadSafeQueue} is empty
// */
// public boolean isEmpty() {
// return queue.isEmpty();
// }
//
// /**
// * Tests that this {@code ThreadSafeQueue} is non-empty.
// *
// * @return true if this {@code ThreadSafeQueue} is non-empty
// */
// public boolean nonEmpty() {
// return !queue.isEmpty();
// }
// }
|
import influent.exception.InfluentIOException;
import influent.internal.util.ThreadSafeQueue;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLEngineResult.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
|
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.nio;
/**
* A non-blocking secure {@code SocketChannel}.
*
* <p>This implementation is naive and its performance is poor yet.
*/
public final class NioTcpTlsChannel implements NioTcpChannel {
private static final Logger logger = LoggerFactory.getLogger(NioTcpTlsChannel.class);
private final NioTcpPlaintextChannel channel;
private final NioTlsEngine engine;
private ByteBuffer inboundNetworkBuffer = newInboundNetworkBuffer();
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
//
// Path: influent-transport/src/main/java/influent/internal/util/ThreadSafeQueue.java
// public final class ThreadSafeQueue<E> {
// private final BlockingQueue<E> queue = new LinkedBlockingQueue<>();
//
// /**
// * Adds an element to this {@code ThreadSafeQueue}.
// *
// * @param element the element to add
// * @return {@code true} if the element was added to this queue, else {@code false}
// * @throws ClassCastException if the class of the specified element prevents it from being added
// * to this queue
// * @throws NullPointerException if the specified element is null
// * @throws IllegalArgumentException if some property of the specified element prevents it from
// * being added to this queue
// */
// public boolean enqueue(final E element) {
// return queue.offer(element);
// }
//
// /**
// * Removes the head element from this {@code ThreadSafeQueue}.
// *
// * @return the head element if this queue is non-empty, otherwise {@code null}
// */
// public E dequeue() {
// return queue.poll();
// }
//
// /**
// * Peeks the head element.
// *
// * @return the head element if this queue is non-empty, otherwise {@code null}
// */
// public E peek() {
// return queue.peek();
// }
//
// /**
// * Tests that this {@code ThreadSafeQueue} is empty.
// *
// * @return true if this {@code ThreadSafeQueue} is empty
// */
// public boolean isEmpty() {
// return queue.isEmpty();
// }
//
// /**
// * Tests that this {@code ThreadSafeQueue} is non-empty.
// *
// * @return true if this {@code ThreadSafeQueue} is non-empty
// */
// public boolean nonEmpty() {
// return !queue.isEmpty();
// }
// }
// Path: influent-transport/src/main/java/influent/internal/nio/NioTcpTlsChannel.java
import influent.exception.InfluentIOException;
import influent.internal.util.ThreadSafeQueue;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLEngineResult.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.nio;
/**
* A non-blocking secure {@code SocketChannel}.
*
* <p>This implementation is naive and its performance is poor yet.
*/
public final class NioTcpTlsChannel implements NioTcpChannel {
private static final Logger logger = LoggerFactory.getLogger(NioTcpTlsChannel.class);
private final NioTcpPlaintextChannel channel;
private final NioTlsEngine engine;
private ByteBuffer inboundNetworkBuffer = newInboundNetworkBuffer();
|
private final ThreadSafeQueue<ByteBuffer> outboundNetworkBuffers = new ThreadSafeQueue<>();
|
okumin/influent
|
influent-transport/src/main/java/influent/internal/nio/NioTlsEngine.java
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
|
import influent.exception.InfluentIOException;
import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLException;
|
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.nio;
/** A wrapped {@code SSLEngine}. */
public final class NioTlsEngine {
private final SSLEngine engine;
private NioTlsEngine(final SSLEngine engine) {
this.engine = engine;
}
/**
* Creates a {@code NioTlsEngine} with server mode.
*
* @param engine the {@code SSLEngine}
* @return the {@code NioTlsEngine}
*/
public static NioTlsEngine createServerEngine(final SSLEngine engine) {
if (engine.getUseClientMode()) {
// TODO: configure in this class
throw new AssertionError();
}
return new NioTlsEngine(engine);
}
/** Returns the current handshake status. */
HandshakeStatus getHandshakeStatus() {
return engine.getHandshakeStatus();
}
/**
* Encodes application data into network data.
*
* @param src application data
* @param dst network data
* @return the {@code SSLEngineResult}
* @throws InfluentIOException when some operations about TLS fails
* @throws ReadOnlyBufferException when the {@code dst} is a read-only buffer
* @throws IllegalArgumentException when the {@code src} or the {@code dst} are {@code null}
*/
SSLEngineResult wrap(final ByteBuffer src, final ByteBuffer dst) {
try {
return engine.wrap(src, dst);
} catch (final SSLException e) {
|
// Path: influent-transport/src/main/java/influent/exception/InfluentIOException.java
// public final class InfluentIOException extends RuntimeException {
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// * @param cause the cause
// */
// public InfluentIOException(final String message, final Throwable cause) {
// super(message, cause);
// }
//
// /**
// * Constructs a new {@code InfluentIOException}.
// *
// * @param message the error message
// */
// public InfluentIOException(final String message) {
// super(message);
// }
//
// /** Constructs a new {@code InfluentIOException}. */
// public InfluentIOException() {
// super();
// }
// }
// Path: influent-transport/src/main/java/influent/internal/nio/NioTlsEngine.java
import influent.exception.InfluentIOException;
import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import javax.net.ssl.SSLException;
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.internal.nio;
/** A wrapped {@code SSLEngine}. */
public final class NioTlsEngine {
private final SSLEngine engine;
private NioTlsEngine(final SSLEngine engine) {
this.engine = engine;
}
/**
* Creates a {@code NioTlsEngine} with server mode.
*
* @param engine the {@code SSLEngine}
* @return the {@code NioTlsEngine}
*/
public static NioTlsEngine createServerEngine(final SSLEngine engine) {
if (engine.getUseClientMode()) {
// TODO: configure in this class
throw new AssertionError();
}
return new NioTlsEngine(engine);
}
/** Returns the current handshake status. */
HandshakeStatus getHandshakeStatus() {
return engine.getHandshakeStatus();
}
/**
* Encodes application data into network data.
*
* @param src application data
* @param dst network data
* @return the {@code SSLEngineResult}
* @throws InfluentIOException when some operations about TLS fails
* @throws ReadOnlyBufferException when the {@code dst} is a read-only buffer
* @throws IllegalArgumentException when the {@code src} or the {@code dst} are {@code null}
*/
SSLEngineResult wrap(final ByteBuffer src, final ByteBuffer dst) {
try {
return engine.wrap(src, dst);
} catch (final SSLException e) {
|
throw new InfluentIOException("Illegal SSL/TLS processing was detected.", e);
|
okumin/influent
|
influent-java/src/main/java/influent/forward/ForwardClientNode.java
|
// Path: influent-transport/src/main/java/influent/internal/util/InetNetwork.java
// public interface InetNetwork {
// static InetNetwork getBySpec(String spec) {
// String[] addressComponents = spec.split("/", 2);
// if (addressComponents.length != 2) {
// throw new IllegalArgumentException("Invalid network: " + spec);
// }
// try {
// int netmask = Integer.parseInt(addressComponents[1]);
// InetAddress base = InetAddress.getByName(addressComponents[0]);
// if (base.getAddress().length == 16) {
// return new Inet6Network(base, netmask);
// } else {
// return new Inet4Network(base, netmask);
// }
// } catch (NumberFormatException | UnknownHostException e) {
// throw new IllegalArgumentException("Invalid network: " + spec, e);
// }
// }
//
// static InetAddress maskIP(InetAddress ip, InetAddress netmask) {
// return maskIP(ip.getAddress(), netmask.getAddress());
// }
//
// static InetAddress maskIP(byte[] ip, byte[] mask) {
// if (ip.length != mask.length) {
// throw new IllegalArgumentException("IP address and mask must be of the same length.");
// }
// byte[] masked = new byte[ip.length];
//
// for (int i = 0; i < ip.length; i++) {
// masked[i] = (byte) (ip[i] & mask[i]);
// }
//
// try {
// return InetAddress.getByAddress(masked);
// } catch (UnknownHostException e) {
// return null;
// }
// }
//
// boolean contains(InetAddress address);
// }
|
import influent.internal.util.InetNetwork;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
|
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.forward;
public class ForwardClientNode {
private InetAddress sourceAddress = null;
|
// Path: influent-transport/src/main/java/influent/internal/util/InetNetwork.java
// public interface InetNetwork {
// static InetNetwork getBySpec(String spec) {
// String[] addressComponents = spec.split("/", 2);
// if (addressComponents.length != 2) {
// throw new IllegalArgumentException("Invalid network: " + spec);
// }
// try {
// int netmask = Integer.parseInt(addressComponents[1]);
// InetAddress base = InetAddress.getByName(addressComponents[0]);
// if (base.getAddress().length == 16) {
// return new Inet6Network(base, netmask);
// } else {
// return new Inet4Network(base, netmask);
// }
// } catch (NumberFormatException | UnknownHostException e) {
// throw new IllegalArgumentException("Invalid network: " + spec, e);
// }
// }
//
// static InetAddress maskIP(InetAddress ip, InetAddress netmask) {
// return maskIP(ip.getAddress(), netmask.getAddress());
// }
//
// static InetAddress maskIP(byte[] ip, byte[] mask) {
// if (ip.length != mask.length) {
// throw new IllegalArgumentException("IP address and mask must be of the same length.");
// }
// byte[] masked = new byte[ip.length];
//
// for (int i = 0; i < ip.length; i++) {
// masked[i] = (byte) (ip[i] & mask[i]);
// }
//
// try {
// return InetAddress.getByAddress(masked);
// } catch (UnknownHostException e) {
// return null;
// }
// }
//
// boolean contains(InetAddress address);
// }
// Path: influent-java/src/main/java/influent/forward/ForwardClientNode.java
import influent.internal.util.InetNetwork;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
/*
* Copyright 2016 okumin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package influent.forward;
public class ForwardClientNode {
private InetAddress sourceAddress = null;
|
private InetNetwork network = null;
|
marcospassos/java-php-serializer
|
src/main/java/com/marcospassos/phpserializer/state/WritingArrayState.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
|
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing an array.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingArrayState extends AbstractState
{
/**
* The parent state.
*/
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingArrayState.java
import com.marcospassos.phpserializer.WriterState;
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing an array.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingArrayState extends AbstractState
{
/**
* The parent state.
*/
|
WriterState parent;
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/exclusion/DisjunctionExclusionStrategyTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/FieldExclusionStrategy.java
// public interface FieldExclusionStrategy
// {
// /**
// * Checks whether the specified field should be ignored.
// *
// * @param field The field that is under test.
// *
// * @return {@code true} if the field should be ignored, or {@code false}
// * otherwise.
// */
// boolean shouldSkipField(Field field);
// }
|
import java.lang.reflect.Field;
import com.marcospassos.phpserializer.FieldExclusionStrategy;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
|
package com.marcospassos.phpserializer.exclusion;
/**
* @author Marcos Passos
* @since 1.0
*/
public class DisjunctionExclusionStrategyTest
{
class A
{
private int field;
}
@Test
public void shouldSkipFieldPerformsShortCircuitOrOperation()
throws Exception
{
|
// Path: src/main/java/com/marcospassos/phpserializer/FieldExclusionStrategy.java
// public interface FieldExclusionStrategy
// {
// /**
// * Checks whether the specified field should be ignored.
// *
// * @param field The field that is under test.
// *
// * @return {@code true} if the field should be ignored, or {@code false}
// * otherwise.
// */
// boolean shouldSkipField(Field field);
// }
// Path: src/test/java/com/marcospassos/phpserializer/exclusion/DisjunctionExclusionStrategyTest.java
import java.lang.reflect.Field;
import com.marcospassos.phpserializer.FieldExclusionStrategy;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
package com.marcospassos.phpserializer.exclusion;
/**
* @author Marcos Passos
* @since 1.0
*/
public class DisjunctionExclusionStrategyTest
{
class A
{
private int field;
}
@Test
public void shouldSkipFieldPerformsShortCircuitOrOperation()
throws Exception
{
|
FieldExclusionStrategy a = mock(FieldExclusionStrategy.class);
|
marcospassos/java-php-serializer
|
src/main/java/com/marcospassos/phpserializer/state/WritingObjectState.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
|
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing an object.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingObjectState extends AbstractState
{
/**
* The parent state.
*/
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingObjectState.java
import com.marcospassos.phpserializer.WriterState;
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing an object.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingObjectState extends AbstractState
{
/**
* The parent state.
*/
|
WriterState parent;
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/state/WritingSerializableObjectStateTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
|
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingSerializableObjectStateTest
{
private WritingSerializableObjectState state;
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/test/java/com/marcospassos/phpserializer/state/WritingSerializableObjectStateTest.java
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingSerializableObjectStateTest
{
private WritingSerializableObjectState state;
|
private WriterState parent;
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/SerializerTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
|
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
|
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
// Path: src/test/java/com/marcospassos/phpserializer/SerializerTest.java
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
|
registry.registerAdapter(Integer.class, new IntegerAdapter());
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/SerializerTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
|
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
|
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
// Path: src/test/java/com/marcospassos/phpserializer/SerializerTest.java
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
|
new PsrNamingStrategy(),
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/SerializerTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
|
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
|
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
new PsrNamingStrategy(),
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
// Path: src/test/java/com/marcospassos/phpserializer/SerializerTest.java
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
new PsrNamingStrategy(),
|
new NoExclusionStrategy(),
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/SerializerTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
|
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
|
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
new PsrNamingStrategy(),
new NoExclusionStrategy(),
registry
);
assertEquals("i:1;", serializer.serialize(1));
}
@Test
public void serializeGenericAdapter() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
// Path: src/test/java/com/marcospassos/phpserializer/SerializerTest.java
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
new PsrNamingStrategy(),
new NoExclusionStrategy(),
registry
);
assertEquals("i:1;", serializer.serialize(1));
}
@Test
public void serializeGenericAdapter() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
|
registry.registerAdapter(Map.class, new MapAdapter());
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/SerializerTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
|
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
|
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
new PsrNamingStrategy(),
new NoExclusionStrategy(),
registry
);
assertEquals("i:1;", serializer.serialize(1));
}
@Test
public void serializeGenericAdapter() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Map.class, new MapAdapter());
|
// Path: src/main/java/com/marcospassos/phpserializer/adapter/IntegerAdapter.java
// public class IntegerAdapter implements TypeAdapter<Integer>
// {
// @Override
// public void write(Integer value, Writer writer, Context context)
// {
// writer.writeInteger(value);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/MapAdapter.java
// public class MapAdapter<K, V> implements TypeAdapter<Map<K, V>>
// {
// @Override
// public void write(Map<K, V> map, Writer writer, Context context)
// {
// int size = map.size();
//
// writer.writeArrayStart(size);
//
// for (Map.Entry<?, ?> entry : map.entrySet()) {
// Object key = entry.getKey();
//
// if (key instanceof Integer) {
// writer.writeKey((Integer) key);
// } else {
// writer.writeKey(key.toString());
// }
//
// context.write(entry.getValue(), writer);
// }
//
// writer.writeArrayEnd();
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/adapter/StringAdapter.java
// public class StringAdapter implements TypeAdapter<String>
// {
// /**
// * The charset.
// */
// private Charset charset;
//
// /**
// * Creates a adapter for strings encoded in UTF-8.
// */
// public StringAdapter() {
// this(Charset.forName("UTF-8"));
// }
//
// /**
// * Creates a adapter for strings encoded with the specified charset.
// *
// * @param charset The charset to encode strings.
// */
// public StringAdapter(Charset charset) {
// this.charset = charset;
// }
//
// @Override
// public void write(String value, Writer writer, Context context)
// {
// writer.writeString(value, this.charset);
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/exclusion/NoExclusionStrategy.java
// public class NoExclusionStrategy implements FieldExclusionStrategy
// {
// @Override
// public boolean shouldSkipField(Field field)
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/naming/PsrNamingStrategy.java
// public class PsrNamingStrategy implements NamingStrategy
// {
// @Override
// public String getClassName(Class type)
// {
// String className = type.getCanonicalName();
// StringBuilder adapted = new StringBuilder();
//
// for (String part : className.split("\\.")) {
// adapted.append("\\");
//
// adapted.append(part.substring(0, 1).toUpperCase());
// adapted.append(part.substring(1));
// }
//
// return adapted.substring(1);
// }
//
// @Override
// public String getFieldName(Field field)
// {
// return field.getName();
// }
// }
// Path: src/test/java/com/marcospassos/phpserializer/SerializerTest.java
import java.util.HashMap;
import java.util.Map;
import com.marcospassos.phpserializer.adapter.IntegerAdapter;
import com.marcospassos.phpserializer.adapter.MapAdapter;
import com.marcospassos.phpserializer.adapter.StringAdapter;
import com.marcospassos.phpserializer.exclusion.NoExclusionStrategy;
import com.marcospassos.phpserializer.naming.PsrNamingStrategy;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
package com.marcospassos.phpserializer;
/**
* @author Marcos Passos
* @since 1.0
*/
public class SerializerTest
{
@Test
public void serialize() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Integer.class, new IntegerAdapter());
Serializer serializer = new Serializer(
new PsrNamingStrategy(),
new NoExclusionStrategy(),
registry
);
assertEquals("i:1;", serializer.serialize(1));
}
@Test
public void serializeGenericAdapter() throws Exception
{
AdapterRegistry registry = new AdapterRegistry();
registry.registerAdapter(Map.class, new MapAdapter());
|
registry.registerAdapter(String.class, new StringAdapter());
|
marcospassos/java-php-serializer
|
src/main/java/com/marcospassos/phpserializer/Writer.java
|
// Path: src/main/java/com/marcospassos/phpserializer/state/FinishedState.java
// public class FinishedState extends AbstractState
// {
// @Override
// public boolean isReferable()
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
// public class WritingValueState extends AbstractState
// {
// /**
// * The parent state.
// */
// WriterState parent;
//
// /**
// * Creates an initial state.
// */
// public WritingValueState()
// {
// this(new FinishedState());
// }
//
// /**
// * Creates a new state from the specified parent state.
// *
// * @param parent The parent state.
// */
// public WritingValueState(WriterState parent)
// {
// this.parent = parent;
// }
//
// @Override
// public boolean isReferable()
// {
// return true;
// }
//
// @Override
// public WriterState serializableBegin()
// {
// return new WritingSerializableObjectState(parent);
// }
//
// @Override
// public WriterState objectBegin()
// {
// return new WritingObjectState(parent);
// }
//
// @Override
// public WriterState value()
// {
// return parent;
// }
//
// @Override
// public WriterState arrayBegin()
// {
// return new WritingArrayState(parent);
// }
// }
|
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import com.marcospassos.phpserializer.state.FinishedState;
import com.marcospassos.phpserializer.state.WritingValueState;
|
package com.marcospassos.phpserializer;
/**
* Writes a values in PHP's serialization format.
*
* @author Marcos Passos
* @since 1.0
*/
public class Writer
{
/**
* The buffer that stores the data.
*/
private StringBuffer buffer;
/**
* The reference counter.
*/
private int pointer = 1;
/**
* The current state of the writer.
*/
private WriterState state;
/**
* The current sub writer.
*/
private Writer subWriter;
/**
* Creates a new writer using an internal buffer.
*/
public Writer()
{
this(new StringBuffer());
}
/**
* Creates a writer specifying a buffer to write the data to.
*
* @param buffer The buffer to write the data to.
*/
public Writer(StringBuffer buffer)
{
this.buffer = buffer;
|
// Path: src/main/java/com/marcospassos/phpserializer/state/FinishedState.java
// public class FinishedState extends AbstractState
// {
// @Override
// public boolean isReferable()
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
// public class WritingValueState extends AbstractState
// {
// /**
// * The parent state.
// */
// WriterState parent;
//
// /**
// * Creates an initial state.
// */
// public WritingValueState()
// {
// this(new FinishedState());
// }
//
// /**
// * Creates a new state from the specified parent state.
// *
// * @param parent The parent state.
// */
// public WritingValueState(WriterState parent)
// {
// this.parent = parent;
// }
//
// @Override
// public boolean isReferable()
// {
// return true;
// }
//
// @Override
// public WriterState serializableBegin()
// {
// return new WritingSerializableObjectState(parent);
// }
//
// @Override
// public WriterState objectBegin()
// {
// return new WritingObjectState(parent);
// }
//
// @Override
// public WriterState value()
// {
// return parent;
// }
//
// @Override
// public WriterState arrayBegin()
// {
// return new WritingArrayState(parent);
// }
// }
// Path: src/main/java/com/marcospassos/phpserializer/Writer.java
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import com.marcospassos.phpserializer.state.FinishedState;
import com.marcospassos.phpserializer.state.WritingValueState;
package com.marcospassos.phpserializer;
/**
* Writes a values in PHP's serialization format.
*
* @author Marcos Passos
* @since 1.0
*/
public class Writer
{
/**
* The buffer that stores the data.
*/
private StringBuffer buffer;
/**
* The reference counter.
*/
private int pointer = 1;
/**
* The current state of the writer.
*/
private WriterState state;
/**
* The current sub writer.
*/
private Writer subWriter;
/**
* Creates a new writer using an internal buffer.
*/
public Writer()
{
this(new StringBuffer());
}
/**
* Creates a writer specifying a buffer to write the data to.
*
* @param buffer The buffer to write the data to.
*/
public Writer(StringBuffer buffer)
{
this.buffer = buffer;
|
this.state = new WritingValueState();
|
marcospassos/java-php-serializer
|
src/main/java/com/marcospassos/phpserializer/Writer.java
|
// Path: src/main/java/com/marcospassos/phpserializer/state/FinishedState.java
// public class FinishedState extends AbstractState
// {
// @Override
// public boolean isReferable()
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
// public class WritingValueState extends AbstractState
// {
// /**
// * The parent state.
// */
// WriterState parent;
//
// /**
// * Creates an initial state.
// */
// public WritingValueState()
// {
// this(new FinishedState());
// }
//
// /**
// * Creates a new state from the specified parent state.
// *
// * @param parent The parent state.
// */
// public WritingValueState(WriterState parent)
// {
// this.parent = parent;
// }
//
// @Override
// public boolean isReferable()
// {
// return true;
// }
//
// @Override
// public WriterState serializableBegin()
// {
// return new WritingSerializableObjectState(parent);
// }
//
// @Override
// public WriterState objectBegin()
// {
// return new WritingObjectState(parent);
// }
//
// @Override
// public WriterState value()
// {
// return parent;
// }
//
// @Override
// public WriterState arrayBegin()
// {
// return new WritingArrayState(parent);
// }
// }
|
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import com.marcospassos.phpserializer.state.FinishedState;
import com.marcospassos.phpserializer.state.WritingValueState;
|
/**
* Writes the start of an object to the buffer and returns an object-level
* sub writer.
*
* @param className The fully-qualified name of the class.
*
* @return An object-level sub writer to write the object's data.
*/
public Writer writeSerializableObjectStart(String className)
{
setState(state.serializableBegin());
buffer.append("C:");
buffer.append(className.length());
buffer.append(":\"");
buffer.append(className);
buffer.append("\":");
subWriter = new Writer();
subWriter.pointer = pointer + 1;
return subWriter;
}
/**
* Writes the end of a serializable object to the buffer.
*/
public void writeSerializableObjectEnd() {
setState(state.serializableEnd());
|
// Path: src/main/java/com/marcospassos/phpserializer/state/FinishedState.java
// public class FinishedState extends AbstractState
// {
// @Override
// public boolean isReferable()
// {
// return false;
// }
// }
//
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
// public class WritingValueState extends AbstractState
// {
// /**
// * The parent state.
// */
// WriterState parent;
//
// /**
// * Creates an initial state.
// */
// public WritingValueState()
// {
// this(new FinishedState());
// }
//
// /**
// * Creates a new state from the specified parent state.
// *
// * @param parent The parent state.
// */
// public WritingValueState(WriterState parent)
// {
// this.parent = parent;
// }
//
// @Override
// public boolean isReferable()
// {
// return true;
// }
//
// @Override
// public WriterState serializableBegin()
// {
// return new WritingSerializableObjectState(parent);
// }
//
// @Override
// public WriterState objectBegin()
// {
// return new WritingObjectState(parent);
// }
//
// @Override
// public WriterState value()
// {
// return parent;
// }
//
// @Override
// public WriterState arrayBegin()
// {
// return new WritingArrayState(parent);
// }
// }
// Path: src/main/java/com/marcospassos/phpserializer/Writer.java
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
import com.marcospassos.phpserializer.state.FinishedState;
import com.marcospassos.phpserializer.state.WritingValueState;
/**
* Writes the start of an object to the buffer and returns an object-level
* sub writer.
*
* @param className The fully-qualified name of the class.
*
* @return An object-level sub writer to write the object's data.
*/
public Writer writeSerializableObjectStart(String className)
{
setState(state.serializableBegin());
buffer.append("C:");
buffer.append(className.length());
buffer.append(":\"");
buffer.append(className);
buffer.append("\":");
subWriter = new Writer();
subWriter.pointer = pointer + 1;
return subWriter;
}
/**
* Writes the end of a serializable object to the buffer.
*/
public void writeSerializableObjectEnd() {
setState(state.serializableEnd());
|
if (!(subWriter.state instanceof FinishedState)) {
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/state/WritingObjectStateTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
|
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingObjectStateTest
{
private WritingObjectState state;
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/test/java/com/marcospassos/phpserializer/state/WritingObjectStateTest.java
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingObjectStateTest
{
private WritingObjectState state;
|
private WriterState parent;
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/state/WritingArrayStateTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
|
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingArrayStateTest
{
private WritingArrayState state;
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/test/java/com/marcospassos/phpserializer/state/WritingArrayStateTest.java
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingArrayStateTest
{
private WritingArrayState state;
|
private WriterState parent;
|
marcospassos/java-php-serializer
|
src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
|
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing a value.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingValueState extends AbstractState
{
/**
* The parent state.
*/
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingValueState.java
import com.marcospassos.phpserializer.WriterState;
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing a value.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingValueState extends AbstractState
{
/**
* The parent state.
*/
|
WriterState parent;
|
marcospassos/java-php-serializer
|
src/test/java/com/marcospassos/phpserializer/state/WritingValueStateTest.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
|
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingValueStateTest
{
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/test/java/com/marcospassos/phpserializer/state/WritingValueStateTest.java
import com.marcospassos.phpserializer.WriterState;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
package com.marcospassos.phpserializer.state;
/**
* @author Marcos Passos
* @since 1.0
*/
public class WritingValueStateTest
{
|
private WriterState parent;
|
marcospassos/java-php-serializer
|
src/main/java/com/marcospassos/phpserializer/state/WritingSerializableObjectState.java
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
|
import com.marcospassos.phpserializer.WriterState;
|
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing a serializable object.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingSerializableObjectState extends AbstractState
{
/**
* The parent state.
*/
|
// Path: src/main/java/com/marcospassos/phpserializer/WriterState.java
// public interface WriterState
// {
//
// /**
// * Checks whether the current state represents a referable value.
// *
// * @return {@code true} if the current state represents a referable value,
// * or {@code false} otherwise.
// */
// boolean isReferable();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState serializableEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState property();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState value();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState objectEnd();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayBegin();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState key();
//
// /**
// * Returns the new state generated as a result of transitions from the
// * current state to the new state.
// *
// * @return WriterState The new state.
// *
// * @throws IllegalStateException if the current state does not allow the
// * transition to the new state.
// */
// WriterState arrayEnd();
// }
// Path: src/main/java/com/marcospassos/phpserializer/state/WritingSerializableObjectState.java
import com.marcospassos.phpserializer.WriterState;
package com.marcospassos.phpserializer.state;
/**
* Represents the state of the writer while writing a serializable object.
*
* @author Marcos Passos
* @since 1.0
*/
public class WritingSerializableObjectState extends AbstractState
{
/**
* The parent state.
*/
|
WriterState parent;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
|
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
|
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
|
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
|
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY, TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY, TIME_DEFAULT);
|
long testSingleTime = settings.getLong(TIME_TEST_SINGLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY, TIME_DEFAULT);
long testSingleTime = settings.getLong(TIME_TEST_SINGLE_KEY, TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryActivity.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryActivity extends AppCompatActivity {
TextView tvHighSingle;
TextView tvHighDouble;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTime = findViewById(R.id.tvTotalTime);
tvHighSingle = findViewById(R.id.tvHighScoreSingles);
tvHighDouble = findViewById(R.id.tvHighScoreDoubles);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY, TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY, TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY, TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY, TIME_DEFAULT);
long testSingleTime = settings.getLong(TIME_TEST_SINGLE_KEY, TIME_DEFAULT);
|
long testDoubleTime = settings.getLong(TIME_TEST_DOUBLE_KEY, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
if(instance == null) {
instance = new StudyTimer();
}
return instance;
}
public void start(Context context, StudyType type) {
// no need to restart the timer for the same type
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
if(instance == null) {
instance = new StudyTimer();
}
return instance;
}
public void start(Context context, StudyType type) {
// no need to restart the timer for the same type
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
|
key = TIME_LEARN_SINGLE_KEY;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
return instance;
}
public void start(Context context, StudyType type) {
// no need to restart the timer for the same type
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
return instance;
}
public void start(Context context, StudyType type) {
// no need to restart the timer for the same type
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
|
key = TIME_LEARN_DOUBLE_KEY;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
public void start(Context context, StudyType type) {
// no need to restart the timer for the same type
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
public void start(Context context, StudyType type) {
// no need to restart the timer for the same type
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
|
key = TIME_PRACTICE_SINGLE_KEY;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
if (this.studyType == type) {
return;
}
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
|
key = TIME_PRACTICE_DOUBLE_KEY;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
// stop and record time for previous type (if any)
stop(context);
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
|
key = TIME_TEST_SINGLE_KEY;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
key = TIME_TEST_SINGLE_KEY;
break;
case TestDouble:
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
// start time for this type
startTime = System.nanoTime();
this.studyType = type;
}
void stop(Context context) {
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
key = TIME_TEST_SINGLE_KEY;
break;
case TestDouble:
|
key = TIME_TEST_DOUBLE_KEY;
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
key = TIME_TEST_SINGLE_KEY;
break;
case TestDouble:
key = TIME_TEST_DOUBLE_KEY;
break;
default:
return;
}
// save time increment to user preferences
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
key = TIME_TEST_SINGLE_KEY;
break;
case TestDouble:
key = TIME_TEST_DOUBLE_KEY;
break;
default:
return;
}
// save time increment to user preferences
|
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
key = TIME_TEST_SINGLE_KEY;
break;
case TestDouble:
key = TIME_TEST_DOUBLE_KEY;
break;
default:
return;
}
// save time increment to user preferences
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/StudyTimer.java
import android.content.Context;
import android.content.SharedPreferences;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
if (studyType == null) {
return;
}
String key;
switch (studyType) {
case LearnSingle:
key = TIME_LEARN_SINGLE_KEY;
break;
case LearnDouble:
key = TIME_LEARN_DOUBLE_KEY;
break;
case PracticeSingle:
key = TIME_PRACTICE_SINGLE_KEY;
break;
case PracticeDouble:
key = TIME_PRACTICE_DOUBLE_KEY;
break;
case TestSingle:
key = TIME_TEST_SINGLE_KEY;
break;
case TestDouble:
key = TIME_TEST_DOUBLE_KEY;
break;
default:
return;
}
// save time increment to user preferences
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
long formerTime = settings.getLong(key, TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/PracticeContentFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
|
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
|
@Override
public void onResume() {
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
soundPool.setOnLoadCompleteListener(this);
super.onResume();
}
@Override
public void onPause() {
if (soundPool != null) {
soundPool.release();
soundPool = null;
}
super.onPause();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
// check if parent Fragment implements listener
if (getParentFragment() instanceof PracticeScreenListener) {
mListener = (PracticeScreenListener) getParentFragment();
} else {
throw new RuntimeException("Parent fragment must implement PracticeScreenListener");
}
}
private void updatePracticeModeFromSharedPreferences() {
if (getActivity() == null) return;
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
// Path: app/src/main/java/com/aepronunciation/ipa/PracticeContentFragment.java
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
@Override
public void onResume() {
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
soundPool.setOnLoadCompleteListener(this);
super.onResume();
}
@Override
public void onPause() {
if (soundPool != null) {
soundPool.release();
soundPool = null;
}
super.onPause();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
// check if parent Fragment implements listener
if (getParentFragment() instanceof PracticeScreenListener) {
mListener = (PracticeScreenListener) getParentFragment();
} else {
throw new RuntimeException("Parent fragment must implement PracticeScreenListener");
}
}
private void updatePracticeModeFromSharedPreferences() {
if (getActivity() == null) return;
|
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/PracticeContentFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
|
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
|
public void onResume() {
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
soundPool.setOnLoadCompleteListener(this);
super.onResume();
}
@Override
public void onPause() {
if (soundPool != null) {
soundPool.release();
soundPool = null;
}
super.onPause();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
// check if parent Fragment implements listener
if (getParentFragment() instanceof PracticeScreenListener) {
mListener = (PracticeScreenListener) getParentFragment();
} else {
throw new RuntimeException("Parent fragment must implement PracticeScreenListener");
}
}
private void updatePracticeModeFromSharedPreferences() {
if (getActivity() == null) return;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
// Path: app/src/main/java/com/aepronunciation/ipa/PracticeContentFragment.java
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
public void onResume() {
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, SRC_QUALITY);
soundPool.setOnLoadCompleteListener(this);
super.onResume();
}
@Override
public void onPause() {
if (soundPool != null) {
soundPool.release();
soundPool = null;
}
super.onPause();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
// check if parent Fragment implements listener
if (getParentFragment() instanceof PracticeScreenListener) {
mListener = (PracticeScreenListener) getParentFragment();
} else {
throw new RuntimeException("Parent fragment must implement PracticeScreenListener");
}
}
private void updatePracticeModeFromSharedPreferences() {
if (getActivity() == null) return;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
boolean isSingle = settings.getBoolean(PRACTICE_MODE_IS_SINGLE_KEY, true);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestFragment extends Fragment implements View.OnClickListener {
private static final String DEFAULT_QUESTIONS = "50";
private EditText etName;
private Spinner spinner;
private RadioButton rbSingle;
//private SharedPreferences settings;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestFragment.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestFragment extends Fragment implements View.OnClickListener {
private static final String DEFAULT_QUESTIONS = "50";
private EditText etName;
private Spinner spinner;
private RadioButton rbSingle;
//private SharedPreferences settings;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
|
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestFragment extends Fragment implements View.OnClickListener {
private static final String DEFAULT_QUESTIONS = "50";
private EditText etName;
private Spinner spinner;
private RadioButton rbSingle;
//private SharedPreferences settings;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String defaultName = getString(R.string.test_default_name);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestFragment.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestFragment extends Fragment implements View.OnClickListener {
private static final String DEFAULT_QUESTIONS = "50";
private EditText etName;
private Spinner spinner;
private RadioButton rbSingle;
//private SharedPreferences settings;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String defaultName = getString(R.string.test_default_name);
|
String name = settings.getString(TEST_NAME_KEY, defaultName);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestFragment extends Fragment implements View.OnClickListener {
private static final String DEFAULT_QUESTIONS = "50";
private EditText etName;
private Spinner spinner;
private RadioButton rbSingle;
//private SharedPreferences settings;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String defaultName = getString(R.string.test_default_name);
String name = settings.getString(TEST_NAME_KEY, defaultName);
etName = view.findViewById(R.id.etName);
if (!name.equals(defaultName)) {
etName.setText(name);
etName.clearFocus();
}
// set up test mode
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestFragment.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestFragment extends Fragment implements View.OnClickListener {
private static final String DEFAULT_QUESTIONS = "50";
private EditText etName;
private Spinner spinner;
private RadioButton rbSingle;
//private SharedPreferences settings;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String defaultName = getString(R.string.test_default_name);
String name = settings.getString(TEST_NAME_KEY, defaultName);
etName = view.findViewById(R.id.etName);
if (!name.equals(defaultName)) {
etName.setText(name);
etName.clearFocus();
}
// set up test mode
|
String testModeString = settings.getString(TEST_MODE_KEY, SoundMode.Single.getPersistentMemoryString());
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String defaultName = getString(R.string.test_default_name);
String name = settings.getString(TEST_NAME_KEY, defaultName);
etName = view.findViewById(R.id.etName);
if (!name.equals(defaultName)) {
etName.setText(name);
etName.clearFocus();
}
// set up test mode
String testModeString = settings.getString(TEST_MODE_KEY, SoundMode.Single.getPersistentMemoryString());
rbSingle = view.findViewById(R.id.rbTestSetupSingle);
RadioButton rbDouble = view.findViewById(R.id.rbTestSetupDouble);
if (testModeString.equals(SoundMode.Double.getPersistentMemoryString())) {
rbDouble.setChecked(true);
} else { // default
rbSingle.setChecked(true);
}
// Setup spinner
spinner = view.findViewById(R.id.spinnerQuestions);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.listvalues,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestFragment.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
View view = inflater.inflate(R.layout.tab_fragment_test, container, false);
// setup name
if (getActivity() == null) return view;
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
String defaultName = getString(R.string.test_default_name);
String name = settings.getString(TEST_NAME_KEY, defaultName);
etName = view.findViewById(R.id.etName);
if (!name.equals(defaultName)) {
etName.setText(name);
etName.clearFocus();
}
// set up test mode
String testModeString = settings.getString(TEST_MODE_KEY, SoundMode.Single.getPersistentMemoryString());
rbSingle = view.findViewById(R.id.rbTestSetupSingle);
RadioButton rbDouble = view.findViewById(R.id.rbTestSetupDouble);
if (testModeString.equals(SoundMode.Double.getPersistentMemoryString())) {
rbDouble.setChecked(true);
} else { // default
rbSingle.setChecked(true);
}
// Setup spinner
spinner = view.findViewById(R.id.spinnerQuestions);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.listvalues,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
|
String numQuestions = settings.getString(NUMBER_OF_QUESTIONS_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
name = getString(R.string.test_default_name);
}
// Number of questions
String questions = spinner.getSelectedItem().toString();
// Test mode
String testModeString;
if (rbSingle.isChecked()) {
testModeString = SoundMode.Single.getPersistentMemoryString();
} else {
testModeString = SoundMode.Double.getPersistentMemoryString();
}
// Save to preferences
if (getActivity() != null) {
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(NUMBER_OF_QUESTIONS_KEY, questions);
editor.putString(TEST_MODE_KEY, testModeString);
editor.putString(TEST_NAME_KEY, name);
editor.apply();
}
// Start test activity
Intent intent = new Intent(getActivity(), TestActivity.class);
intent.putExtra(TEST_NAME_KEY, name);
intent.putExtra(TEST_MODE_KEY, testModeString);
intent.putExtra(NUMBER_OF_QUESTIONS_KEY, Integer.parseInt(questions));
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestFragment.java
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
name = getString(R.string.test_default_name);
}
// Number of questions
String questions = spinner.getSelectedItem().toString();
// Test mode
String testModeString;
if (rbSingle.isChecked()) {
testModeString = SoundMode.Single.getPersistentMemoryString();
} else {
testModeString = SoundMode.Double.getPersistentMemoryString();
}
// Save to preferences
if (getActivity() != null) {
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString(NUMBER_OF_QUESTIONS_KEY, questions);
editor.putString(TEST_MODE_KEY, testModeString);
editor.putString(TEST_NAME_KEY, name);
editor.apply();
}
// Start test activity
Intent intent = new Intent(getActivity(), TestActivity.class);
intent.putExtra(TEST_NAME_KEY, name);
intent.putExtra(TEST_MODE_KEY, testModeString);
intent.putExtra(NUMBER_OF_QUESTIONS_KEY, Integer.parseInt(questions));
|
getActivity().startActivityForResult(intent, TEST_RESULTS_RESULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
|
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
|
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
|
TIME_DEFAULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
|
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
|
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
package com.aepronunciation.ipa;
public class HistoryTimeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history_time);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
TIME_DEFAULT);
|
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY,
TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY,
TIME_DEFAULT);
|
long testSingleTime = settings.getLong(TIME_TEST_SINGLE_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
|
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
|
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY,
TIME_DEFAULT);
long testSingleTime = settings.getLong(TIME_TEST_SINGLE_KEY,
TIME_DEFAULT);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final long TIME_DEFAULT = 0;
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_DOUBLE_KEY = "timeLearnDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_LEARN_SINGLE_KEY = "timeLearnSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_DOUBLE_KEY = "timePracticeDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_PRACTICE_SINGLE_KEY = "timePracticeSingle";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_DOUBLE_KEY = "timeTestDouble";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TIME_TEST_SINGLE_KEY = "timeTestSingle";
// Path: app/src/main/java/com/aepronunciation/ipa/HistoryTimeActivity.java
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.TextView;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
import static com.aepronunciation.ipa.MainActivity.TIME_DEFAULT;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_LEARN_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_PRACTICE_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_DOUBLE_KEY;
import static com.aepronunciation.ipa.MainActivity.TIME_TEST_SINGLE_KEY;
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Create objects
TextView tvTimeLearning = findViewById(R.id.tvTimeLearning);
TextView tvTimeLearningSingles = findViewById(R.id.tvTimeLearningSingles);
TextView tvTimeLearningDoubles = findViewById(R.id.tvTimeLearningDoubles);
TextView tvTimePracticing = findViewById(R.id.tvTimePracticing);
TextView tvTimePracticingSingles = findViewById(R.id.tvTimePracticingSingles);
TextView tvTimePracticingDoubles = findViewById(R.id.tvTimePracticingDoubles);
TextView tvTimeTesting = findViewById(R.id.tvTimeTesting);
TextView tvTimeTestingSingles = findViewById(R.id.tvTimeTestingSingles);
TextView tvTimeTestingDoubles = findViewById(R.id.tvTimeTestingDoubles);
TextView tvTotalTime = findViewById(R.id.tvTotalTime);
// get times from preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
long learnSingleTime = settings.getLong(TIME_LEARN_SINGLE_KEY,
TIME_DEFAULT);
long learnDoubleTime = settings.getLong(TIME_LEARN_DOUBLE_KEY,
TIME_DEFAULT);
long practiceSingleTime = settings.getLong(TIME_PRACTICE_SINGLE_KEY,
TIME_DEFAULT);
long practiceDoubleTime = settings.getLong(TIME_PRACTICE_DOUBLE_KEY,
TIME_DEFAULT);
long testSingleTime = settings.getLong(TIME_TEST_SINGLE_KEY,
TIME_DEFAULT);
|
long testDoubleTime = settings.getLong(TIME_TEST_DOUBLE_KEY,
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
|
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
|
package com.aepronunciation.ipa;
public class TestResultsActivity extends AppCompatActivity implements TestResultsRecyclerViewAdapter.ItemClickListener,
SoundPool.OnLoadCompleteListener {
private String userName;
private long timeLength;
private SoundMode testMode;
private int score;
private ArrayList<Answer> answers;
private TestResultsRecyclerViewAdapter adapter;
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private DoubleSound doubleSound;
private SingleSound singleSound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_results);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Get extras from Test Activity
Bundle bundle = getIntent().getExtras();
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
// Path: app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
package com.aepronunciation.ipa;
public class TestResultsActivity extends AppCompatActivity implements TestResultsRecyclerViewAdapter.ItemClickListener,
SoundPool.OnLoadCompleteListener {
private String userName;
private long timeLength;
private SoundMode testMode;
private int score;
private ArrayList<Answer> answers;
private TestResultsRecyclerViewAdapter adapter;
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private DoubleSound doubleSound;
private SingleSound singleSound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_results);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Get extras from Test Activity
Bundle bundle = getIntent().getExtras();
|
userName = bundle.getString(TEST_NAME_KEY);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
|
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
|
package com.aepronunciation.ipa;
public class TestResultsActivity extends AppCompatActivity implements TestResultsRecyclerViewAdapter.ItemClickListener,
SoundPool.OnLoadCompleteListener {
private String userName;
private long timeLength;
private SoundMode testMode;
private int score;
private ArrayList<Answer> answers;
private TestResultsRecyclerViewAdapter adapter;
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private DoubleSound doubleSound;
private SingleSound singleSound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_results);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Get extras from Test Activity
Bundle bundle = getIntent().getExtras();
userName = bundle.getString(TEST_NAME_KEY);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
// Path: app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
package com.aepronunciation.ipa;
public class TestResultsActivity extends AppCompatActivity implements TestResultsRecyclerViewAdapter.ItemClickListener,
SoundPool.OnLoadCompleteListener {
private String userName;
private long timeLength;
private SoundMode testMode;
private int score;
private ArrayList<Answer> answers;
private TestResultsRecyclerViewAdapter adapter;
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private DoubleSound doubleSound;
private SingleSound singleSound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_results);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// add back arrow to toolbar
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
// Get extras from Test Activity
Bundle bundle = getIntent().getExtras();
userName = bundle.getString(TEST_NAME_KEY);
|
testMode = SoundMode.fromString(bundle.getString(TEST_MODE_KEY));
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
|
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
|
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
finish(); // close this activity and return to preview activity (if there is any)
}
return super.onOptionsItemSelected(item);
}
public void practiceDifficultClick(View view) {
// get vowel and consonant sounds
ArrayList<String> vowelArray = new ArrayList<>();
ArrayList<String> consonantArray = new ArrayList<>();
Set<String> allSounds = findNeedToPracticeSounds(answers);
for (String sound : allSounds) {
if (Ipa.isConsonant(sound)) {
consonantArray.add(sound);
} else {
vowelArray.add(sound);
}
}
// put the String to pass back into an Intent and close this activity
Intent intent = new Intent();
intent.putExtra(TEST_MODE_KEY, testMode);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
// Path: app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
finish(); // close this activity and return to preview activity (if there is any)
}
return super.onOptionsItemSelected(item);
}
public void practiceDifficultClick(View view) {
// get vowel and consonant sounds
ArrayList<String> vowelArray = new ArrayList<>();
ArrayList<String> consonantArray = new ArrayList<>();
Set<String> allSounds = findNeedToPracticeSounds(answers);
for (String sound : allSounds) {
if (Ipa.isConsonant(sound)) {
consonantArray.add(sound);
} else {
vowelArray.add(sound);
}
}
// put the String to pass back into an Intent and close this activity
Intent intent = new Intent();
intent.putExtra(TEST_MODE_KEY, testMode);
|
intent.putStringArrayListExtra(VOWEL_ARRAY_KEY, vowelArray);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
|
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
|
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
finish(); // close this activity and return to preview activity (if there is any)
}
return super.onOptionsItemSelected(item);
}
public void practiceDifficultClick(View view) {
// get vowel and consonant sounds
ArrayList<String> vowelArray = new ArrayList<>();
ArrayList<String> consonantArray = new ArrayList<>();
Set<String> allSounds = findNeedToPracticeSounds(answers);
for (String sound : allSounds) {
if (Ipa.isConsonant(sound)) {
consonantArray.add(sound);
} else {
vowelArray.add(sound);
}
}
// put the String to pass back into an Intent and close this activity
Intent intent = new Intent();
intent.putExtra(TEST_MODE_KEY, testMode);
intent.putStringArrayListExtra(VOWEL_ARRAY_KEY, vowelArray);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String CONSONANT_ARRAY_KEY = "consonantArray";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String VOWEL_ARRAY_KEY = "vowelArray";
// Path: app/src/main/java/com/aepronunciation/ipa/TestResultsActivity.java
import android.content.DialogInterface;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import java.text.DateFormat;
import android.util.Pair;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static com.aepronunciation.ipa.MainActivity.CONSONANT_ARRAY_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.VOWEL_ARRAY_KEY;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
finish(); // close this activity and return to preview activity (if there is any)
}
return super.onOptionsItemSelected(item);
}
public void practiceDifficultClick(View view) {
// get vowel and consonant sounds
ArrayList<String> vowelArray = new ArrayList<>();
ArrayList<String> consonantArray = new ArrayList<>();
Set<String> allSounds = findNeedToPracticeSounds(answers);
for (String sound : allSounds) {
if (Ipa.isConsonant(sound)) {
consonantArray.add(sound);
} else {
vowelArray.add(sound);
}
}
// put the String to pass back into an Intent and close this activity
Intent intent = new Intent();
intent.putExtra(TEST_MODE_KEY, testMode);
intent.putStringArrayListExtra(VOWEL_ARRAY_KEY, vowelArray);
|
intent.putStringArrayListExtra(CONSONANT_ARRAY_KEY, consonantArray);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestActivity extends AppCompatActivity implements KeyboardFragment.KeyboardListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// Get extras from Test Fragment (setup)
Intent intent = getIntent();
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestActivity.java
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestActivity extends AppCompatActivity implements KeyboardFragment.KeyboardListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// Get extras from Test Fragment (setup)
Intent intent = getIntent();
|
SoundMode testMode = SoundMode.fromString(intent.getStringExtra(TEST_MODE_KEY));
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestActivity extends AppCompatActivity implements KeyboardFragment.KeyboardListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// Get extras from Test Fragment (setup)
Intent intent = getIntent();
SoundMode testMode = SoundMode.fromString(intent.getStringExtra(TEST_MODE_KEY));
Bundle contentBundle = new Bundle();
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestActivity.java
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestActivity extends AppCompatActivity implements KeyboardFragment.KeyboardListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// Get extras from Test Fragment (setup)
Intent intent = getIntent();
SoundMode testMode = SoundMode.fromString(intent.getStringExtra(TEST_MODE_KEY));
Bundle contentBundle = new Bundle();
|
contentBundle.putString(TEST_NAME_KEY, intent.getStringExtra(TEST_NAME_KEY));
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestActivity extends AppCompatActivity implements KeyboardFragment.KeyboardListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// Get extras from Test Fragment (setup)
Intent intent = getIntent();
SoundMode testMode = SoundMode.fromString(intent.getStringExtra(TEST_MODE_KEY));
Bundle contentBundle = new Bundle();
contentBundle.putString(TEST_NAME_KEY, intent.getStringExtra(TEST_NAME_KEY));
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestActivity.java
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestActivity extends AppCompatActivity implements KeyboardFragment.KeyboardListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
// Get extras from Test Fragment (setup)
Intent intent = getIntent();
SoundMode testMode = SoundMode.fromString(intent.getStringExtra(TEST_MODE_KEY));
Bundle contentBundle = new Bundle();
contentBundle.putString(TEST_NAME_KEY, intent.getStringExtra(TEST_NAME_KEY));
|
contentBundle.putInt(NUMBER_OF_QUESTIONS_KEY, intent.getIntExtra(NUMBER_OF_QUESTIONS_KEY, 50));
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestActivity.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
contentFragment.setArguments(contentBundle);
transaction.replace(R.id.test_content_frame, contentFragment);
Fragment keyboardFragment = new KeyboardFragment();
keyboardFragment.setArguments(keyboardBundle);
transaction.replace(R.id.keyboard_frame, keyboardFragment);
transaction.commit();
// disable rotation for smaller devices
if(getResources().getBoolean(R.bool.portrait_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
// required method for KeyboardFragment.KeyboardListener
@Override
public void onKeyTouched(String keyString) {
// find the correct fragment and then perform the appropriate action on it
Fragment f = getSupportFragmentManager().findFragmentById(R.id.test_content_frame);
if (f instanceof TestContentFragment) {
// update display
TestContentFragment testContentFragment = (TestContentFragment) f;
testContentFragment.onKeyTouched(keyString);
}
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestActivity.java
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.fragment.app.FragmentTransaction;
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AppCompatActivity;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
contentFragment.setArguments(contentBundle);
transaction.replace(R.id.test_content_frame, contentFragment);
Fragment keyboardFragment = new KeyboardFragment();
keyboardFragment.setArguments(keyboardBundle);
transaction.replace(R.id.keyboard_frame, keyboardFragment);
transaction.commit();
// disable rotation for smaller devices
if(getResources().getBoolean(R.bool.portrait_only)){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
// required method for KeyboardFragment.KeyboardListener
@Override
public void onKeyTouched(String keyString) {
// find the correct fragment and then perform the appropriate action on it
Fragment f = getSupportFragmentManager().findFragmentById(R.id.test_content_frame);
if (f instanceof TestContentFragment) {
// update display
TestContentFragment testContentFragment = (TestContentFragment) f;
testContentFragment.onKeyTouched(keyString);
}
}
@Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
|
if (requestCode == TEST_RESULTS_RESULT) {
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/KeyboardFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
|
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.HashMap;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
|
package com.aepronunciation.ipa;
public class KeyboardFragment extends Fragment implements OnClickListener {
View view;
private HashMap<Integer, String> mLayoutToString;
private HashMap<Integer, String> mTextViewToString;
private KeyboardListener mListener; // communicate with the parent activity
// Container Activity must implement this interface
public interface KeyboardListener {
void onKeyTouched(String keyString);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeMaps();
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_keyboard, container, false);
if (getArguments() != null) {
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
// Path: app/src/main/java/com/aepronunciation/ipa/KeyboardFragment.java
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.core.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.HashMap;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
package com.aepronunciation.ipa;
public class KeyboardFragment extends Fragment implements OnClickListener {
View view;
private HashMap<Integer, String> mLayoutToString;
private HashMap<Integer, String> mTextViewToString;
private KeyboardListener mListener; // communicate with the parent activity
// Container Activity must implement this interface
public interface KeyboardListener {
void onKeyTouched(String keyString);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeMaps();
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_keyboard, container, false);
if (getArguments() != null) {
|
SoundMode testMode = SoundMode.fromString(getArguments().getString(TEST_MODE_KEY));
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestContentFragment extends Fragment implements View.OnClickListener,
SoundPool.OnLoadCompleteListener {
private String studentName;
private SoundMode testMode;
private int totalNumberOfQuestions = 50;
private ArrayList<Answer> answers;
private SingleSound singleSound;
private DoubleSound doubleSound;
private TextView tvInputWindow;
private TextView tvQuestionNumber;
private RelativeLayout nextButton;
private String currentIpa = "";
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private boolean readyForNewSound = true;
private int inputKeyCounter = 0;
private int questionNumber = 0; // zero based
private long startTime;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_test_content, container, false);
// get arguments
if (getArguments() == null) {
studentName = getString(R.string.test_default_name);
totalNumberOfQuestions = 50;
testMode = SoundMode.Single;
} else {
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestContentFragment extends Fragment implements View.OnClickListener,
SoundPool.OnLoadCompleteListener {
private String studentName;
private SoundMode testMode;
private int totalNumberOfQuestions = 50;
private ArrayList<Answer> answers;
private SingleSound singleSound;
private DoubleSound doubleSound;
private TextView tvInputWindow;
private TextView tvQuestionNumber;
private RelativeLayout nextButton;
private String currentIpa = "";
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private boolean readyForNewSound = true;
private int inputKeyCounter = 0;
private int questionNumber = 0; // zero based
private long startTime;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_test_content, container, false);
// get arguments
if (getArguments() == null) {
studentName = getString(R.string.test_default_name);
totalNumberOfQuestions = 50;
testMode = SoundMode.Single;
} else {
|
studentName = getArguments().getString(TEST_NAME_KEY);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
package com.aepronunciation.ipa;
public class TestContentFragment extends Fragment implements View.OnClickListener,
SoundPool.OnLoadCompleteListener {
private String studentName;
private SoundMode testMode;
private int totalNumberOfQuestions = 50;
private ArrayList<Answer> answers;
private SingleSound singleSound;
private DoubleSound doubleSound;
private TextView tvInputWindow;
private TextView tvQuestionNumber;
private RelativeLayout nextButton;
private String currentIpa = "";
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private boolean readyForNewSound = true;
private int inputKeyCounter = 0;
private int questionNumber = 0; // zero based
private long startTime;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_test_content, container, false);
// get arguments
if (getArguments() == null) {
studentName = getString(R.string.test_default_name);
totalNumberOfQuestions = 50;
testMode = SoundMode.Single;
} else {
studentName = getArguments().getString(TEST_NAME_KEY);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
package com.aepronunciation.ipa;
public class TestContentFragment extends Fragment implements View.OnClickListener,
SoundPool.OnLoadCompleteListener {
private String studentName;
private SoundMode testMode;
private int totalNumberOfQuestions = 50;
private ArrayList<Answer> answers;
private SingleSound singleSound;
private DoubleSound doubleSound;
private TextView tvInputWindow;
private TextView tvQuestionNumber;
private RelativeLayout nextButton;
private String currentIpa = "";
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private boolean readyForNewSound = true;
private int inputKeyCounter = 0;
private int questionNumber = 0; // zero based
private long startTime;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_test_content, container, false);
// get arguments
if (getArguments() == null) {
studentName = getString(R.string.test_default_name);
totalNumberOfQuestions = 50;
testMode = SoundMode.Single;
} else {
studentName = getArguments().getString(TEST_NAME_KEY);
|
totalNumberOfQuestions = getArguments().getInt(NUMBER_OF_QUESTIONS_KEY, 50);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
private ArrayList<Answer> answers;
private SingleSound singleSound;
private DoubleSound doubleSound;
private TextView tvInputWindow;
private TextView tvQuestionNumber;
private RelativeLayout nextButton;
private String currentIpa = "";
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private boolean readyForNewSound = true;
private int inputKeyCounter = 0;
private int questionNumber = 0; // zero based
private long startTime;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_test_content, container, false);
// get arguments
if (getArguments() == null) {
studentName = getString(R.string.test_default_name);
totalNumberOfQuestions = 50;
testMode = SoundMode.Single;
} else {
studentName = getArguments().getString(TEST_NAME_KEY);
totalNumberOfQuestions = getArguments().getInt(NUMBER_OF_QUESTIONS_KEY, 50);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
private ArrayList<Answer> answers;
private SingleSound singleSound;
private DoubleSound doubleSound;
private TextView tvInputWindow;
private TextView tvQuestionNumber;
private RelativeLayout nextButton;
private String currentIpa = "";
private static final int SRC_QUALITY = 0;
private static final int PRIORITY = 1;
private SoundPool soundPool = null;
private boolean readyForNewSound = true;
private int inputKeyCounter = 0;
private int questionNumber = 0; // zero based
private long startTime;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_test_content, container, false);
// get arguments
if (getArguments() == null) {
studentName = getString(R.string.test_default_name);
totalNumberOfQuestions = 50;
testMode = SoundMode.Single;
} else {
studentName = getArguments().getString(TEST_NAME_KEY);
totalNumberOfQuestions = getArguments().getInt(NUMBER_OF_QUESTIONS_KEY, 50);
|
testMode = SoundMode.fromString(getArguments().getString(TEST_MODE_KEY));
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
|
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
|
}
private void nextClick() {
if (getActivity() == null) return;
String userAnswer = tvInputWindow.getText().toString();
// record correct answer and user answer
Answer thisAnswer = new Answer();
thisAnswer.setCorrectAnswer(currentIpa);
thisAnswer.setUserAnswer(userAnswer);
answers.add(thisAnswer);
// reset values
tvInputWindow.setText("");
inputKeyCounter = 0;
readyForNewSound = true;
nextButton.setVisibility(View.INVISIBLE);
questionNumber++;
if (questionNumber == totalNumberOfQuestions) {
// Start test results activity
Intent intent = new Intent(getActivity(), TestResultsActivity.class);
intent.putExtra(TEST_NAME_KEY, studentName);
intent.putExtra(TEST_MODE_KEY, testMode.getPersistentMemoryString());
intent.putExtra("time", System.nanoTime() - startTime);
intent.putParcelableArrayListExtra(
"com.aepronunciation.ipa.testAnswers", answers);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String NUMBER_OF_QUESTIONS_KEY = "numberOfQuestions";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_MODE_KEY = "testMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String TEST_NAME_KEY = "testName";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final int TEST_RESULTS_RESULT = 0;
// Path: app/src/main/java/com/aepronunciation/ipa/TestContentFragment.java
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import static com.aepronunciation.ipa.MainActivity.NUMBER_OF_QUESTIONS_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_MODE_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_NAME_KEY;
import static com.aepronunciation.ipa.MainActivity.TEST_RESULTS_RESULT;
}
private void nextClick() {
if (getActivity() == null) return;
String userAnswer = tvInputWindow.getText().toString();
// record correct answer and user answer
Answer thisAnswer = new Answer();
thisAnswer.setCorrectAnswer(currentIpa);
thisAnswer.setUserAnswer(userAnswer);
answers.add(thisAnswer);
// reset values
tvInputWindow.setText("");
inputKeyCounter = 0;
readyForNewSound = true;
nextButton.setVisibility(View.INVISIBLE);
questionNumber++;
if (questionNumber == totalNumberOfQuestions) {
// Start test results activity
Intent intent = new Intent(getActivity(), TestResultsActivity.class);
intent.putExtra(TEST_NAME_KEY, studentName);
intent.putExtra(TEST_MODE_KEY, testMode.getPersistentMemoryString());
intent.putExtra("time", System.nanoTime() - startTime);
intent.putParcelableArrayListExtra(
"com.aepronunciation.ipa.testAnswers", answers);
|
getActivity().startActivityForResult(intent, TEST_RESULTS_RESULT);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/SelectSoundDialogFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
|
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
|
private SelectSoundDialogListener mListener;
private RadioButton rbSingle;
private RadioButton rbDouble;
private CheckBox cbVowelsCategory;
private CheckBox cbConsonantsCategory;
private CheckBox[] checkBoxesVowels;
private CheckBox[] checkBoxesConsonants;
private CheckBox cbSchwa;
private CheckBox cbUnstressedEr;
private CheckBox cbGlottalStop;
private CheckBox cbFlapT;
private Button positiveButton;
private boolean listenerDisabled = false;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_select_sound, null);
rbSingle = view.findViewById(R.id.radio_single);
rbDouble = view.findViewById(R.id.radio_double);
cbSchwa = view.findViewById(R.id.cb_shwua);
cbUnstressedEr = view.findViewById(R.id.cb_er_unstressed);
cbGlottalStop = view.findViewById(R.id.cb_glottal_stop);
cbFlapT = view.findViewById(R.id.cb_flap_t);
// get saved practice mode
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
// Path: app/src/main/java/com/aepronunciation/ipa/SelectSoundDialogFragment.java
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
private SelectSoundDialogListener mListener;
private RadioButton rbSingle;
private RadioButton rbDouble;
private CheckBox cbVowelsCategory;
private CheckBox cbConsonantsCategory;
private CheckBox[] checkBoxesVowels;
private CheckBox[] checkBoxesConsonants;
private CheckBox cbSchwa;
private CheckBox cbUnstressedEr;
private CheckBox cbGlottalStop;
private CheckBox cbFlapT;
private Button positiveButton;
private boolean listenerDisabled = false;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_select_sound, null);
rbSingle = view.findViewById(R.id.radio_single);
rbDouble = view.findViewById(R.id.radio_double);
cbSchwa = view.findViewById(R.id.cb_shwua);
cbUnstressedEr = view.findViewById(R.id.cb_er_unstressed);
cbGlottalStop = view.findViewById(R.id.cb_glottal_stop);
cbFlapT = view.findViewById(R.id.cb_flap_t);
// get saved practice mode
|
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
suragch/aePronunciation
|
app/src/main/java/com/aepronunciation/ipa/SelectSoundDialogFragment.java
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
|
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
|
private SelectSoundDialogListener mListener;
private RadioButton rbSingle;
private RadioButton rbDouble;
private CheckBox cbVowelsCategory;
private CheckBox cbConsonantsCategory;
private CheckBox[] checkBoxesVowels;
private CheckBox[] checkBoxesConsonants;
private CheckBox cbSchwa;
private CheckBox cbUnstressedEr;
private CheckBox cbGlottalStop;
private CheckBox cbFlapT;
private Button positiveButton;
private boolean listenerDisabled = false;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_select_sound, null);
rbSingle = view.findViewById(R.id.radio_single);
rbDouble = view.findViewById(R.id.radio_double);
cbSchwa = view.findViewById(R.id.cb_shwua);
cbUnstressedEr = view.findViewById(R.id.cb_er_unstressed);
cbGlottalStop = view.findViewById(R.id.cb_glottal_stop);
cbFlapT = view.findViewById(R.id.cb_flap_t);
// get saved practice mode
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PRACTICE_MODE_IS_SINGLE_KEY = "practiceMode";
//
// Path: app/src/main/java/com/aepronunciation/ipa/MainActivity.java
// public static final String PREFS_NAME = "MyPrefsFile";
// Path: app/src/main/java/com/aepronunciation/ipa/SelectSoundDialogFragment.java
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import java.util.ArrayList;
import static android.content.Context.MODE_PRIVATE;
import static com.aepronunciation.ipa.MainActivity.PRACTICE_MODE_IS_SINGLE_KEY;
import static com.aepronunciation.ipa.MainActivity.PREFS_NAME;
private SelectSoundDialogListener mListener;
private RadioButton rbSingle;
private RadioButton rbDouble;
private CheckBox cbVowelsCategory;
private CheckBox cbConsonantsCategory;
private CheckBox[] checkBoxesVowels;
private CheckBox[] checkBoxesConsonants;
private CheckBox cbSchwa;
private CheckBox cbUnstressedEr;
private CheckBox cbGlottalStop;
private CheckBox cbFlapT;
private Button positiveButton;
private boolean listenerDisabled = false;
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_select_sound, null);
rbSingle = view.findViewById(R.id.radio_single);
rbDouble = view.findViewById(R.id.radio_double);
cbSchwa = view.findViewById(R.id.cb_shwua);
cbUnstressedEr = view.findViewById(R.id.cb_er_unstressed);
cbGlottalStop = view.findViewById(R.id.cb_glottal_stop);
cbFlapT = view.findViewById(R.id.cb_flap_t);
// get saved practice mode
SharedPreferences settings = getActivity().getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
boolean isSingle = settings.getBoolean(PRACTICE_MODE_IS_SINGLE_KEY, true);
|
mwitkow/java-flagz
|
flagz-java/src/test/java/org/flagz/FlagFieldScannerTest.java
|
// Path: flagz-java/src/test/java/org/flagz/testclasses/StaticFlags.java
// public class StaticFlags {
//
// @FlagInfo(help = "for testing of resolution with no name argument")
// public static final Flag<Integer> testFieldNameFlag = Flagz.valueOf(0);
//
// @FlagInfo(name = "test_alt_name", help = "for testing of resolution with alt name", altName = "t_alt")
// public static final Flag<String> testAltNameFlag = Flagz.valueOf("my_alt");
//
// @FlagInfo(name = "test_flag_full_name", help = "for testing of resolution with full name")
// public static final Flag<Long> testFullNameFlag = Flagz.valueOf(0L);
//
// @FlagInfo(name = "test_flag_private_static", help = "for testing of resolution of private static fields")
// private static final Flag<Long> testPrivateStaticFlag = Flagz.valueOf(0L);
//
// @FlagInfo(name = "test_flag_public_static", help = "for testing of resolution of public static fields")
// public static final Flag<Long> testPublicStaticFlag = Flagz.valueOf(0L);
//
// @FlagInfo(name = "test_flag_non_static", help = "for validating that we won't see non static fields")
// private final Flag<Long> testInvisibleNonStaticFlag = Flagz.valueOf(0L);
//
//
// public static Flag<Long> testPrivateStaticFlagAccessor() {
// return testPrivateStaticFlag;
// }
//
// @SuppressWarnings("unchecked")
// public static void resetToDefaults() {
// List<Flag<?>> list = ImmutableList.of(
// testFieldNameFlag, testAltNameFlag, testFullNameFlag, testPrivateStaticFlag, testPublicStaticFlag);
// for (Flag f : list) {
// f.accept(f.defaultValue());
// }
// }
// }
|
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.flagz.testclasses.StaticFlags;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
|
}
}
;
static class ContainerTwo {
@FlagInfo(name = "test_flag_obj_public_two", help = "")
public final Flag<Long> testPublicFlag = Flagz.valueOf(999L);
}
;
static class ContainerClashingWithStatic {
@FlagInfo(name = "test_flag_public_static", help = "")
public final Flag<Long> testStaticClash = Flagz.valueOf(999L);
}
;
private ContainerOne one = new ContainerOne();
private ContainerTwo two = new ContainerTwo();
private ContainerClashingWithStatic clashing = new ContainerClashingWithStatic();
private Set<Object> goodContainers = ImmutableSet.of(one, two);
private Set<Object> clashingContainers = ImmutableSet.of(one, two, clashing);
@Test
public void testGeneric_FieldNameResolution() {
String[] args = {"--testFieldNameFlag=101010"};
Flagz.parse(args, EMPTY_PACKAGE_PREFIXES, goodContainers);
|
// Path: flagz-java/src/test/java/org/flagz/testclasses/StaticFlags.java
// public class StaticFlags {
//
// @FlagInfo(help = "for testing of resolution with no name argument")
// public static final Flag<Integer> testFieldNameFlag = Flagz.valueOf(0);
//
// @FlagInfo(name = "test_alt_name", help = "for testing of resolution with alt name", altName = "t_alt")
// public static final Flag<String> testAltNameFlag = Flagz.valueOf("my_alt");
//
// @FlagInfo(name = "test_flag_full_name", help = "for testing of resolution with full name")
// public static final Flag<Long> testFullNameFlag = Flagz.valueOf(0L);
//
// @FlagInfo(name = "test_flag_private_static", help = "for testing of resolution of private static fields")
// private static final Flag<Long> testPrivateStaticFlag = Flagz.valueOf(0L);
//
// @FlagInfo(name = "test_flag_public_static", help = "for testing of resolution of public static fields")
// public static final Flag<Long> testPublicStaticFlag = Flagz.valueOf(0L);
//
// @FlagInfo(name = "test_flag_non_static", help = "for validating that we won't see non static fields")
// private final Flag<Long> testInvisibleNonStaticFlag = Flagz.valueOf(0L);
//
//
// public static Flag<Long> testPrivateStaticFlagAccessor() {
// return testPrivateStaticFlag;
// }
//
// @SuppressWarnings("unchecked")
// public static void resetToDefaults() {
// List<Flag<?>> list = ImmutableList.of(
// testFieldNameFlag, testAltNameFlag, testFullNameFlag, testPrivateStaticFlag, testPublicStaticFlag);
// for (Flag f : list) {
// f.accept(f.defaultValue());
// }
// }
// }
// Path: flagz-java/src/test/java/org/flagz/FlagFieldScannerTest.java
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.flagz.testclasses.StaticFlags;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
}
}
;
static class ContainerTwo {
@FlagInfo(name = "test_flag_obj_public_two", help = "")
public final Flag<Long> testPublicFlag = Flagz.valueOf(999L);
}
;
static class ContainerClashingWithStatic {
@FlagInfo(name = "test_flag_public_static", help = "")
public final Flag<Long> testStaticClash = Flagz.valueOf(999L);
}
;
private ContainerOne one = new ContainerOne();
private ContainerTwo two = new ContainerTwo();
private ContainerClashingWithStatic clashing = new ContainerClashingWithStatic();
private Set<Object> goodContainers = ImmutableSet.of(one, two);
private Set<Object> clashingContainers = ImmutableSet.of(one, two, clashing);
@Test
public void testGeneric_FieldNameResolution() {
String[] args = {"--testFieldNameFlag=101010"};
Flagz.parse(args, EMPTY_PACKAGE_PREFIXES, goodContainers);
|
assertThat(StaticFlags.testFieldNameFlag.get(), is(101010));
|
mwitkow/java-flagz
|
flagz-java/src/test/java/org/flagz/ContainerFlagFieldTest.java
|
// Path: flagz-java/src/test/java/org/flagz/testclasses/SomeEnum.java
// public enum SomeEnum {
// CRAZY,
// WACKY,
// NORMAL,
// CHILLED,
// }
|
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.flagz.testclasses.SomeEnum;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
|
package org.flagz;
/**
* Tests of flags that contain other values (Sets, Lists, Maps).
*
* **Note:** All flags are declared in-object, and the `this` object is passed to Flagz to find these fields. We are not
* testing the ability of Flagz to resolve fields, just value parsing.
*/
public class ContainerFlagFieldTest {
public static final String[] EMPTY_ARGS = {};
public static final List<String> EMPTY_PACKAGE_PREFIXES = ImmutableList.of();
@FlagInfo(name = "test_list_int_flag", help = "")
final Flag<List<Integer>> integerListFlag = Flagz.valueOf(ImmutableList.of(1337, 9999));
@FlagInfo(name = "test_set_string_flag", help = "")
final Flag<Set<String>> stringSetFlag = Flagz.valueOf(ImmutableSet.of("elite", "awesome"));
@FlagInfo(name = "test_list_enum_flag", help = "")
|
// Path: flagz-java/src/test/java/org/flagz/testclasses/SomeEnum.java
// public enum SomeEnum {
// CRAZY,
// WACKY,
// NORMAL,
// CHILLED,
// }
// Path: flagz-java/src/test/java/org/flagz/ContainerFlagFieldTest.java
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.flagz.testclasses.SomeEnum;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
package org.flagz;
/**
* Tests of flags that contain other values (Sets, Lists, Maps).
*
* **Note:** All flags are declared in-object, and the `this` object is passed to Flagz to find these fields. We are not
* testing the ability of Flagz to resolve fields, just value parsing.
*/
public class ContainerFlagFieldTest {
public static final String[] EMPTY_ARGS = {};
public static final List<String> EMPTY_PACKAGE_PREFIXES = ImmutableList.of();
@FlagInfo(name = "test_list_int_flag", help = "")
final Flag<List<Integer>> integerListFlag = Flagz.valueOf(ImmutableList.of(1337, 9999));
@FlagInfo(name = "test_set_string_flag", help = "")
final Flag<Set<String>> stringSetFlag = Flagz.valueOf(ImmutableSet.of("elite", "awesome"));
@FlagInfo(name = "test_list_enum_flag", help = "")
|
final Flag<List<SomeEnum>> enumListFlag = Flagz.valueOf(ImmutableList.of(SomeEnum.NORMAL, SomeEnum.CHILLED));
|
mwitkow/java-flagz
|
flagz-java/src/test/java/org/flagz/testclasses/StaticFlags.java
|
// Path: flagz-java/src/main/java/org/flagz/Flag.java
// public interface Flag<T> extends Supplier<T>, Consumer<T> {
//
// /** Returns the value of this flag. */
// T get();
//
// /** Returns the default value of this flag. */
// T defaultValue();
//
// /** Sets the value of this flag. */
// void accept(T flagValue);
//
// /**
// * Returns the user-visible flag name.
// */
// String name();
//
// /**
// * Returns a user-visible alternative name for the flag, if any.
// */
// @Nullable
// String altName();
//
// /**
// * Returns the user-visible help string of the flag.
// */
// String help();
//
//
// Flag<T> withValidator(Predicate<T> predicate);
//
// /**
// * Add a listener for changes to this flag.
// *
// * Whenever the flag is changed (parsed from command line, or set dynamically), the given
// * listener will be called.
// */
// Flag<T> withListener(Consumer<T> predicate);
// }
//
// Path: flagz-java/src/main/java/org/flagz/Flagz.java
// public class Flagz {
//
// @FlagInfo(name = "help", altName = "h", help = "display this help menu")
// private static final Flag<Boolean> showHelp = Flagz.valueOf(false);
//
// protected Flagz() {
// }
//
// public static <N extends Number> Flag<N> valueOf(N defaultValue) {
// return new PrimitiveFlagField.NumberFlagField<>(defaultValue);
// }
//
// public static Flag<Boolean> valueOf(Boolean defaultValue) {
// return new PrimitiveFlagField.BooleanFlagField(defaultValue);
// }
//
// public static <E extends Enum<E>> Flag<E> valueOf(E defaultValue) {
// return new PrimitiveFlagField.EnumFlagField<>(defaultValue);
// }
//
// public static Flag<String> valueOf(String defaultValue) {
// return new PrimitiveFlagField.StringFlagField(defaultValue);
// }
//
// public static <K, V> Flag<Map<K, V>> valueOf(Map<K, V> defaultMap) {
// return new ContainerFlagField.MapFlagField<>(defaultMap, HashMap::new);
// }
//
// public static <V> Flag<List<V>> valueOf(List<V> defaultList) {
// return new ContainerFlagField.CollectionFlagField<>(defaultList, ArrayList::new);
// }
//
// public static <V> Flag<Set<V>> valueOf(Set<V> defaultSet) {
// return new ContainerFlagField.CollectionFlagField<>(defaultSet, HashSet::new);
// }
//
//
// /**
// * Parses the command line arguments and updates as necessary all {@link Flag}
// * objects annotated with {@link FlagInfo}.
// *
// * If "--help" of "-h" is passed in at the command line, then the help menu
// * will be printed and the JVM will exit with a 0 exit status.
// *
// * @param args command line arguments in the form
// * "--defaultFlagName=value --booleanFlag -c=foo ..."
// * @param packagePrefixes list of Java packages to be scanned for Flag objects, keeping the scope
// * narrow makes it start fast. By default an empty list is used, meaning
// * all classes will be reflected on.
// * @param objects Set of objects that should be reflected to discover non-static final
// * {@link Flag} fields.
// * @return A registry that can be used for accessing all flags.
// */
// public static FlagFieldRegistry parse(String[] args, List<String> packagePrefixes,
// Set<Object> objects) {
// Set<FlagFieldScanner> scanners = ImmutableSet.of(
// new FlagFieldScanner.ObjectBoundFinalScanner(objects),
// new FlagFieldScanner.StaticFinalScanner(packagePrefixes));
// FlagFieldRegistry registry = new FlagFieldRegistry(scanners);
// registry.init();
// registry.parseAll(Utils.parseArgsToFieldMap(args));
//
// if (showHelp.get()) {
// Utils.printHelpPage(registry.allFields());
// System.exit(0);
// }
// return registry;
// }
//
//
// public static FlagFieldRegistry parse(String[] args) {
// return parse(args, ImmutableList.<String>of(), ImmutableSet.<Object>of());
// }
// }
|
import com.google.common.collect.ImmutableList;
import org.flagz.Flag;
import org.flagz.FlagInfo;
import org.flagz.Flagz;
import java.util.List;
|
package org.flagz.testclasses;
/**
* Set of flags that are useful for testing of {@link Flagz}.
*/
public class StaticFlags {
@FlagInfo(help = "for testing of resolution with no name argument")
|
// Path: flagz-java/src/main/java/org/flagz/Flag.java
// public interface Flag<T> extends Supplier<T>, Consumer<T> {
//
// /** Returns the value of this flag. */
// T get();
//
// /** Returns the default value of this flag. */
// T defaultValue();
//
// /** Sets the value of this flag. */
// void accept(T flagValue);
//
// /**
// * Returns the user-visible flag name.
// */
// String name();
//
// /**
// * Returns a user-visible alternative name for the flag, if any.
// */
// @Nullable
// String altName();
//
// /**
// * Returns the user-visible help string of the flag.
// */
// String help();
//
//
// Flag<T> withValidator(Predicate<T> predicate);
//
// /**
// * Add a listener for changes to this flag.
// *
// * Whenever the flag is changed (parsed from command line, or set dynamically), the given
// * listener will be called.
// */
// Flag<T> withListener(Consumer<T> predicate);
// }
//
// Path: flagz-java/src/main/java/org/flagz/Flagz.java
// public class Flagz {
//
// @FlagInfo(name = "help", altName = "h", help = "display this help menu")
// private static final Flag<Boolean> showHelp = Flagz.valueOf(false);
//
// protected Flagz() {
// }
//
// public static <N extends Number> Flag<N> valueOf(N defaultValue) {
// return new PrimitiveFlagField.NumberFlagField<>(defaultValue);
// }
//
// public static Flag<Boolean> valueOf(Boolean defaultValue) {
// return new PrimitiveFlagField.BooleanFlagField(defaultValue);
// }
//
// public static <E extends Enum<E>> Flag<E> valueOf(E defaultValue) {
// return new PrimitiveFlagField.EnumFlagField<>(defaultValue);
// }
//
// public static Flag<String> valueOf(String defaultValue) {
// return new PrimitiveFlagField.StringFlagField(defaultValue);
// }
//
// public static <K, V> Flag<Map<K, V>> valueOf(Map<K, V> defaultMap) {
// return new ContainerFlagField.MapFlagField<>(defaultMap, HashMap::new);
// }
//
// public static <V> Flag<List<V>> valueOf(List<V> defaultList) {
// return new ContainerFlagField.CollectionFlagField<>(defaultList, ArrayList::new);
// }
//
// public static <V> Flag<Set<V>> valueOf(Set<V> defaultSet) {
// return new ContainerFlagField.CollectionFlagField<>(defaultSet, HashSet::new);
// }
//
//
// /**
// * Parses the command line arguments and updates as necessary all {@link Flag}
// * objects annotated with {@link FlagInfo}.
// *
// * If "--help" of "-h" is passed in at the command line, then the help menu
// * will be printed and the JVM will exit with a 0 exit status.
// *
// * @param args command line arguments in the form
// * "--defaultFlagName=value --booleanFlag -c=foo ..."
// * @param packagePrefixes list of Java packages to be scanned for Flag objects, keeping the scope
// * narrow makes it start fast. By default an empty list is used, meaning
// * all classes will be reflected on.
// * @param objects Set of objects that should be reflected to discover non-static final
// * {@link Flag} fields.
// * @return A registry that can be used for accessing all flags.
// */
// public static FlagFieldRegistry parse(String[] args, List<String> packagePrefixes,
// Set<Object> objects) {
// Set<FlagFieldScanner> scanners = ImmutableSet.of(
// new FlagFieldScanner.ObjectBoundFinalScanner(objects),
// new FlagFieldScanner.StaticFinalScanner(packagePrefixes));
// FlagFieldRegistry registry = new FlagFieldRegistry(scanners);
// registry.init();
// registry.parseAll(Utils.parseArgsToFieldMap(args));
//
// if (showHelp.get()) {
// Utils.printHelpPage(registry.allFields());
// System.exit(0);
// }
// return registry;
// }
//
//
// public static FlagFieldRegistry parse(String[] args) {
// return parse(args, ImmutableList.<String>of(), ImmutableSet.<Object>of());
// }
// }
// Path: flagz-java/src/test/java/org/flagz/testclasses/StaticFlags.java
import com.google.common.collect.ImmutableList;
import org.flagz.Flag;
import org.flagz.FlagInfo;
import org.flagz.Flagz;
import java.util.List;
package org.flagz.testclasses;
/**
* Set of flags that are useful for testing of {@link Flagz}.
*/
public class StaticFlags {
@FlagInfo(help = "for testing of resolution with no name argument")
|
public static final Flag<Integer> testFieldNameFlag = Flagz.valueOf(0);
|
mwitkow/java-flagz
|
flagz-java/src/test/java/org/flagz/testclasses/StaticFlags.java
|
// Path: flagz-java/src/main/java/org/flagz/Flag.java
// public interface Flag<T> extends Supplier<T>, Consumer<T> {
//
// /** Returns the value of this flag. */
// T get();
//
// /** Returns the default value of this flag. */
// T defaultValue();
//
// /** Sets the value of this flag. */
// void accept(T flagValue);
//
// /**
// * Returns the user-visible flag name.
// */
// String name();
//
// /**
// * Returns a user-visible alternative name for the flag, if any.
// */
// @Nullable
// String altName();
//
// /**
// * Returns the user-visible help string of the flag.
// */
// String help();
//
//
// Flag<T> withValidator(Predicate<T> predicate);
//
// /**
// * Add a listener for changes to this flag.
// *
// * Whenever the flag is changed (parsed from command line, or set dynamically), the given
// * listener will be called.
// */
// Flag<T> withListener(Consumer<T> predicate);
// }
//
// Path: flagz-java/src/main/java/org/flagz/Flagz.java
// public class Flagz {
//
// @FlagInfo(name = "help", altName = "h", help = "display this help menu")
// private static final Flag<Boolean> showHelp = Flagz.valueOf(false);
//
// protected Flagz() {
// }
//
// public static <N extends Number> Flag<N> valueOf(N defaultValue) {
// return new PrimitiveFlagField.NumberFlagField<>(defaultValue);
// }
//
// public static Flag<Boolean> valueOf(Boolean defaultValue) {
// return new PrimitiveFlagField.BooleanFlagField(defaultValue);
// }
//
// public static <E extends Enum<E>> Flag<E> valueOf(E defaultValue) {
// return new PrimitiveFlagField.EnumFlagField<>(defaultValue);
// }
//
// public static Flag<String> valueOf(String defaultValue) {
// return new PrimitiveFlagField.StringFlagField(defaultValue);
// }
//
// public static <K, V> Flag<Map<K, V>> valueOf(Map<K, V> defaultMap) {
// return new ContainerFlagField.MapFlagField<>(defaultMap, HashMap::new);
// }
//
// public static <V> Flag<List<V>> valueOf(List<V> defaultList) {
// return new ContainerFlagField.CollectionFlagField<>(defaultList, ArrayList::new);
// }
//
// public static <V> Flag<Set<V>> valueOf(Set<V> defaultSet) {
// return new ContainerFlagField.CollectionFlagField<>(defaultSet, HashSet::new);
// }
//
//
// /**
// * Parses the command line arguments and updates as necessary all {@link Flag}
// * objects annotated with {@link FlagInfo}.
// *
// * If "--help" of "-h" is passed in at the command line, then the help menu
// * will be printed and the JVM will exit with a 0 exit status.
// *
// * @param args command line arguments in the form
// * "--defaultFlagName=value --booleanFlag -c=foo ..."
// * @param packagePrefixes list of Java packages to be scanned for Flag objects, keeping the scope
// * narrow makes it start fast. By default an empty list is used, meaning
// * all classes will be reflected on.
// * @param objects Set of objects that should be reflected to discover non-static final
// * {@link Flag} fields.
// * @return A registry that can be used for accessing all flags.
// */
// public static FlagFieldRegistry parse(String[] args, List<String> packagePrefixes,
// Set<Object> objects) {
// Set<FlagFieldScanner> scanners = ImmutableSet.of(
// new FlagFieldScanner.ObjectBoundFinalScanner(objects),
// new FlagFieldScanner.StaticFinalScanner(packagePrefixes));
// FlagFieldRegistry registry = new FlagFieldRegistry(scanners);
// registry.init();
// registry.parseAll(Utils.parseArgsToFieldMap(args));
//
// if (showHelp.get()) {
// Utils.printHelpPage(registry.allFields());
// System.exit(0);
// }
// return registry;
// }
//
//
// public static FlagFieldRegistry parse(String[] args) {
// return parse(args, ImmutableList.<String>of(), ImmutableSet.<Object>of());
// }
// }
|
import com.google.common.collect.ImmutableList;
import org.flagz.Flag;
import org.flagz.FlagInfo;
import org.flagz.Flagz;
import java.util.List;
|
package org.flagz.testclasses;
/**
* Set of flags that are useful for testing of {@link Flagz}.
*/
public class StaticFlags {
@FlagInfo(help = "for testing of resolution with no name argument")
|
// Path: flagz-java/src/main/java/org/flagz/Flag.java
// public interface Flag<T> extends Supplier<T>, Consumer<T> {
//
// /** Returns the value of this flag. */
// T get();
//
// /** Returns the default value of this flag. */
// T defaultValue();
//
// /** Sets the value of this flag. */
// void accept(T flagValue);
//
// /**
// * Returns the user-visible flag name.
// */
// String name();
//
// /**
// * Returns a user-visible alternative name for the flag, if any.
// */
// @Nullable
// String altName();
//
// /**
// * Returns the user-visible help string of the flag.
// */
// String help();
//
//
// Flag<T> withValidator(Predicate<T> predicate);
//
// /**
// * Add a listener for changes to this flag.
// *
// * Whenever the flag is changed (parsed from command line, or set dynamically), the given
// * listener will be called.
// */
// Flag<T> withListener(Consumer<T> predicate);
// }
//
// Path: flagz-java/src/main/java/org/flagz/Flagz.java
// public class Flagz {
//
// @FlagInfo(name = "help", altName = "h", help = "display this help menu")
// private static final Flag<Boolean> showHelp = Flagz.valueOf(false);
//
// protected Flagz() {
// }
//
// public static <N extends Number> Flag<N> valueOf(N defaultValue) {
// return new PrimitiveFlagField.NumberFlagField<>(defaultValue);
// }
//
// public static Flag<Boolean> valueOf(Boolean defaultValue) {
// return new PrimitiveFlagField.BooleanFlagField(defaultValue);
// }
//
// public static <E extends Enum<E>> Flag<E> valueOf(E defaultValue) {
// return new PrimitiveFlagField.EnumFlagField<>(defaultValue);
// }
//
// public static Flag<String> valueOf(String defaultValue) {
// return new PrimitiveFlagField.StringFlagField(defaultValue);
// }
//
// public static <K, V> Flag<Map<K, V>> valueOf(Map<K, V> defaultMap) {
// return new ContainerFlagField.MapFlagField<>(defaultMap, HashMap::new);
// }
//
// public static <V> Flag<List<V>> valueOf(List<V> defaultList) {
// return new ContainerFlagField.CollectionFlagField<>(defaultList, ArrayList::new);
// }
//
// public static <V> Flag<Set<V>> valueOf(Set<V> defaultSet) {
// return new ContainerFlagField.CollectionFlagField<>(defaultSet, HashSet::new);
// }
//
//
// /**
// * Parses the command line arguments and updates as necessary all {@link Flag}
// * objects annotated with {@link FlagInfo}.
// *
// * If "--help" of "-h" is passed in at the command line, then the help menu
// * will be printed and the JVM will exit with a 0 exit status.
// *
// * @param args command line arguments in the form
// * "--defaultFlagName=value --booleanFlag -c=foo ..."
// * @param packagePrefixes list of Java packages to be scanned for Flag objects, keeping the scope
// * narrow makes it start fast. By default an empty list is used, meaning
// * all classes will be reflected on.
// * @param objects Set of objects that should be reflected to discover non-static final
// * {@link Flag} fields.
// * @return A registry that can be used for accessing all flags.
// */
// public static FlagFieldRegistry parse(String[] args, List<String> packagePrefixes,
// Set<Object> objects) {
// Set<FlagFieldScanner> scanners = ImmutableSet.of(
// new FlagFieldScanner.ObjectBoundFinalScanner(objects),
// new FlagFieldScanner.StaticFinalScanner(packagePrefixes));
// FlagFieldRegistry registry = new FlagFieldRegistry(scanners);
// registry.init();
// registry.parseAll(Utils.parseArgsToFieldMap(args));
//
// if (showHelp.get()) {
// Utils.printHelpPage(registry.allFields());
// System.exit(0);
// }
// return registry;
// }
//
//
// public static FlagFieldRegistry parse(String[] args) {
// return parse(args, ImmutableList.<String>of(), ImmutableSet.<Object>of());
// }
// }
// Path: flagz-java/src/test/java/org/flagz/testclasses/StaticFlags.java
import com.google.common.collect.ImmutableList;
import org.flagz.Flag;
import org.flagz.FlagInfo;
import org.flagz.Flagz;
import java.util.List;
package org.flagz.testclasses;
/**
* Set of flags that are useful for testing of {@link Flagz}.
*/
public class StaticFlags {
@FlagInfo(help = "for testing of resolution with no name argument")
|
public static final Flag<Integer> testFieldNameFlag = Flagz.valueOf(0);
|
mwitkow/java-flagz
|
flagz-java/src/test/java/org/flagz/PrimitiveFlagFieldTest.java
|
// Path: flagz-java/src/test/java/org/flagz/testclasses/SomeEnum.java
// public enum SomeEnum {
// CRAZY,
// WACKY,
// NORMAL,
// CHILLED,
// }
|
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.flagz.testclasses.SomeEnum;
import org.junit.Test;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
|
package org.flagz;
/**
* Tests of flags of primitive types.
*
* **Note:** All flags are declared in-object, and the `this` object is passed to Flagz to find these fields. We are not
* testing the ability of Flagz to resolve fields, just value parsing.
*/
public class PrimitiveFlagFieldTest {
public static final String[] EMPTY_ARGS = {};
public static final List<String> EMPTY_PACKAGE_PREFIXES = ImmutableList.of();
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {}
@Retention(RetentionPolicy.RUNTIME)
public @interface OtherCustomAnnotation {}
@FlagInfo(name = "test_int_flag", help = "")
final Flag<Integer> integerFlag = Flagz.valueOf(1337);
@FlagInfo(name = "test_long_flag", help = "")
final Flag<Long> longFlag = Flagz.valueOf(13371337L);
@FlagInfo(name = "test_double_flag", help = "")
final Flag<Double> doubleFlag = Flagz.valueOf(13.37);
@FlagInfo(name = "test_float_flag", help = "")
final Flag<Float> floatFlag = Flagz.valueOf((float) 13.37);
@FlagInfo(name = "test_bool_flag", help = "")
final Flag<Boolean> booleanFlag = Flagz.valueOf(false);
@FlagInfo(name = "test_string_flag", help = "")
final Flag<String> stringFlag = Flagz.valueOf("elite");
@FlagInfo(name = "test_short_flag", help = "")
final Flag<Short> shortFlag = Flagz.valueOf((short) 13);
@FlagInfo(name = "test_byte_flag", help = "")
final Flag<Byte> byteFlag = Flagz.valueOf((byte) 0xDD);
@FlagInfo(name = "test_enum_flag", help = "")
|
// Path: flagz-java/src/test/java/org/flagz/testclasses/SomeEnum.java
// public enum SomeEnum {
// CRAZY,
// WACKY,
// NORMAL,
// CHILLED,
// }
// Path: flagz-java/src/test/java/org/flagz/PrimitiveFlagFieldTest.java
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.flagz.testclasses.SomeEnum;
import org.junit.Test;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
package org.flagz;
/**
* Tests of flags of primitive types.
*
* **Note:** All flags are declared in-object, and the `this` object is passed to Flagz to find these fields. We are not
* testing the ability of Flagz to resolve fields, just value parsing.
*/
public class PrimitiveFlagFieldTest {
public static final String[] EMPTY_ARGS = {};
public static final List<String> EMPTY_PACKAGE_PREFIXES = ImmutableList.of();
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {}
@Retention(RetentionPolicy.RUNTIME)
public @interface OtherCustomAnnotation {}
@FlagInfo(name = "test_int_flag", help = "")
final Flag<Integer> integerFlag = Flagz.valueOf(1337);
@FlagInfo(name = "test_long_flag", help = "")
final Flag<Long> longFlag = Flagz.valueOf(13371337L);
@FlagInfo(name = "test_double_flag", help = "")
final Flag<Double> doubleFlag = Flagz.valueOf(13.37);
@FlagInfo(name = "test_float_flag", help = "")
final Flag<Float> floatFlag = Flagz.valueOf((float) 13.37);
@FlagInfo(name = "test_bool_flag", help = "")
final Flag<Boolean> booleanFlag = Flagz.valueOf(false);
@FlagInfo(name = "test_string_flag", help = "")
final Flag<String> stringFlag = Flagz.valueOf("elite");
@FlagInfo(name = "test_short_flag", help = "")
final Flag<Short> shortFlag = Flagz.valueOf((short) 13);
@FlagInfo(name = "test_byte_flag", help = "")
final Flag<Byte> byteFlag = Flagz.valueOf((byte) 0xDD);
@FlagInfo(name = "test_enum_flag", help = "")
|
final Flag<SomeEnum> enumFlag = Flagz.valueOf(SomeEnum.NORMAL);
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/StarHashExtractor.java
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class TimeStarComparator implements Comparator<Star> {
// @Override
// public int compare(Star o1, Star o2) {
// int t1 = o1.getTick();
// int t2 = o2.getTick();
//
// if (t1 == t2) {
// return 0;
// }
// else if (t1 < t2) {
// return -1;
// }
// else {
// return 1;
// }
// }
// }
|
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.sidoh.collections.TreeMapOfSets;
import org.sidoh.io.ProgressNotifier;
import org.sidoh.io.ProgressNotifier.Builder;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.TimeStarComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
|
package org.sidoh.song_recognition.signature;
public class StarHashExtractor implements SpectrogramSignatureExtractor<StarHashSignature> {
private final ConstellationMapExtractor starExtractor;
private final Region.Builder regionBuilder;
private final int timeResolution;
private final ProgressNotifier.Builder progress;
private final Region.Builder reverseRegionBuilder;
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this(starExtractor, regionBuilder, null, timeResolution, progress);
}
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
Region.Builder reverseRegionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this.starExtractor = starExtractor;
this.regionBuilder = regionBuilder;
this.reverseRegionBuilder = reverseRegionBuilder;
this.timeResolution = timeResolution;
this.progress = progress;
}
@Override
public StarHashSignature extractSignature(Spectrogram spec) {
ConstellationMapSignature starSig = starExtractor.extractSignature(spec);
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class TimeStarComparator implements Comparator<Star> {
// @Override
// public int compare(Star o1, Star o2) {
// int t1 = o1.getTick();
// int t2 = o2.getTick();
//
// if (t1 == t2) {
// return 0;
// }
// else if (t1 < t2) {
// return -1;
// }
// else {
// return 1;
// }
// }
// }
// Path: src/java/org/sidoh/song_recognition/signature/StarHashExtractor.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.sidoh.collections.TreeMapOfSets;
import org.sidoh.io.ProgressNotifier;
import org.sidoh.io.ProgressNotifier.Builder;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.TimeStarComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
package org.sidoh.song_recognition.signature;
public class StarHashExtractor implements SpectrogramSignatureExtractor<StarHashSignature> {
private final ConstellationMapExtractor starExtractor;
private final Region.Builder regionBuilder;
private final int timeResolution;
private final ProgressNotifier.Builder progress;
private final Region.Builder reverseRegionBuilder;
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this(starExtractor, regionBuilder, null, timeResolution, progress);
}
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
Region.Builder reverseRegionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this.starExtractor = starExtractor;
this.regionBuilder = regionBuilder;
this.reverseRegionBuilder = reverseRegionBuilder;
this.timeResolution = timeResolution;
this.progress = progress;
}
@Override
public StarHashSignature extractSignature(Spectrogram spec) {
ConstellationMapSignature starSig = starExtractor.extractSignature(spec);
|
List<Star> stars = new ArrayList<Star>(starSig.getConstellationMap().getStars());
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/StarHashExtractor.java
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class TimeStarComparator implements Comparator<Star> {
// @Override
// public int compare(Star o1, Star o2) {
// int t1 = o1.getTick();
// int t2 = o2.getTick();
//
// if (t1 == t2) {
// return 0;
// }
// else if (t1 < t2) {
// return -1;
// }
// else {
// return 1;
// }
// }
// }
|
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.sidoh.collections.TreeMapOfSets;
import org.sidoh.io.ProgressNotifier;
import org.sidoh.io.ProgressNotifier.Builder;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.TimeStarComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
|
package org.sidoh.song_recognition.signature;
public class StarHashExtractor implements SpectrogramSignatureExtractor<StarHashSignature> {
private final ConstellationMapExtractor starExtractor;
private final Region.Builder regionBuilder;
private final int timeResolution;
private final ProgressNotifier.Builder progress;
private final Region.Builder reverseRegionBuilder;
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this(starExtractor, regionBuilder, null, timeResolution, progress);
}
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
Region.Builder reverseRegionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this.starExtractor = starExtractor;
this.regionBuilder = regionBuilder;
this.reverseRegionBuilder = reverseRegionBuilder;
this.timeResolution = timeResolution;
this.progress = progress;
}
@Override
public StarHashSignature extractSignature(Spectrogram spec) {
ConstellationMapSignature starSig = starExtractor.extractSignature(spec);
List<Star> stars = new ArrayList<Star>(starSig.getConstellationMap().getStars());
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class TimeStarComparator implements Comparator<Star> {
// @Override
// public int compare(Star o1, Star o2) {
// int t1 = o1.getTick();
// int t2 = o2.getTick();
//
// if (t1 == t2) {
// return 0;
// }
// else if (t1 < t2) {
// return -1;
// }
// else {
// return 1;
// }
// }
// }
// Path: src/java/org/sidoh/song_recognition/signature/StarHashExtractor.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.sidoh.collections.TreeMapOfSets;
import org.sidoh.io.ProgressNotifier;
import org.sidoh.io.ProgressNotifier.Builder;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.TimeStarComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
package org.sidoh.song_recognition.signature;
public class StarHashExtractor implements SpectrogramSignatureExtractor<StarHashSignature> {
private final ConstellationMapExtractor starExtractor;
private final Region.Builder regionBuilder;
private final int timeResolution;
private final ProgressNotifier.Builder progress;
private final Region.Builder reverseRegionBuilder;
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this(starExtractor, regionBuilder, null, timeResolution, progress);
}
public StarHashExtractor(ConstellationMapExtractor starExtractor,
Region.Builder regionBuilder,
Region.Builder reverseRegionBuilder,
int timeResolution,
ProgressNotifier.Builder progress) {
this.starExtractor = starExtractor;
this.regionBuilder = regionBuilder;
this.reverseRegionBuilder = reverseRegionBuilder;
this.timeResolution = timeResolution;
this.progress = progress;
}
@Override
public StarHashSignature extractSignature(Spectrogram spec) {
ConstellationMapSignature starSig = starExtractor.extractSignature(spec);
List<Star> stars = new ArrayList<Star>(starSig.getConstellationMap().getStars());
|
Collections.sort(stars, new TimeStarComparator());
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/CoordinateAgnosticStarBuffer.java
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class StarEnergyComparator implements Comparator<Star> {
//
// private final boolean reverse;
//
// public StarEnergyComparator(boolean reverse) {
// this.reverse = reverse;
// }
//
// @Override
// public int compare(Star o1, Star o2) {
// if (o1 == null || o2 == null) {
// throw new IllegalArgumentException("Can't compare null - " + o1 + " // " + o2 + "!");
// }
//
// if (reverse) {
// return Double.compare(o2.getIntensity(), o1.getIntensity());
// }
// else {
// return Double.compare(o1.getIntensity(), o2.getIntensity());
// }
// }
//
// }
|
import java.util.Collection;
import java.util.Collections;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.StarEnergyComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
|
package org.sidoh.song_recognition.signature;
/**
* This {@link StarBuffer} doesn't care where stars come from. It just keeps
* track of the ones with the highest intensity using a {@link MinMaxPriorityQueue}.
*
* @author chris
*
*/
public class CoordinateAgnosticStarBuffer extends StarBuffer {
public static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
@Override
public StarBuffer create(Spectrogram spec) {
return new CoordinateAgnosticStarBuffer(spec, starDensityFactor);
}
}
private final double starDensityFactor;
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class StarEnergyComparator implements Comparator<Star> {
//
// private final boolean reverse;
//
// public StarEnergyComparator(boolean reverse) {
// this.reverse = reverse;
// }
//
// @Override
// public int compare(Star o1, Star o2) {
// if (o1 == null || o2 == null) {
// throw new IllegalArgumentException("Can't compare null - " + o1 + " // " + o2 + "!");
// }
//
// if (reverse) {
// return Double.compare(o2.getIntensity(), o1.getIntensity());
// }
// else {
// return Double.compare(o1.getIntensity(), o2.getIntensity());
// }
// }
//
// }
// Path: src/java/org/sidoh/song_recognition/signature/CoordinateAgnosticStarBuffer.java
import java.util.Collection;
import java.util.Collections;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.StarEnergyComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
package org.sidoh.song_recognition.signature;
/**
* This {@link StarBuffer} doesn't care where stars come from. It just keeps
* track of the ones with the highest intensity using a {@link MinMaxPriorityQueue}.
*
* @author chris
*
*/
public class CoordinateAgnosticStarBuffer extends StarBuffer {
public static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
@Override
public StarBuffer create(Spectrogram spec) {
return new CoordinateAgnosticStarBuffer(spec, starDensityFactor);
}
}
private final double starDensityFactor;
|
private final Collection<Star> pq;
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/CoordinateAgnosticStarBuffer.java
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class StarEnergyComparator implements Comparator<Star> {
//
// private final boolean reverse;
//
// public StarEnergyComparator(boolean reverse) {
// this.reverse = reverse;
// }
//
// @Override
// public int compare(Star o1, Star o2) {
// if (o1 == null || o2 == null) {
// throw new IllegalArgumentException("Can't compare null - " + o1 + " // " + o2 + "!");
// }
//
// if (reverse) {
// return Double.compare(o2.getIntensity(), o1.getIntensity());
// }
// else {
// return Double.compare(o1.getIntensity(), o2.getIntensity());
// }
// }
//
// }
|
import java.util.Collection;
import java.util.Collections;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.StarEnergyComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
|
package org.sidoh.song_recognition.signature;
/**
* This {@link StarBuffer} doesn't care where stars come from. It just keeps
* track of the ones with the highest intensity using a {@link MinMaxPriorityQueue}.
*
* @author chris
*
*/
public class CoordinateAgnosticStarBuffer extends StarBuffer {
public static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
@Override
public StarBuffer create(Spectrogram spec) {
return new CoordinateAgnosticStarBuffer(spec, starDensityFactor);
}
}
private final double starDensityFactor;
private final Collection<Star> pq;
public CoordinateAgnosticStarBuffer(Spectrogram spec, double starDensityFactor) {
super(spec);
this.starDensityFactor = starDensityFactor;
this.pq = Collections.synchronizedCollection(MinMaxPriorityQueue
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class StarEnergyComparator implements Comparator<Star> {
//
// private final boolean reverse;
//
// public StarEnergyComparator(boolean reverse) {
// this.reverse = reverse;
// }
//
// @Override
// public int compare(Star o1, Star o2) {
// if (o1 == null || o2 == null) {
// throw new IllegalArgumentException("Can't compare null - " + o1 + " // " + o2 + "!");
// }
//
// if (reverse) {
// return Double.compare(o2.getIntensity(), o1.getIntensity());
// }
// else {
// return Double.compare(o1.getIntensity(), o2.getIntensity());
// }
// }
//
// }
// Path: src/java/org/sidoh/song_recognition/signature/CoordinateAgnosticStarBuffer.java
import java.util.Collection;
import java.util.Collections;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.signature.ConstellationMap.StarEnergyComparator;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
package org.sidoh.song_recognition.signature;
/**
* This {@link StarBuffer} doesn't care where stars come from. It just keeps
* track of the ones with the highest intensity using a {@link MinMaxPriorityQueue}.
*
* @author chris
*
*/
public class CoordinateAgnosticStarBuffer extends StarBuffer {
public static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
@Override
public StarBuffer create(Spectrogram spec) {
return new CoordinateAgnosticStarBuffer(spec, starDensityFactor);
}
}
private final double starDensityFactor;
private final Collection<Star> pq;
public CoordinateAgnosticStarBuffer(Spectrogram spec, double starDensityFactor) {
super(spec);
this.starDensityFactor = starDensityFactor;
this.pq = Collections.synchronizedCollection(MinMaxPriorityQueue
|
.orderedBy(new StarEnergyComparator(true))
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/StarBuffer.java
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
|
import java.util.Iterator;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
|
package org.sidoh.song_recognition.signature;
/**
* This is used in conjunction with {@link ConstellationMapExtractor} to extract
* {@link Star}s (Spectrogram peaks). It is fed potential peaks and the coordinates
* that they reside at, and it keeps track of which ones it likes to keep (in
* memory).
*
* It should support an operation called flush(), which should return an
* {@link Iterator} of {@link Star}s that it'd like to keep.
*
* {@link StarBuffer}s are required to be thread safe.
*
* @author chris
*/
public abstract class StarBuffer {
public static abstract class Builder {
protected static final double[] fairSizes = {0.05d, 0.15, 0.40d};
protected static final double[] fairWeights = {0.1d, 0.7d, 0.2d};
protected double starDensityFactor;
public Builder(double starDensityFactor) {
this.starDensityFactor = starDensityFactor;
}
public Builder starDensityFactor(double starDensityFactor) {
this.starDensityFactor = starDensityFactor;
return this;
}
public EvenFrequencyBandsStarBuffer.Builder evenlyBanded(int numBands) {
return new EvenFrequencyBandsStarBuffer.Builder(numBands, this);
}
public ManuallyBucketizedFrequencyBandsStarBuffer.Builder manuallyBanded(double[] bandSizes, double[] bandWeights) {
return new ManuallyBucketizedFrequencyBandsStarBuffer.Builder(starDensityFactor, bandSizes, bandWeights, this);
}
public ManuallyBucketizedFrequencyBandsStarBuffer.Builder fairlyBanded() {
return manuallyBanded(fairSizes, fairWeights);
}
public abstract StarBuffer create(Spectrogram spec);
}
protected final Spectrogram spec;
public StarBuffer(Spectrogram spec) {
this.spec = spec;
}
/**
* Offer a {@link Star} to this buffer. It may or may not accept it, and this
* {@link Star} may or may not be returned by {@link #flush()} depending on
* how the internal logic works.
*
* @param s
*/
|
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
// Path: src/java/org/sidoh/song_recognition/signature/StarBuffer.java
import java.util.Iterator;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
package org.sidoh.song_recognition.signature;
/**
* This is used in conjunction with {@link ConstellationMapExtractor} to extract
* {@link Star}s (Spectrogram peaks). It is fed potential peaks and the coordinates
* that they reside at, and it keeps track of which ones it likes to keep (in
* memory).
*
* It should support an operation called flush(), which should return an
* {@link Iterator} of {@link Star}s that it'd like to keep.
*
* {@link StarBuffer}s are required to be thread safe.
*
* @author chris
*/
public abstract class StarBuffer {
public static abstract class Builder {
protected static final double[] fairSizes = {0.05d, 0.15, 0.40d};
protected static final double[] fairWeights = {0.1d, 0.7d, 0.2d};
protected double starDensityFactor;
public Builder(double starDensityFactor) {
this.starDensityFactor = starDensityFactor;
}
public Builder starDensityFactor(double starDensityFactor) {
this.starDensityFactor = starDensityFactor;
return this;
}
public EvenFrequencyBandsStarBuffer.Builder evenlyBanded(int numBands) {
return new EvenFrequencyBandsStarBuffer.Builder(numBands, this);
}
public ManuallyBucketizedFrequencyBandsStarBuffer.Builder manuallyBanded(double[] bandSizes, double[] bandWeights) {
return new ManuallyBucketizedFrequencyBandsStarBuffer.Builder(starDensityFactor, bandSizes, bandWeights, this);
}
public ManuallyBucketizedFrequencyBandsStarBuffer.Builder fairlyBanded() {
return manuallyBanded(fairSizes, fairWeights);
}
public abstract StarBuffer create(Spectrogram spec);
}
protected final Spectrogram spec;
public StarBuffer(Spectrogram spec) {
this.spec = spec;
}
/**
* Offer a {@link Star} to this buffer. It may or may not accept it, and this
* {@link Star} may or may not be returned by {@link #flush()} depending on
* how the internal logic works.
*
* @param s
*/
|
public abstract void offerStar(Star s);
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/database/WavDatabaseBuilder.java
|
// Path: src/java/org/sidoh/song_recognition/audio_io/FrameBuffer.java
// public abstract class FrameBuffer implements Iterable<double[]> {
// public static class Builder {
// private int frameSize;
// private double overlap;
//
// private Builder(int frameSize) {
// this.frameSize = frameSize;
// overlap = 0d;
// }
//
// public Builder sampleOverlap(double rate) {
// overlap = rate;
// return this;
// }
//
// public Builder frameSize(int size) {
// this.frameSize = size;
// return this;
// }
//
// public FrameBuffer fromWavFile(String filename) throws IOException, WavFileException {
// return fromWavFile(WavFile.openWavFile(new File(filename)));
// }
//
// public FrameBuffer fromWavFile(WavFile wav) {
// FrameBuffer buffer = new WavFrameBuffer(wav, frameSize);
//
// if (overlap != 0d) {
// buffer = new OverlappingFrameBuffer(buffer, overlap);
// }
//
// return buffer;
// }
// }
//
// /**
// * Returns the size of the next frame
// *
// * @return
// */
// public abstract int getFrameSize();
//
// /**
// * Returns the number of frames in this buffer.
// *
// * @return
// */
// public abstract int getNumFrames();
//
// /**
// * Returns sample rate
// *
// * @return
// */
// public abstract double getSampleRate();
//
// /**
// * Returns # of frames in a second.
// *
// * @return
// */
// public abstract double getFramesPerSecond();
//
//
// /**
// * Create new builder with specified frame size
// *
// * @param size
// * @return
// */
// public static Builder frameSize(int size) {
// return new Builder(size);
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/SpectrogramSignatureExtractor.java
// public interface SpectrogramSignatureExtractor<T extends Signature> extends SignatureExtractor<T> {
// /**
// *
// * @param song
// * @param spec
// * @return
// */
// public T extractSignature(Spectrogram spec);
// }
|
import java.io.File;
import java.io.IOException;
import org.sidoh.song_recognition.audio_io.FrameBuffer;
import org.sidoh.song_recognition.audio_io.WavFile;
import org.sidoh.song_recognition.audio_io.WavFileException;
import org.sidoh.song_recognition.signature.Signature;
import org.sidoh.song_recognition.signature.SpectrogramSignatureExtractor;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
|
package org.sidoh.song_recognition.database;
public class WavDatabaseBuilder<S extends Signature, E extends SignatureDatabase<S>> {
private final SpectrogramSignatureExtractor<S> extractor;
private final E db;
|
// Path: src/java/org/sidoh/song_recognition/audio_io/FrameBuffer.java
// public abstract class FrameBuffer implements Iterable<double[]> {
// public static class Builder {
// private int frameSize;
// private double overlap;
//
// private Builder(int frameSize) {
// this.frameSize = frameSize;
// overlap = 0d;
// }
//
// public Builder sampleOverlap(double rate) {
// overlap = rate;
// return this;
// }
//
// public Builder frameSize(int size) {
// this.frameSize = size;
// return this;
// }
//
// public FrameBuffer fromWavFile(String filename) throws IOException, WavFileException {
// return fromWavFile(WavFile.openWavFile(new File(filename)));
// }
//
// public FrameBuffer fromWavFile(WavFile wav) {
// FrameBuffer buffer = new WavFrameBuffer(wav, frameSize);
//
// if (overlap != 0d) {
// buffer = new OverlappingFrameBuffer(buffer, overlap);
// }
//
// return buffer;
// }
// }
//
// /**
// * Returns the size of the next frame
// *
// * @return
// */
// public abstract int getFrameSize();
//
// /**
// * Returns the number of frames in this buffer.
// *
// * @return
// */
// public abstract int getNumFrames();
//
// /**
// * Returns sample rate
// *
// * @return
// */
// public abstract double getSampleRate();
//
// /**
// * Returns # of frames in a second.
// *
// * @return
// */
// public abstract double getFramesPerSecond();
//
//
// /**
// * Create new builder with specified frame size
// *
// * @param size
// * @return
// */
// public static Builder frameSize(int size) {
// return new Builder(size);
// }
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/SpectrogramSignatureExtractor.java
// public interface SpectrogramSignatureExtractor<T extends Signature> extends SignatureExtractor<T> {
// /**
// *
// * @param song
// * @param spec
// * @return
// */
// public T extractSignature(Spectrogram spec);
// }
// Path: src/java/org/sidoh/song_recognition/database/WavDatabaseBuilder.java
import java.io.File;
import java.io.IOException;
import org.sidoh.song_recognition.audio_io.FrameBuffer;
import org.sidoh.song_recognition.audio_io.WavFile;
import org.sidoh.song_recognition.audio_io.WavFileException;
import org.sidoh.song_recognition.signature.Signature;
import org.sidoh.song_recognition.signature.SpectrogramSignatureExtractor;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
package org.sidoh.song_recognition.database;
public class WavDatabaseBuilder<S extends Signature, E extends SignatureDatabase<S>> {
private final SpectrogramSignatureExtractor<S> extractor;
private final E db;
|
private final FrameBuffer.Builder bufferBuilder;
|
cmullins/song_recognition
|
src/java/org/sidoh/collections/BufferedCountingMap.java
|
// Path: src/java/org/sidoh/math/Stats.java
// public class Stats {
// /**
// *
// * @param a
// * @return
// */
// public static double mean(Iterable<Double> a) {
// double sum = 0d;
// int count = 0;
// for (double value : a) {
// sum += value;
// count++;
// }
// return sum/count;
// }
//
// /**
// *
// * @param a
// * @return
// */
// public static double variance(Iterable<Double> a) {
// double sum = 0d;
// double sq = 0d;
// int n = 0;
//
// for (double value : a) {
// sum += value;
// sq += value*value;
// n++;
// }
//
// return
// (n*sq - sum*sum)
// /
// (n * (n-1));
// }
//
// /**
// *
// * @param n
// * @param sum
// * @param sqSum
// * @return
// */
// public static double variance(int n, double sum, double sqSum) {
// return (n*sqSum - sum*sum) / (n * (n-1));
// }
//
// /**
// *
// * @param n
// * @param sum
// * @param sqSum
// * @return
// */
// public static double sd(int n, double sum, double sqSum) {
// return Math.sqrt(variance(n,sum,sqSum));
// }
//
// /**
// *
// * @param a
// * @return
// */
// public static double sd(Iterable<Double> a) {
// return Math.sqrt(variance(a));
// }
// }
|
import java.util.Iterator;
import org.sidoh.math.Stats;
|
* @return
*/
public int getMaxCount() {
return maxCount;
}
/**
* Returns the count of the bin with the fewest counts
*
* @return
*/
public int getMinCount() {
return minCount;
}
/**
* Returns the mean of the counts
*
* @return
*/
public double getMeanCount() {
return countsSum / getNumBins();
}
/**
* Returns the standard deviation of the counts
*
* @return
*/
public double getCountSd() {
|
// Path: src/java/org/sidoh/math/Stats.java
// public class Stats {
// /**
// *
// * @param a
// * @return
// */
// public static double mean(Iterable<Double> a) {
// double sum = 0d;
// int count = 0;
// for (double value : a) {
// sum += value;
// count++;
// }
// return sum/count;
// }
//
// /**
// *
// * @param a
// * @return
// */
// public static double variance(Iterable<Double> a) {
// double sum = 0d;
// double sq = 0d;
// int n = 0;
//
// for (double value : a) {
// sum += value;
// sq += value*value;
// n++;
// }
//
// return
// (n*sq - sum*sum)
// /
// (n * (n-1));
// }
//
// /**
// *
// * @param n
// * @param sum
// * @param sqSum
// * @return
// */
// public static double variance(int n, double sum, double sqSum) {
// return (n*sqSum - sum*sum) / (n * (n-1));
// }
//
// /**
// *
// * @param n
// * @param sum
// * @param sqSum
// * @return
// */
// public static double sd(int n, double sum, double sqSum) {
// return Math.sqrt(variance(n,sum,sqSum));
// }
//
// /**
// *
// * @param a
// * @return
// */
// public static double sd(Iterable<Double> a) {
// return Math.sqrt(variance(a));
// }
// }
// Path: src/java/org/sidoh/collections/BufferedCountingMap.java
import java.util.Iterator;
import org.sidoh.math.Stats;
* @return
*/
public int getMaxCount() {
return maxCount;
}
/**
* Returns the count of the bin with the fewest counts
*
* @return
*/
public int getMinCount() {
return minCount;
}
/**
* Returns the mean of the counts
*
* @return
*/
public double getMeanCount() {
return countsSum / getNumBins();
}
/**
* Returns the standard deviation of the counts
*
* @return
*/
public double getCountSd() {
|
return Stats.sd(getNumBins(), countsSum, sqCountsSum);
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/EvenlySpreadInFrequencyStarBuffer.java
|
// Path: src/java/org/sidoh/collections/HashOfPriorityQueues.java
// public class HashOfPriorityQueues<K, V> extends DefaultingHashMap<K, Collection<V>> {
// private static final long serialVersionUID = -9081613625997115241L;
//
// private final Builder<V> pqBuilder;
// private final boolean sync;
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> builder) {
// this(builder, false);
// }
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> pqBuilder, boolean sync) {
// this.pqBuilder = pqBuilder;
// this.sync = sync;
// }
//
// @Override
// protected Collection<V> getDefaultValue() {
// Collection<V> val = pqBuilder.create();
// if (sync) {
// val = Collections.synchronizedCollection(val);
// }
// return val;
// }
//
// public void addFor(K key, V value) {
// get(key).add(value);
// }
//
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
|
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import org.sidoh.collections.HashOfPriorityQueues;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
|
package org.sidoh.song_recognition.signature;
public class EvenlySpreadInFrequencyStarBuffer extends StarBuffer {
protected static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
public EvenlySpreadInFrequencyStarBuffer create(Spectrogram spec) {
return new EvenlySpreadInFrequencyStarBuffer(spec, starDensityFactor);
}
}
|
// Path: src/java/org/sidoh/collections/HashOfPriorityQueues.java
// public class HashOfPriorityQueues<K, V> extends DefaultingHashMap<K, Collection<V>> {
// private static final long serialVersionUID = -9081613625997115241L;
//
// private final Builder<V> pqBuilder;
// private final boolean sync;
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> builder) {
// this(builder, false);
// }
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> pqBuilder, boolean sync) {
// this.pqBuilder = pqBuilder;
// this.sync = sync;
// }
//
// @Override
// protected Collection<V> getDefaultValue() {
// Collection<V> val = pqBuilder.create();
// if (sync) {
// val = Collections.synchronizedCollection(val);
// }
// return val;
// }
//
// public void addFor(K key, V value) {
// get(key).add(value);
// }
//
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
// Path: src/java/org/sidoh/song_recognition/signature/EvenlySpreadInFrequencyStarBuffer.java
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import org.sidoh.collections.HashOfPriorityQueues;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
package org.sidoh.song_recognition.signature;
public class EvenlySpreadInFrequencyStarBuffer extends StarBuffer {
protected static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
public EvenlySpreadInFrequencyStarBuffer create(Spectrogram spec) {
return new EvenlySpreadInFrequencyStarBuffer(spec, starDensityFactor);
}
}
|
protected Map<Integer, Collection<Star>> stars;
|
cmullins/song_recognition
|
src/java/org/sidoh/song_recognition/signature/EvenlySpreadInFrequencyStarBuffer.java
|
// Path: src/java/org/sidoh/collections/HashOfPriorityQueues.java
// public class HashOfPriorityQueues<K, V> extends DefaultingHashMap<K, Collection<V>> {
// private static final long serialVersionUID = -9081613625997115241L;
//
// private final Builder<V> pqBuilder;
// private final boolean sync;
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> builder) {
// this(builder, false);
// }
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> pqBuilder, boolean sync) {
// this.pqBuilder = pqBuilder;
// this.sync = sync;
// }
//
// @Override
// protected Collection<V> getDefaultValue() {
// Collection<V> val = pqBuilder.create();
// if (sync) {
// val = Collections.synchronizedCollection(val);
// }
// return val;
// }
//
// public void addFor(K key, V value) {
// get(key).add(value);
// }
//
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
|
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import org.sidoh.collections.HashOfPriorityQueues;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
|
package org.sidoh.song_recognition.signature;
public class EvenlySpreadInFrequencyStarBuffer extends StarBuffer {
protected static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
public EvenlySpreadInFrequencyStarBuffer create(Spectrogram spec) {
return new EvenlySpreadInFrequencyStarBuffer(spec, starDensityFactor);
}
}
protected Map<Integer, Collection<Star>> stars;
public EvenlySpreadInFrequencyStarBuffer(Spectrogram spec, double starDensityFactor) {
super(spec);
int perFreqSize = Math.max(1,(int)Math.floor((starDensityFactor*spec.getMaxTick()) / spec.getBinFloors().length));
|
// Path: src/java/org/sidoh/collections/HashOfPriorityQueues.java
// public class HashOfPriorityQueues<K, V> extends DefaultingHashMap<K, Collection<V>> {
// private static final long serialVersionUID = -9081613625997115241L;
//
// private final Builder<V> pqBuilder;
// private final boolean sync;
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> builder) {
// this(builder, false);
// }
//
// public HashOfPriorityQueues(MinMaxPriorityQueue.Builder<V> pqBuilder, boolean sync) {
// this.pqBuilder = pqBuilder;
// this.sync = sync;
// }
//
// @Override
// protected Collection<V> getDefaultValue() {
// Collection<V> val = pqBuilder.create();
// if (sync) {
// val = Collections.synchronizedCollection(val);
// }
// return val;
// }
//
// public void addFor(K key, V value) {
// get(key).add(value);
// }
//
// }
//
// Path: src/java/org/sidoh/song_recognition/signature/ConstellationMap.java
// public static class Star implements Serializable {
// private static final long serialVersionUID = 1851275921474044916L;
//
//
// private final double time;
// private final double frequency;
// private final double intensity;
// private final int x;
// private final int y;
//
// public Star(final double time, final double frequency, final double intensity, final int x, final int y) {
// this.time = time;
// this.frequency = frequency;
// this.intensity = intensity;
// this.x = x;
// this.y = y;
// }
//
// public double getTime() {
// return time;
// }
//
// public double getFrequency() {
// return frequency;
// }
//
// public double getIntensity() {
// return intensity;
// }
//
// public int getTick() {
// return x;
// }
//
// public int getBin() {
// return y;
// }
//
// @Override
// public int hashCode() {
// final int prime = 31;
// int result = 1;
// result = prime * result + x;
// result = prime * result + y;
// return result;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj)
// return true;
// if (obj == null)
// return false;
// if (getClass() != obj.getClass())
// return false;
// Star other = (Star) obj;
// if (x != other.x)
// return false;
// if (y != other.y)
// return false;
// return true;
// }
//
// @Override
// public String toString() {
// return "Star [x=" + x + ", y=" + y + ", intensity=" + intensity + "]";
// }
// }
// Path: src/java/org/sidoh/song_recognition/signature/EvenlySpreadInFrequencyStarBuffer.java
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import org.sidoh.collections.HashOfPriorityQueues;
import org.sidoh.song_recognition.signature.ConstellationMap.Star;
import org.sidoh.song_recognition.spectrogram.Spectrogram;
import com.google.common.collect.MinMaxPriorityQueue;
package org.sidoh.song_recognition.signature;
public class EvenlySpreadInFrequencyStarBuffer extends StarBuffer {
protected static class Builder extends StarBuffer.Builder {
public Builder(double starDensityFactor) {
super(starDensityFactor);
}
public EvenlySpreadInFrequencyStarBuffer create(Spectrogram spec) {
return new EvenlySpreadInFrequencyStarBuffer(spec, starDensityFactor);
}
}
protected Map<Integer, Collection<Star>> stars;
public EvenlySpreadInFrequencyStarBuffer(Spectrogram spec, double starDensityFactor) {
super(spec);
int perFreqSize = Math.max(1,(int)Math.floor((starDensityFactor*spec.getMaxTick()) / spec.getBinFloors().length));
|
stars = Collections.synchronizedMap(new HashOfPriorityQueues<Integer, Star>(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.