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
|
---|---|---|---|---|---|---|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/view/CellMovie.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/Theater/Horaires.java
// public class Horaires {
// boolean avantPremier = false;
// String date;
// String formatEcran;
// String display; //affichage complet
// List<String> seances = new ArrayList<String>();
// String version;
//
// public boolean isAvantPremier() {
// return avantPremier;
// }
//
// public void setAvantPremier(boolean avantPremier) {
// this.avantPremier = avantPremier;
// }
//
// public String getDate() {
// try {
// String[] d = date.split("-");
// return d[2] + "/" + d[1] + "/" + d[0];
// } catch (Exception e) {
// return date;
// }
// }
//
// public void setDate(String date) {
// this.date = date;
// }
//
// public String getFormatEcran() {
// return formatEcran;
// }
//
// public void setFormatEcran(String formatEcran) {
// this.formatEcran = formatEcran;
// }
//
// public String getDisplay() {
// return display;
// }
//
// public void setDisplay(String display) {
// this.display = display;
// }
//
// public List<String> getSeances() {
// return seances;
// }
//
// public void setSeances(List<String> seances) {
// this.seances = seances;
// }
//
// public String getVersion() {
// return version;
// }
//
// public void setVersion(String version) {
// this.version = version;
// }
//
// public boolean isToday() {
// String dateFormatted = getDate();
//
// Date now = new Date();
// SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
// String nowFormatted = formater.format(now);
//
// Log.d("DATE", dateFormatted + " " + nowFormatted);
//
// return dateFormatted.equals(nowFormatted);
// }
//
// public boolean isMoreThanToday() {
// try {
// String dateFormatted = getDate();
//
// Date now = new Date();
// now.setHours(0);
// now.setSeconds(0);
// now.setMinutes(0);
//
// SimpleDateFormat formater = new SimpleDateFormat("E dd MMMMM yyyy", Locale.FRANCE);
// Date date = formater.parse(dateFormatted);
//
// date.setHours(13);
//
// return date.equals(now) || date.after(now);
// } catch (Exception e) {
// e.printStackTrace();
// return false;
// }
// }
//
// @Override
// public String toString() {
// return "Horraires{" +
// ", date='" + date + '\'' +
// ", seances=" + seances +
// '}';
// }
// }
|
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.bdc.ociney.R;
import com.bdc.ociney.modele.Movie.Movie;
import com.bdc.ociney.modele.Theater.Horaires;
import com.squareup.picasso.Picasso;
import java.util.Calendar;
import java.util.GregorianCalendar;
|
if (rating == 0) {
ratingLabel.setVisibility(View.GONE);
ratingBar.setVisibility(View.GONE);
if (getObject().getRelease() != null) {
try {
String date = getObject().getRelease().getReleaseDate();
int annee = Integer.parseInt(date.split("/")[2]);
int anneeEncours = GregorianCalendar.getInstance().get(Calendar.YEAR);
if (annee >= anneeEncours) {
enSalle.setVisibility(View.VISIBLE);
enSalleDate.setText(getObject().getRelease().getReleaseDate());
}
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
enSalle.setVisibility(View.GONE);
ratingLabel.setVisibility(View.VISIBLE);
ratingBar.setVisibility(View.VISIBLE);
ratingLabel.setText("(" + String.format("%.1f", rating) + ")");
ratingBar.setRating(rating);
ratingBar.setIsIndicator(true);
}
}
private void chargerHorraires() {
if (getObject().getHoraires() != null && getObject().getHoraires().size() > 0) {
|
// Path: app/src/main/java/com/bdc/ociney/modele/Theater/Horaires.java
// public class Horaires {
// boolean avantPremier = false;
// String date;
// String formatEcran;
// String display; //affichage complet
// List<String> seances = new ArrayList<String>();
// String version;
//
// public boolean isAvantPremier() {
// return avantPremier;
// }
//
// public void setAvantPremier(boolean avantPremier) {
// this.avantPremier = avantPremier;
// }
//
// public String getDate() {
// try {
// String[] d = date.split("-");
// return d[2] + "/" + d[1] + "/" + d[0];
// } catch (Exception e) {
// return date;
// }
// }
//
// public void setDate(String date) {
// this.date = date;
// }
//
// public String getFormatEcran() {
// return formatEcran;
// }
//
// public void setFormatEcran(String formatEcran) {
// this.formatEcran = formatEcran;
// }
//
// public String getDisplay() {
// return display;
// }
//
// public void setDisplay(String display) {
// this.display = display;
// }
//
// public List<String> getSeances() {
// return seances;
// }
//
// public void setSeances(List<String> seances) {
// this.seances = seances;
// }
//
// public String getVersion() {
// return version;
// }
//
// public void setVersion(String version) {
// this.version = version;
// }
//
// public boolean isToday() {
// String dateFormatted = getDate();
//
// Date now = new Date();
// SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
// String nowFormatted = formater.format(now);
//
// Log.d("DATE", dateFormatted + " " + nowFormatted);
//
// return dateFormatted.equals(nowFormatted);
// }
//
// public boolean isMoreThanToday() {
// try {
// String dateFormatted = getDate();
//
// Date now = new Date();
// now.setHours(0);
// now.setSeconds(0);
// now.setMinutes(0);
//
// SimpleDateFormat formater = new SimpleDateFormat("E dd MMMMM yyyy", Locale.FRANCE);
// Date date = formater.parse(dateFormatted);
//
// date.setHours(13);
//
// return date.equals(now) || date.after(now);
// } catch (Exception e) {
// e.printStackTrace();
// return false;
// }
// }
//
// @Override
// public String toString() {
// return "Horraires{" +
// ", date='" + date + '\'' +
// ", seances=" + seances +
// '}';
// }
// }
// Path: app/src/main/java/com/bdc/ociney/view/CellMovie.java
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
import com.bdc.ociney.R;
import com.bdc.ociney.modele.Movie.Movie;
import com.bdc.ociney.modele.Theater.Horaires;
import com.squareup.picasso.Picasso;
import java.util.Calendar;
import java.util.GregorianCalendar;
if (rating == 0) {
ratingLabel.setVisibility(View.GONE);
ratingBar.setVisibility(View.GONE);
if (getObject().getRelease() != null) {
try {
String date = getObject().getRelease().getReleaseDate();
int annee = Integer.parseInt(date.split("/")[2]);
int anneeEncours = GregorianCalendar.getInstance().get(Calendar.YEAR);
if (annee >= anneeEncours) {
enSalle.setVisibility(View.VISIBLE);
enSalleDate.setText(getObject().getRelease().getReleaseDate());
}
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
enSalle.setVisibility(View.GONE);
ratingLabel.setVisibility(View.VISIBLE);
ratingBar.setVisibility(View.VISIBLE);
ratingLabel.setText("(" + String.format("%.1f", rating) + ")");
ratingBar.setRating(rating);
ratingBar.setIsIndicator(true);
}
}
private void chargerHorraires() {
if (getObject().getHoraires() != null && getObject().getHoraires().size() > 0) {
|
for (Horaires h : getObject().getHoraires()) {
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/activity/MovieCastingActivity.java
|
// Path: app/src/main/java/com/bdc/ociney/core/BaseActivity.java
// public class BaseActivity extends AppCompatActivity implements LifecycleRegistryOwner {
//
// private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);
// private AdsManager adsManager;
//
// public LifecycleRegistry getLifecycle() {
// return this.mRegistry;
// }
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// adsManager = new AdsManager(this, getLifecycle());
// //if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
// // getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
// //}
// }
//
// public AdsManager getAdsManager() {
// return adsManager;
// }
//
// public MainApplication getApp() {
// return ((MainApplication) getApplication());
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/fragment/ListCastingFragment.java
// public class ListCastingFragment extends BaseFragment {
//
// public static List<CastMember> casting;
// static Movie movie;
//
// ObjectAdapter<CastMember> adapter;
// AbsListView list;
//
// MovingImageView imageFond;
//
// public static ListCastingFragment newInstance() {
//
// Bundle args = new Bundle();
//
// ListCastingFragment fragment = new ListCastingFragment();
// fragment.setArguments(args);
// return fragment;
// }
//
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
//
// View view = inflater.inflate(R.layout.fragment_list_casting,
// container, false);
//
// setFragmentView(view);
//
// charger();
// remplir();
// ajouterListeners();
//
//
// return view;
// }
//
// @Override
// public void onResume() {
// super.onResume();
// }
//
// @Override
// public void onPause() {
// super.onPause();
// }
//
// @Override
// protected void charger() {
// list = (AbsListView) View.inflate(getActivity(), R.layout.list, null);
// ((ViewGroup) fragmentView).addView(list);
//
// this.imageFond = (MovingImageView) findViewById(R.id.imageFond);
// }
//
// @Override
// protected void remplir() {
// adapter = new ObjectAdapter<CastMember>(getActivity(), casting, R.layout.casting_member, CellMember.class);
// list.setAdapter(adapter);
// adapter.notifyDataSetChanged();
//
// if (movie != null)
// imageFond.activerBlur(getActivity().getResources().getInteger(R.integer.fragment_movie_fond_blur))
// .activerAnimations().loadFromUrl(getActivity(), movie.getUrlPoster(getActivity().getResources().getInteger(R.integer.fragment_movie_fond_blur_height)));
//
// }
//
// @Override
// protected void ajouterListeners() {
// }
//
// @Override
// public void onClick(View view) {
//
// }
// }
|
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import com.bdc.ociney.R;
import com.bdc.ociney.core.BaseActivity;
import com.bdc.ociney.fragment.ListCastingFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
|
package com.bdc.ociney.activity;
/**
* Created by florentchampigny on 21/04/2014.
*/
public class MovieCastingActivity extends BaseActivity {
@BindView(R.id.toolbar)
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_movie_casting);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(Color.WHITE);
getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ab_back_mtrl_am_alpha));
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction()
|
// Path: app/src/main/java/com/bdc/ociney/core/BaseActivity.java
// public class BaseActivity extends AppCompatActivity implements LifecycleRegistryOwner {
//
// private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);
// private AdsManager adsManager;
//
// public LifecycleRegistry getLifecycle() {
// return this.mRegistry;
// }
//
// @Override
// protected void onCreate(@Nullable Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// adsManager = new AdsManager(this, getLifecycle());
// //if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
// // getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
// //}
// }
//
// public AdsManager getAdsManager() {
// return adsManager;
// }
//
// public MainApplication getApp() {
// return ((MainApplication) getApplication());
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/fragment/ListCastingFragment.java
// public class ListCastingFragment extends BaseFragment {
//
// public static List<CastMember> casting;
// static Movie movie;
//
// ObjectAdapter<CastMember> adapter;
// AbsListView list;
//
// MovingImageView imageFond;
//
// public static ListCastingFragment newInstance() {
//
// Bundle args = new Bundle();
//
// ListCastingFragment fragment = new ListCastingFragment();
// fragment.setArguments(args);
// return fragment;
// }
//
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
//
// View view = inflater.inflate(R.layout.fragment_list_casting,
// container, false);
//
// setFragmentView(view);
//
// charger();
// remplir();
// ajouterListeners();
//
//
// return view;
// }
//
// @Override
// public void onResume() {
// super.onResume();
// }
//
// @Override
// public void onPause() {
// super.onPause();
// }
//
// @Override
// protected void charger() {
// list = (AbsListView) View.inflate(getActivity(), R.layout.list, null);
// ((ViewGroup) fragmentView).addView(list);
//
// this.imageFond = (MovingImageView) findViewById(R.id.imageFond);
// }
//
// @Override
// protected void remplir() {
// adapter = new ObjectAdapter<CastMember>(getActivity(), casting, R.layout.casting_member, CellMember.class);
// list.setAdapter(adapter);
// adapter.notifyDataSetChanged();
//
// if (movie != null)
// imageFond.activerBlur(getActivity().getResources().getInteger(R.integer.fragment_movie_fond_blur))
// .activerAnimations().loadFromUrl(getActivity(), movie.getUrlPoster(getActivity().getResources().getInteger(R.integer.fragment_movie_fond_blur_height)));
//
// }
//
// @Override
// protected void ajouterListeners() {
// }
//
// @Override
// public void onClick(View view) {
//
// }
// }
// Path: app/src/main/java/com/bdc/ociney/activity/MovieCastingActivity.java
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import com.bdc.ociney.R;
import com.bdc.ociney.core.BaseActivity;
import com.bdc.ociney.fragment.ListCastingFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
package com.bdc.ociney.activity;
/**
* Created by florentchampigny on 21/04/2014.
*/
public class MovieCastingActivity extends BaseActivity {
@BindView(R.id.toolbar)
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.activity_movie_casting);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(Color.WHITE);
getSupportActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.ab_back_mtrl_am_alpha));
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportFragmentManager().beginTransaction()
|
.replace(R.id.fragmentLayout, ListCastingFragment.newInstance())
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/modele/Theater/MovieShowtime.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
|
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
import com.bdc.ociney.modele.Version;
import java.util.ArrayList;
import java.util.List;
|
package com.bdc.ociney.modele.Theater;
public class MovieShowtime {
@Expose
private String preview;
@Expose
private String releaseWeek;
@Expose
private OnShow onShow;
@Expose
private Version version;
@Expose
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
// Path: app/src/main/java/com/bdc/ociney/modele/Theater/MovieShowtime.java
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
import com.bdc.ociney.modele.Version;
import java.util.ArrayList;
import java.util.List;
package com.bdc.ociney.modele.Theater;
public class MovieShowtime {
@Expose
private String preview;
@Expose
private String releaseWeek;
@Expose
private OnShow onShow;
@Expose
private Version version;
@Expose
|
private ModelObject screenFormat;
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/core/BaseFragment.java
|
// Path: app/src/main/java/com/bdc/ociney/MainApplication.java
// public class MainApplication extends Application{
//
// @Override
// public void onCreate() {
// super.onCreate();
// Fabric.with(this, new Crashlytics());
//
// MobileAds.initialize(this, getString(R.string.admob_app));
//
// Analytics.registerProvider(
// new GoogleAnalyticsProvider(this, R.xml.global_tracker)
// );
// }
// }
|
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import com.bdc.ociney.MainApplication;
|
package com.bdc.ociney.core;
/**
* Created by florentchampigny on 07/08/2017.
*/
public class BaseFragment extends Fragment implements LifecycleRegistryOwner {
private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);
private AdsManager adsManager;
public LifecycleRegistry getLifecycle() {
return this.mRegistry;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adsManager = new AdsManager(getContext(), getLifecycle());
}
public AdsManager getAdsManager() {
return adsManager;
}
|
// Path: app/src/main/java/com/bdc/ociney/MainApplication.java
// public class MainApplication extends Application{
//
// @Override
// public void onCreate() {
// super.onCreate();
// Fabric.with(this, new Crashlytics());
//
// MobileAds.initialize(this, getString(R.string.admob_app));
//
// Analytics.registerProvider(
// new GoogleAnalyticsProvider(this, R.xml.global_tracker)
// );
// }
// }
// Path: app/src/main/java/com/bdc/ociney/core/BaseFragment.java
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import com.bdc.ociney.MainApplication;
package com.bdc.ociney.core;
/**
* Created by florentchampigny on 07/08/2017.
*/
public class BaseFragment extends Fragment implements LifecycleRegistryOwner {
private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);
private AdsManager adsManager;
public LifecycleRegistry getLifecycle() {
return this.mRegistry;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adsManager = new AdsManager(getContext(), getLifecycle());
}
public AdsManager getAdsManager() {
return adsManager;
}
|
public MainApplication getApp() {
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/adapter/ObjectAdapter.java
|
// Path: app/src/main/java/com/bdc/ociney/view/ViewCell.java
// public abstract class ViewCell<OBJECT> {
//
// Context context;
// View view;
// OBJECT object;
// int position;
//
// public ViewCell() {
//
// }
//
// public abstract void animer();
//
// public void construire(Context context, View view) {
// this.context = context;
// this.view = view;
// this.charger();
// }
//
// public void construire(OBJECT object, int position) {
// this.object = object;
// this.position = position;
// this.remplir();
// }
//
// public abstract void construire();
//
// public abstract void charger();
//
// public abstract void remplir();
//
// public abstract void ajouterListeners();
//
// public Context getContext() {
// return context;
// }
//
// public void setContext(Context context) {
// this.context = context;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public OBJECT getObject() {
// return object;
// }
//
// public void setObject(OBJECT object) {
// this.object = object;
// }
//
// public int getPosition() {
// return position;
// }
//
// public void setPosition(int position) {
// this.position = position;
// }
//
// public void onScroll(float yOffset) {
// }
// }
|
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.bdc.ociney.view.ViewCell;
import java.util.ArrayList;
import java.util.List;
|
package com.bdc.ociney.adapter;
/**
* Created by florentchampigny on 20/04/2014.
*/
public class ObjectAdapter<OBJECT> extends ArrayAdapter<OBJECT> {
public ObjectAdapterLoadMore listener;
Context context;
int layoutId;
Class cellClass;
ArrayList<Integer> apparitions = new ArrayList<Integer>();
|
// Path: app/src/main/java/com/bdc/ociney/view/ViewCell.java
// public abstract class ViewCell<OBJECT> {
//
// Context context;
// View view;
// OBJECT object;
// int position;
//
// public ViewCell() {
//
// }
//
// public abstract void animer();
//
// public void construire(Context context, View view) {
// this.context = context;
// this.view = view;
// this.charger();
// }
//
// public void construire(OBJECT object, int position) {
// this.object = object;
// this.position = position;
// this.remplir();
// }
//
// public abstract void construire();
//
// public abstract void charger();
//
// public abstract void remplir();
//
// public abstract void ajouterListeners();
//
// public Context getContext() {
// return context;
// }
//
// public void setContext(Context context) {
// this.context = context;
// }
//
// public View getView() {
// return view;
// }
//
// public void setView(View view) {
// this.view = view;
// }
//
// public OBJECT getObject() {
// return object;
// }
//
// public void setObject(OBJECT object) {
// this.object = object;
// }
//
// public int getPosition() {
// return position;
// }
//
// public void setPosition(int position) {
// this.position = position;
// }
//
// public void onScroll(float yOffset) {
// }
// }
// Path: app/src/main/java/com/bdc/ociney/adapter/ObjectAdapter.java
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.bdc.ociney.view.ViewCell;
import java.util.ArrayList;
import java.util.List;
package com.bdc.ociney.adapter;
/**
* Created by florentchampigny on 20/04/2014.
*/
public class ObjectAdapter<OBJECT> extends ArrayAdapter<OBJECT> {
public ObjectAdapterLoadMore listener;
Context context;
int layoutId;
Class cellClass;
ArrayList<Integer> apparitions = new ArrayList<Integer>();
|
public ObjectAdapter(Context context, List<OBJECT> objets, int layoutId, Class<? extends ViewCell> cellClass) {
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/modele/Movie/MovieCertificate.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
|
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
|
package com.bdc.ociney.modele.Movie;
public class MovieCertificate {
@Expose
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
// Path: app/src/main/java/com/bdc/ociney/modele/Movie/MovieCertificate.java
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
package com.bdc.ociney.modele.Movie;
public class MovieCertificate {
@Expose
|
private ModelObject certificate;
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/core/BaseActivity.java
|
// Path: app/src/main/java/com/bdc/ociney/MainApplication.java
// public class MainApplication extends Application{
//
// @Override
// public void onCreate() {
// super.onCreate();
// Fabric.with(this, new Crashlytics());
//
// MobileAds.initialize(this, getString(R.string.admob_app));
//
// Analytics.registerProvider(
// new GoogleAnalyticsProvider(this, R.xml.global_tracker)
// );
// }
// }
|
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.bdc.ociney.MainApplication;
|
package com.bdc.ociney.core;
/**
* Created by florentchampigny on 07/08/2017.
*/
public class BaseActivity extends AppCompatActivity implements LifecycleRegistryOwner {
private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);
private AdsManager adsManager;
public LifecycleRegistry getLifecycle() {
return this.mRegistry;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adsManager = new AdsManager(this, getLifecycle());
//if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
//}
}
public AdsManager getAdsManager() {
return adsManager;
}
|
// Path: app/src/main/java/com/bdc/ociney/MainApplication.java
// public class MainApplication extends Application{
//
// @Override
// public void onCreate() {
// super.onCreate();
// Fabric.with(this, new Crashlytics());
//
// MobileAds.initialize(this, getString(R.string.admob_app));
//
// Analytics.registerProvider(
// new GoogleAnalyticsProvider(this, R.xml.global_tracker)
// );
// }
// }
// Path: app/src/main/java/com/bdc/ociney/core/BaseActivity.java
import android.arch.lifecycle.LifecycleRegistry;
import android.arch.lifecycle.LifecycleRegistryOwner;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.bdc.ociney.MainApplication;
package com.bdc.ociney.core;
/**
* Created by florentchampigny on 07/08/2017.
*/
public class BaseActivity extends AppCompatActivity implements LifecycleRegistryOwner {
private final LifecycleRegistry mRegistry = new LifecycleRegistry(this);
private AdsManager adsManager;
public LifecycleRegistry getLifecycle() {
return this.mRegistry;
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adsManager = new AdsManager(this, getLifecycle());
//if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
//}
}
public AdsManager getAdsManager() {
return adsManager;
}
|
public MainApplication getApp() {
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/adapter/FilmoPagerAdapter.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/Participation.java
// public class Participation {
//
// @Expose
// private Movie movie;
// @Expose
// private ModelObject activity;
// @Expose
// private Tvseries tvseries;
// @Expose
// private String role;
//
// public Movie getMovie() {
// return movie;
// }
//
// public void setMovie(Movie movie) {
// this.movie = movie;
// }
//
// public ModelObject getActivity() {
// return activity;
// }
//
// public void setActivity(ModelObject activity) {
// this.activity = activity;
// }
//
// public Tvseries getTvseries() {
// return tvseries;
// }
//
// public void setTvseries(Tvseries tvseries) {
// this.tvseries = tvseries;
// }
//
// public String getRole() {
// return role;
// }
//
// public void setRole(String role) {
// this.role = role;
// }
//
// @Override
// public String toString() {
// return "Participation{" +
// "movie=" + movie +
// ", activity=" + activity +
// ", tvseries=" + tvseries +
// ", role='" + role + '\'' +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/view/textview/TypefacedTextView.java
// public class TypefacedTextView extends TextView {
//
// public TypefacedTextView(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// //Typeface.createFromAsset doesn't work in the layout editor. Skipping...
// if (isInEditMode()) {
// return;
// }
//
// TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
// String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);
// styledAttrs.recycle();
//
// setTypeFace(fontName);
// }
//
// public void setTypeFace(String fontName) {
// try {
// Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName);
// setTypeface(typeface);
//
// } catch (Exception e) {
// //Log.e("FONT", "Police " + fontName + " introuvable grosse !");
// }
// }
//
// }
|
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bdc.ociney.R;
import com.bdc.ociney.modele.Participation;
import com.bdc.ociney.view.textview.TypefacedTextView;
import com.squareup.picasso.Picasso;
import java.util.List;
|
package com.bdc.ociney.adapter;
/**
* Created by florentchampigny on 01/05/2014.
*/
public class FilmoPagerAdapter extends BaseAdapter {
Activity activity;
|
// Path: app/src/main/java/com/bdc/ociney/modele/Participation.java
// public class Participation {
//
// @Expose
// private Movie movie;
// @Expose
// private ModelObject activity;
// @Expose
// private Tvseries tvseries;
// @Expose
// private String role;
//
// public Movie getMovie() {
// return movie;
// }
//
// public void setMovie(Movie movie) {
// this.movie = movie;
// }
//
// public ModelObject getActivity() {
// return activity;
// }
//
// public void setActivity(ModelObject activity) {
// this.activity = activity;
// }
//
// public Tvseries getTvseries() {
// return tvseries;
// }
//
// public void setTvseries(Tvseries tvseries) {
// this.tvseries = tvseries;
// }
//
// public String getRole() {
// return role;
// }
//
// public void setRole(String role) {
// this.role = role;
// }
//
// @Override
// public String toString() {
// return "Participation{" +
// "movie=" + movie +
// ", activity=" + activity +
// ", tvseries=" + tvseries +
// ", role='" + role + '\'' +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/view/textview/TypefacedTextView.java
// public class TypefacedTextView extends TextView {
//
// public TypefacedTextView(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// //Typeface.createFromAsset doesn't work in the layout editor. Skipping...
// if (isInEditMode()) {
// return;
// }
//
// TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
// String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);
// styledAttrs.recycle();
//
// setTypeFace(fontName);
// }
//
// public void setTypeFace(String fontName) {
// try {
// Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName);
// setTypeface(typeface);
//
// } catch (Exception e) {
// //Log.e("FONT", "Police " + fontName + " introuvable grosse !");
// }
// }
//
// }
// Path: app/src/main/java/com/bdc/ociney/adapter/FilmoPagerAdapter.java
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bdc.ociney.R;
import com.bdc.ociney.modele.Participation;
import com.bdc.ociney.view.textview.TypefacedTextView;
import com.squareup.picasso.Picasso;
import java.util.List;
package com.bdc.ociney.adapter;
/**
* Created by florentchampigny on 01/05/2014.
*/
public class FilmoPagerAdapter extends BaseAdapter {
Activity activity;
|
List<Participation> participations;
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/adapter/FilmoPagerAdapter.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/Participation.java
// public class Participation {
//
// @Expose
// private Movie movie;
// @Expose
// private ModelObject activity;
// @Expose
// private Tvseries tvseries;
// @Expose
// private String role;
//
// public Movie getMovie() {
// return movie;
// }
//
// public void setMovie(Movie movie) {
// this.movie = movie;
// }
//
// public ModelObject getActivity() {
// return activity;
// }
//
// public void setActivity(ModelObject activity) {
// this.activity = activity;
// }
//
// public Tvseries getTvseries() {
// return tvseries;
// }
//
// public void setTvseries(Tvseries tvseries) {
// this.tvseries = tvseries;
// }
//
// public String getRole() {
// return role;
// }
//
// public void setRole(String role) {
// this.role = role;
// }
//
// @Override
// public String toString() {
// return "Participation{" +
// "movie=" + movie +
// ", activity=" + activity +
// ", tvseries=" + tvseries +
// ", role='" + role + '\'' +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/view/textview/TypefacedTextView.java
// public class TypefacedTextView extends TextView {
//
// public TypefacedTextView(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// //Typeface.createFromAsset doesn't work in the layout editor. Skipping...
// if (isInEditMode()) {
// return;
// }
//
// TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
// String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);
// styledAttrs.recycle();
//
// setTypeFace(fontName);
// }
//
// public void setTypeFace(String fontName) {
// try {
// Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName);
// setTypeface(typeface);
//
// } catch (Exception e) {
// //Log.e("FONT", "Police " + fontName + " introuvable grosse !");
// }
// }
//
// }
|
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bdc.ociney.R;
import com.bdc.ociney.modele.Participation;
import com.bdc.ociney.view.textview.TypefacedTextView;
import com.squareup.picasso.Picasso;
import java.util.List;
|
package com.bdc.ociney.adapter;
/**
* Created by florentchampigny on 01/05/2014.
*/
public class FilmoPagerAdapter extends BaseAdapter {
Activity activity;
List<Participation> participations;
SensorManager sensorManager;
Sensor sensor;
int position;
public FilmoPagerAdapter(Activity activity, List<Participation> participations) {
this.activity = activity;
this.participations = participations;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View viewParent, ViewGroup viewGroup) {
View view;
view = View.inflate(activity, R.layout.jaquette, null);
Participation participation = participations.get(i);
view.setVisibility(View.VISIBLE);
if (participation.getMovie() != null && participation.getMovie().getPoster() != null) {
String urlImage = participation.getMovie().getUrlPoster(activity.getResources().getInteger(R.integer.cell_movie_poster_height));
Picasso.with(activity).load(urlImage).into((ImageView) view.findViewById(R.id.jaquette));
}
if (participation.getMovie() != null && participation.getMovie().getTitle() != null) {
|
// Path: app/src/main/java/com/bdc/ociney/modele/Participation.java
// public class Participation {
//
// @Expose
// private Movie movie;
// @Expose
// private ModelObject activity;
// @Expose
// private Tvseries tvseries;
// @Expose
// private String role;
//
// public Movie getMovie() {
// return movie;
// }
//
// public void setMovie(Movie movie) {
// this.movie = movie;
// }
//
// public ModelObject getActivity() {
// return activity;
// }
//
// public void setActivity(ModelObject activity) {
// this.activity = activity;
// }
//
// public Tvseries getTvseries() {
// return tvseries;
// }
//
// public void setTvseries(Tvseries tvseries) {
// this.tvseries = tvseries;
// }
//
// public String getRole() {
// return role;
// }
//
// public void setRole(String role) {
// this.role = role;
// }
//
// @Override
// public String toString() {
// return "Participation{" +
// "movie=" + movie +
// ", activity=" + activity +
// ", tvseries=" + tvseries +
// ", role='" + role + '\'' +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/view/textview/TypefacedTextView.java
// public class TypefacedTextView extends TextView {
//
// public TypefacedTextView(Context context, AttributeSet attrs) {
// super(context, attrs);
//
// //Typeface.createFromAsset doesn't work in the layout editor. Skipping...
// if (isInEditMode()) {
// return;
// }
//
// TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.TypefacedTextView);
// String fontName = styledAttrs.getString(R.styleable.TypefacedTextView_typeface);
// styledAttrs.recycle();
//
// setTypeFace(fontName);
// }
//
// public void setTypeFace(String fontName) {
// try {
// Typeface typeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName);
// setTypeface(typeface);
//
// } catch (Exception e) {
// //Log.e("FONT", "Police " + fontName + " introuvable grosse !");
// }
// }
//
// }
// Path: app/src/main/java/com/bdc/ociney/adapter/FilmoPagerAdapter.java
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.bdc.ociney.R;
import com.bdc.ociney.modele.Participation;
import com.bdc.ociney.view.textview.TypefacedTextView;
import com.squareup.picasso.Picasso;
import java.util.List;
package com.bdc.ociney.adapter;
/**
* Created by florentchampigny on 01/05/2014.
*/
public class FilmoPagerAdapter extends BaseAdapter {
Activity activity;
List<Participation> participations;
SensorManager sensorManager;
Sensor sensor;
int position;
public FilmoPagerAdapter(Activity activity, List<Participation> participations) {
this.activity = activity;
this.participations = participations;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View viewParent, ViewGroup viewGroup) {
View view;
view = View.inflate(activity, R.layout.jaquette, null);
Participation participation = participations.get(i);
view.setVisibility(View.VISIBLE);
if (participation.getMovie() != null && participation.getMovie().getPoster() != null) {
String urlImage = participation.getMovie().getUrlPoster(activity.getResources().getInteger(R.integer.cell_movie_poster_height));
Picasso.with(activity).load(urlImage).into((ImageView) view.findViewById(R.id.jaquette));
}
if (participation.getMovie() != null && participation.getMovie().getTitle() != null) {
|
((TypefacedTextView) view.findViewById(R.id.titreFilmo)).setText(participation.getMovie().getTitle());
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/modele/Release.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/Movie/Distributor.java
// public class Distributor {
//
// @Expose
// private Integer code;
// @Expose
// private String name;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public String toString() {
// return "Distributor{" +
// "code=" + code +
// ", name='" + name + '\'' +
// '}';
// }
// }
|
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.Movie.Distributor;
|
package com.bdc.ociney.modele;
public class Release {
@Expose
private String releaseDate;
@Expose
private ModelObject country;
@Expose
private ModelObject releaseState;
@Expose
private ModelObject releaseVersion;
@Expose
|
// Path: app/src/main/java/com/bdc/ociney/modele/Movie/Distributor.java
// public class Distributor {
//
// @Expose
// private Integer code;
// @Expose
// private String name;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Override
// public String toString() {
// return "Distributor{" +
// "code=" + code +
// ", name='" + name + '\'' +
// '}';
// }
// }
// Path: app/src/main/java/com/bdc/ociney/modele/Release.java
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.Movie.Distributor;
package com.bdc.ociney.modele;
public class Release {
@Expose
private String releaseDate;
@Expose
private ModelObject country;
@Expose
private ModelObject releaseState;
@Expose
private ModelObject releaseVersion;
@Expose
|
private Distributor distributor;
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/modele/Theater/TheaterShowtime.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/modele/Place.java
// public class Place {
//
// @Expose
// private Theater theater;
//
// public Theater getTheater() {
// return theater;
// }
//
// public void setTheater(Theater theater) {
// this.theater = theater;
// }
//
// @Override
// public String toString() {
// return "Place{" +
// "theater=" + theater +
// '}';
// }
// }
|
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
import com.bdc.ociney.modele.Movie.Movie;
import com.bdc.ociney.modele.Place;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
|
package com.bdc.ociney.modele.Theater;
public class TheaterShowtime {
@Expose
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/modele/Place.java
// public class Place {
//
// @Expose
// private Theater theater;
//
// public Theater getTheater() {
// return theater;
// }
//
// public void setTheater(Theater theater) {
// this.theater = theater;
// }
//
// @Override
// public String toString() {
// return "Place{" +
// "theater=" + theater +
// '}';
// }
// }
// Path: app/src/main/java/com/bdc/ociney/modele/Theater/TheaterShowtime.java
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
import com.bdc.ociney.modele.Movie.Movie;
import com.bdc.ociney.modele.Place;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
package com.bdc.ociney.modele.Theater;
public class TheaterShowtime {
@Expose
|
private Place place;
|
florent37/OCiney
|
app/src/main/java/com/bdc/ociney/modele/Theater/TheaterShowtime.java
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/modele/Place.java
// public class Place {
//
// @Expose
// private Theater theater;
//
// public Theater getTheater() {
// return theater;
// }
//
// public void setTheater(Theater theater) {
// this.theater = theater;
// }
//
// @Override
// public String toString() {
// return "Place{" +
// "theater=" + theater +
// '}';
// }
// }
|
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
import com.bdc.ociney.modele.Movie.Movie;
import com.bdc.ociney.modele.Place;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
|
try {
for (TheaterShowtime t : showtimes) {
if (t.getMovieShowtimes() != null)
for (MovieShowtime mst : t.getMovieShowtimes()) {
boolean avantPremiere = mst.getPreview().equals("true");
String version = mst.getVersion().get$();
String screenFormat = mst.getScreenFormat().get$();
if (cinema != null)
cinema.showTimes = showtimes;
if (mst.getOnShow() != null && mst.getOnShow().getMovie() != null) {
Movie movie = mst.getOnShow().getMovie();
if (!movies.containsKey(movie.getCode()))
movies.put(movie.getCode(), movie);
else {
movie = movies.get(movie.getCode());
}
Scr scr = mst.getScr().get(0);
if (scr.getT() != null) {
Horaires h = new Horaires();
h.setDate(scr.getD());
h.setFormatEcran(screenFormat);
h.setVersion(version);
h.setAvantPremier(avantPremiere);
h.setDisplay(mst.getDisplay());
|
// Path: app/src/main/java/com/bdc/ociney/modele/ModelObject.java
// public class ModelObject {
//
// @Expose
// private Integer code;
// @Expose
// private String value;
// @Expose
// private String $;
// @Expose
// private Integer p;
// @Expose
// private Double note;
// @Expose
// private String type;
//
// public Integer getCode() {
// return code;
// }
//
// public void setCode(Integer code) {
// this.code = code;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
//
// public String get$() {
// return $;
// }
//
// public void set$(String $) {
// this.$ = $;
// }
//
// public Integer getP() {
// return p;
// }
//
// public void setP(Integer p) {
// this.p = p;
// }
//
// public Double getNote() {
// return note;
// }
//
// public void setNote(Double note) {
// this.note = note;
// }
//
// public String getType() {
// return type;
// }
//
// public void setType(String type) {
// this.type = type;
// }
//
// public void setScheme(String scheme) {
// this.value = scheme;
// }
//
// @Override
// public String toString() {
// return "ModelObject{" +
// "code=" + code +
// ", $= " + $ +
// ", value='" + value + '\'' +
// ", p=" + p +
// ", type= " + type +
// ", note=" + note +
// '}';
// }
// }
//
// Path: app/src/main/java/com/bdc/ociney/modele/Place.java
// public class Place {
//
// @Expose
// private Theater theater;
//
// public Theater getTheater() {
// return theater;
// }
//
// public void setTheater(Theater theater) {
// this.theater = theater;
// }
//
// @Override
// public String toString() {
// return "Place{" +
// "theater=" + theater +
// '}';
// }
// }
// Path: app/src/main/java/com/bdc/ociney/modele/Theater/TheaterShowtime.java
import com.google.gson.annotations.Expose;
import com.bdc.ociney.modele.ModelObject;
import com.bdc.ociney.modele.Movie.Movie;
import com.bdc.ociney.modele.Place;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
try {
for (TheaterShowtime t : showtimes) {
if (t.getMovieShowtimes() != null)
for (MovieShowtime mst : t.getMovieShowtimes()) {
boolean avantPremiere = mst.getPreview().equals("true");
String version = mst.getVersion().get$();
String screenFormat = mst.getScreenFormat().get$();
if (cinema != null)
cinema.showTimes = showtimes;
if (mst.getOnShow() != null && mst.getOnShow().getMovie() != null) {
Movie movie = mst.getOnShow().getMovie();
if (!movies.containsKey(movie.getCode()))
movies.put(movie.getCode(), movie);
else {
movie = movies.get(movie.getCode());
}
Scr scr = mst.getScr().get(0);
if (scr.getT() != null) {
Horaires h = new Horaires();
h.setDate(scr.getD());
h.setFormatEcran(screenFormat);
h.setVersion(version);
h.setAvantPremier(avantPremiere);
h.setDisplay(mst.getDisplay());
|
for (ModelObject s : scr.getT()) {
|
adelnoureddine/jalen
|
1.0/src/main/java/jalen/formulas/cpu/CPUFormulaMaxFrequency.java
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
|
import jalen.sensors.cpu.CPUSensorsInterface;
|
/*
* Copyright (c) 2013, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaMaxFrequency implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
// Path: 1.0/src/main/java/jalen/formulas/cpu/CPUFormulaMaxFrequency.java
import jalen.sensors.cpu.CPUSensorsInterface;
/*
* Copyright (c) 2013, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaMaxFrequency implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
private CPUSensorsInterface cpuSensor;
|
adelnoureddine/jalen
|
1.1/src/main/java/jalen/formulas/cpu/CPUFormulaMaxFrequency.java
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
|
import jalen.sensors.cpu.CPUSensorsInterface;
|
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaMaxFrequency implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
// Path: 1.1/src/main/java/jalen/formulas/cpu/CPUFormulaMaxFrequency.java
import jalen.sensors.cpu.CPUSensorsInterface;
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaMaxFrequency implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
private CPUSensorsInterface cpuSensor;
|
adelnoureddine/jalen
|
1.0/src/main/java/jalen/formulas/cpu/CPUFormulaDVFS.java
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
|
import jalen.sensors.cpu.CPUSensorsInterface;
import java.util.HashMap;
import java.util.Map;
|
/*
* Copyright (c) 2013, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaDVFS implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
// Path: 1.0/src/main/java/jalen/formulas/cpu/CPUFormulaDVFS.java
import jalen.sensors.cpu.CPUSensorsInterface;
import java.util.HashMap;
import java.util.Map;
/*
* Copyright (c) 2013, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaDVFS implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
private CPUSensorsInterface cpuSensor;
|
adelnoureddine/jalen
|
trunk/src/main/java/jalen/formulas/disk/DiskFormulasProc.java
|
// Path: 1.0/src/main/java/jalen/sensors/disk/DiskSensorsInterface.java
// public interface DiskSensorsInterface {
//
// /**
// * Get number of bytes read and written by pid
// * @return An array with number of bytes read and written
// * double[0] = read
// * double[1] = write
// */
// public Double[] getProcesDiskReadWriteBytes();
//
// }
|
import jalen.sensors.disk.DiskSensorsInterface;
|
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.disk;
public class DiskFormulasProc implements DiskFormulasInterface {
/**
* Disk read and write power, and read and write rate
* Data from configuration file (from hardware specifications)
*/
private Double diskReadPower, diskReadRate, diskWritePower, diskWriteRate;
/**
* Power for reading/writing one byte
*/
private Double powerPerReadByte, powerPerWriteByte;
/**
* Disk sensor
*/
|
// Path: 1.0/src/main/java/jalen/sensors/disk/DiskSensorsInterface.java
// public interface DiskSensorsInterface {
//
// /**
// * Get number of bytes read and written by pid
// * @return An array with number of bytes read and written
// * double[0] = read
// * double[1] = write
// */
// public Double[] getProcesDiskReadWriteBytes();
//
// }
// Path: trunk/src/main/java/jalen/formulas/disk/DiskFormulasProc.java
import jalen.sensors.disk.DiskSensorsInterface;
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.disk;
public class DiskFormulasProc implements DiskFormulasInterface {
/**
* Disk read and write power, and read and write rate
* Data from configuration file (from hardware specifications)
*/
private Double diskReadPower, diskReadRate, diskWritePower, diskWriteRate;
/**
* Power for reading/writing one byte
*/
private Double powerPerReadByte, powerPerWriteByte;
/**
* Disk sensor
*/
|
private DiskSensorsInterface diskSensor;
|
adelnoureddine/jalen
|
trunk/src/main/java/jalen/formulas/cpu/CPUFormulaDVFS.java
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
|
import jalen.sensors.cpu.CPUSensorsInterface;
import java.util.HashMap;
import java.util.Map;
|
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaDVFS implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
// Path: trunk/src/main/java/jalen/sensors/cpu/CPUSensorsInterface.java
// public interface CPUSensorsInterface {
//
// /**
// * Calculate percentage of CPU usage for PID
// * @return the percentage of CPU usage by PID
// */
// double getProcessCPUUsagePercentage();
//
// /**
// * Calculate CPU time for each frequency
// * @return Map of CPU frequencies and the CPU time spend for each
// */
// Map<Double, Double> getTimeInFrequencies();
//
// }
// Path: trunk/src/main/java/jalen/formulas/cpu/CPUFormulaDVFS.java
import jalen.sensors.cpu.CPUSensorsInterface;
import java.util.HashMap;
import java.util.Map;
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.cpu;
public class CPUFormulaDVFS implements CPUFormulasInterface {
/**
* Thermal Design Power of the CPU (given by constructors)
*/
private double TDP;
/**
* TDP factor for CMOS formula
* By default, it is at 0.7
*/
private double TDPFactor = 0.7;
/**
* The CPU sensor used to collect data from the CPU
*/
|
private CPUSensorsInterface cpuSensor;
|
adelnoureddine/jalen
|
1.1/src/main/java/jalen/formulas/disk/DiskFormulasProc.java
|
// Path: 1.0/src/main/java/jalen/sensors/disk/DiskSensorsInterface.java
// public interface DiskSensorsInterface {
//
// /**
// * Get number of bytes read and written by pid
// * @return An array with number of bytes read and written
// * double[0] = read
// * double[1] = write
// */
// public Double[] getProcesDiskReadWriteBytes();
//
// }
|
import jalen.sensors.disk.DiskSensorsInterface;
|
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.disk;
public class DiskFormulasProc implements DiskFormulasInterface {
/**
* Disk read and write power, and read and write rate
* Data from configuration file (from hardware specifications)
*/
private Double diskReadPower, diskReadRate, diskWritePower, diskWriteRate;
/**
* Power for reading/writing one byte
*/
private Double powerPerReadByte, powerPerWriteByte;
/**
* Disk sensor
*/
|
// Path: 1.0/src/main/java/jalen/sensors/disk/DiskSensorsInterface.java
// public interface DiskSensorsInterface {
//
// /**
// * Get number of bytes read and written by pid
// * @return An array with number of bytes read and written
// * double[0] = read
// * double[1] = write
// */
// public Double[] getProcesDiskReadWriteBytes();
//
// }
// Path: 1.1/src/main/java/jalen/formulas/disk/DiskFormulasProc.java
import jalen.sensors.disk.DiskSensorsInterface;
/*
* Copyright (c) 2014, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.disk;
public class DiskFormulasProc implements DiskFormulasInterface {
/**
* Disk read and write power, and read and write rate
* Data from configuration file (from hardware specifications)
*/
private Double diskReadPower, diskReadRate, diskWritePower, diskWriteRate;
/**
* Power for reading/writing one byte
*/
private Double powerPerReadByte, powerPerWriteByte;
/**
* Disk sensor
*/
|
private DiskSensorsInterface diskSensor;
|
adelnoureddine/jalen
|
1.0/src/main/java/jalen/formulas/disk/DiskFormulasProc.java
|
// Path: 1.0/src/main/java/jalen/sensors/disk/DiskSensorsInterface.java
// public interface DiskSensorsInterface {
//
// /**
// * Get number of bytes read and written by pid
// * @return An array with number of bytes read and written
// * double[0] = read
// * double[1] = write
// */
// public Double[] getProcesDiskReadWriteBytes();
//
// }
|
import jalen.sensors.disk.DiskSensorsInterface;
|
/*
* Copyright (c) 2013, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.disk;
public class DiskFormulasProc implements DiskFormulasInterface {
/**
* Disk read and write power, and read and write rate
* Data from configuration file (from hardware specifications)
*/
private Double diskReadPower, diskReadRate, diskWritePower, diskWriteRate;
/**
* Power for reading/writing one byte
*/
private Double powerPerReadByte, powerPerWriteByte;
/**
* Disk sensor
*/
|
// Path: 1.0/src/main/java/jalen/sensors/disk/DiskSensorsInterface.java
// public interface DiskSensorsInterface {
//
// /**
// * Get number of bytes read and written by pid
// * @return An array with number of bytes read and written
// * double[0] = read
// * double[1] = write
// */
// public Double[] getProcesDiskReadWriteBytes();
//
// }
// Path: 1.0/src/main/java/jalen/formulas/disk/DiskFormulasProc.java
import jalen.sensors.disk.DiskSensorsInterface;
/*
* Copyright (c) 2013, Inria, University Lille 1.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Affero General Public License v3.0
* which accompanies this distribution, and is available at
* https://www.gnu.org/licenses/agpl-3.0.html
*
* Author : Adel Noureddine
*/
package jalen.formulas.disk;
public class DiskFormulasProc implements DiskFormulasInterface {
/**
* Disk read and write power, and read and write rate
* Data from configuration file (from hardware specifications)
*/
private Double diskReadPower, diskReadRate, diskWritePower, diskWriteRate;
/**
* Power for reading/writing one byte
*/
private Double powerPerReadByte, powerPerWriteByte;
/**
* Disk sensor
*/
|
private DiskSensorsInterface diskSensor;
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/DynamicIntervalTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2021-01-29.
*/
class DynamicIntervalTest {
private static final Logger logger = LoggerFactory.getLogger(DynamicIntervalTest.class);
@Test
void test() {
int[] interval = {2};
AtomicInteger counter = new AtomicInteger();
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/DynamicIntervalTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2021-01-29.
*/
class DynamicIntervalTest {
private static final Logger logger = LoggerFactory.getLogger(DynamicIntervalTest.class);
@Test
void test() {
int[] interval = {2};
AtomicInteger counter = new AtomicInteger();
|
BufferTrigger<String> buffer = BufferTrigger.<String, Integer> simple()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/BatchBlockingConflictTrigTest2.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2018-06-12.
*/
class BatchBlockingConflictTrigTest2 {
private static final Logger logger = LoggerFactory
.getLogger(BatchBlockingConflictTrigTest2.class);
private volatile boolean check = true;
private volatile boolean failed;
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/BatchBlockingConflictTrigTest2.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2018-06-12.
*/
class BatchBlockingConflictTrigTest2 {
private static final Logger logger = LoggerFactory
.getLogger(BatchBlockingConflictTrigTest2.class);
private volatile boolean check = true;
private volatile boolean failed;
|
private final BufferTrigger<Integer> trigger = BufferTrigger.<Integer> batchBlocking()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/BatchBlockDynamicTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.time.Duration.ofSeconds;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2019-12-03.
*/
class BatchBlockDynamicTest {
@Test
void test() {
Duration[] linger = {ofSeconds(1)};
int[] consumed = {0};
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/BatchBlockDynamicTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.time.Duration.ofSeconds;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2019-12-03.
*/
class BatchBlockDynamicTest {
@Test
void test() {
Duration[] linger = {ofSeconds(1)};
int[] consumed = {0};
|
BufferTrigger<String> buffer = BufferTrigger.<String> batchBlocking()
|
PhantomThief/buffer-trigger
|
src/main/java/com/github/phantomthief/collection/impl/GenericBatchConsumerTriggerBuilder.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import java.time.Duration;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.github.phantomthief.collection.BufferTrigger;
import com.github.phantomthief.util.ThrowableConsumer;
|
* 设置异常处理器.
* <p>
* 该处理器会在消费异常时执行.
*/
public GenericBatchConsumerTriggerBuilder<E>
setExceptionHandler(BiConsumer<? super Throwable, ? super List<E>> exceptionHandler) {
builder.setExceptionHandler(exceptionHandler);
return this;
}
/**
* 该方法已废弃,请使用{@link #bufferSize}替代.
*/
@Deprecated
public GenericBatchConsumerTriggerBuilder<E> queueCapacity(int capacity) {
builder.queueCapacity(capacity);
return this;
}
/**
* 设置缓存队列最大容量.
*/
public GenericBatchConsumerTriggerBuilder<E> bufferSize(int bufferSize) {
builder.bufferSize(bufferSize);
return this;
}
/**
* 生成实例.
*/
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/main/java/com/github/phantomthief/collection/impl/GenericBatchConsumerTriggerBuilder.java
import java.time.Duration;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.github.phantomthief.collection.BufferTrigger;
import com.github.phantomthief.util.ThrowableConsumer;
* 设置异常处理器.
* <p>
* 该处理器会在消费异常时执行.
*/
public GenericBatchConsumerTriggerBuilder<E>
setExceptionHandler(BiConsumer<? super Throwable, ? super List<E>> exceptionHandler) {
builder.setExceptionHandler(exceptionHandler);
return this;
}
/**
* 该方法已废弃,请使用{@link #bufferSize}替代.
*/
@Deprecated
public GenericBatchConsumerTriggerBuilder<E> queueCapacity(int capacity) {
builder.queueCapacity(capacity);
return this;
}
/**
* 设置缓存队列最大容量.
*/
public GenericBatchConsumerTriggerBuilder<E> bufferSize(int bufferSize) {
builder.bufferSize(bufferSize);
return this;
}
/**
* 生成实例.
*/
|
public BufferTrigger<E> build() {
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/collection/impl/BackPressureTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination;
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.Collections.synchronizedList;
import static java.util.concurrent.Executors.newFixedThreadPool;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
import com.google.common.util.concurrent.AtomicLongMap;
|
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2019-07-30.
*/
class BackPressureTest {
private static final Logger logger = LoggerFactory.getLogger(BackPressureTest.class);
@Test
void test() {
List<String> consumed = new ArrayList<>();
List<String> backPressured = Collections.synchronizedList(new ArrayList<>());
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/collection/impl/BackPressureTest.java
import static com.google.common.util.concurrent.MoreExecutors.shutdownAndAwaitTermination;
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.Collections.synchronizedList;
import static java.util.concurrent.Executors.newFixedThreadPool;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import javax.annotation.Nullable;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
import com.google.common.util.concurrent.AtomicLongMap;
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2019-07-30.
*/
class BackPressureTest {
private static final Logger logger = LoggerFactory.getLogger(BackPressureTest.class);
@Test
void test() {
List<String> consumed = new ArrayList<>();
List<String> backPressured = Collections.synchronizedList(new ArrayList<>());
|
BufferTrigger<String> buffer = BufferTrigger.<String, List<String>> simple()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/collection/impl/FixIntervalTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.lang.System.currentTimeMillis;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2017-11-13.
*/
class FixIntervalTest {
private static final Logger logger = LoggerFactory.getLogger(FixIntervalTest.class);
private static final ThreadLocal<Long> THREAD_LOCAL = new ThreadLocal<>();
private static final int INTERVAL = 2;
@Test
void testDelayMode() {
logger.info("start.");
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/collection/impl/FixIntervalTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.lang.System.currentTimeMillis;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2017-11-13.
*/
class FixIntervalTest {
private static final Logger logger = LoggerFactory.getLogger(FixIntervalTest.class);
private static final ThreadLocal<Long> THREAD_LOCAL = new ThreadLocal<>();
private static final int INTERVAL = 2;
@Test
void testDelayMode() {
logger.info("start.");
|
BufferTrigger<String> trigger = BufferTrigger.simpleTrigger()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/MultiThreadQueueTriggerTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.Collections.synchronizedSet;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
*/
class MultiThreadQueueTriggerTest {
private static final Logger logger = LoggerFactory.getLogger(MultiThreadQueueTriggerTest.class);
private Set<String> deal;
@Test
void test() {
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/MultiThreadQueueTriggerTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.Collections.synchronizedSet;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
*/
class MultiThreadQueueTriggerTest {
private static final Logger logger = LoggerFactory.getLogger(MultiThreadQueueTriggerTest.class);
private Set<String> deal;
@Test
void test() {
|
BufferTrigger<String> buffer = BufferTrigger.batchBlockingTrigger()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/collection/impl/BuilderTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2019-07-30.
*/
class BuilderTest {
@Test
void testBuilder() {
assertThrows(NullPointerException.class, () ->
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/collection/impl/BuilderTest.java
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2019-07-30.
*/
class BuilderTest {
@Test
void testBuilder() {
assertThrows(NullPointerException.class, () ->
|
BufferTrigger.simple()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/BatchBlockingConflictTrigTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.ThreadPoolExecutor;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2018-06-12.
*/
class BatchBlockingConflictTrigTest {
private ExecutorService executor = new ThreadPoolExecutor(2, 2, 0L, MILLISECONDS,
new LinkedBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
private volatile boolean check = true;
private volatile boolean failed;
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/BatchBlockingConflictTrigTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.ThreadPoolExecutor;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2018-06-12.
*/
class BatchBlockingConflictTrigTest {
private ExecutorService executor = new ThreadPoolExecutor(2, 2, 0L, MILLISECONDS,
new LinkedBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
private volatile boolean check = true;
private volatile boolean failed;
|
private final BufferTrigger<Integer> trigger = BufferTrigger.<Integer> batchBlocking()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/TestCloseable.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2020-07-20.
*/
class TestCloseable {
@Test
void testSimpleClose() {
AtomicInteger result = new AtomicInteger();
AtomicInteger consumeCount = new AtomicInteger();
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/TestCloseable.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2020-07-20.
*/
class TestCloseable {
@Test
void testSimpleClose() {
AtomicInteger result = new AtomicInteger();
AtomicInteger consumeCount = new AtomicInteger();
|
BufferTrigger<String> trigger = BufferTrigger.<String, AtomicInteger> simple()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/SimpleBufferMaxBufferCountTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2019-12-03.
*/
class SimpleBufferMaxBufferCountTest {
@Test
void test() {
long[] maxSize = {100};
long[] sleep = {100000};
long[] rejected = {0};
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/test/SimpleBufferMaxBufferCountTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 2019-12-03.
*/
class SimpleBufferMaxBufferCountTest {
@Test
void test() {
long[] maxSize = {100};
long[] sleep = {100000};
long[] rejected = {0};
|
BufferTrigger<String> trigger = BufferTrigger.<String, int[]> simple()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/collection/impl/NameRegistryTest.java
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
|
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
|
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2021-02-04.
*/
class NameRegistryTest {
private static final String[] NAME = {null};
static {
SimpleBufferTrigger.setupGlobalNameRegistry(() -> {
String name1 = NameRegistry.autoRegistry().name();
NAME[0] = name1;
return name1;
});
}
|
// Path: src/main/java/com/github/phantomthief/collection/BufferTrigger.java
// public interface BufferTrigger<E> extends AutoCloseable {
//
// /**
// * 将需要定时处理的元素推入缓存.
// *
// * @throws IllegalStateException 当实例被关闭时,调用该方法可能会引起该异常.
// */
// void enqueue(E element);
//
// /**
// * 手动触发一次缓存消费.
// * <p>一般处于缓存关闭方法{@link #close()}实现中.
// */
// void manuallyDoTrigger();
//
// /**
// * 获取当前缓存中未消费元素个数.
// */
// long getPendingChanges();
//
// /**
// * 快捷创建{@link GenericSimpleBufferTriggerBuilder}建造器,用于构造{@link SimpleBufferTrigger}实例.
// * <p>
// * 推荐用该方法构造{@link SimpleBufferTrigger}实例,适用用大多数场景
// *
// * @param <E> 元素类型
// * @param <C> 持有元素的容器类型,如使用默认容器实现(不指定 {@link GenericSimpleBufferTriggerBuilder#setContainerEx}),默认为 {@link ConcurrentHashMap#newKeySet()},
// * <p>此时本泛型可以考虑设置为 <code>Set<E></code>
// * <p>注意,强烈不建议使用默认容器,任何时候,都应该优先考虑自行设计容器类型!
// * @return {@link GenericSimpleBufferTriggerBuilder} 实例
// */
// static <E, C> GenericSimpleBufferTriggerBuilder<E, C> simple() {
// return new GenericSimpleBufferTriggerBuilder<>(SimpleBufferTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,可更换为{@link #simple()}.
// */
// @Deprecated
// static SimpleBufferTriggerBuilder<Object, Object> simpleTrigger() {
// return SimpleBufferTrigger.newBuilder();
// }
//
// /**
// * 提供自带背压(back-pressure)的简单批量归并消费能力.
// * <p>
// *
// * <p>
// * FIXME: 高亮注意,目前 {@link #simple()} 也提供了背压能力 {@link GenericSimpleBufferTriggerBuilder#enableBackPressure()}
// * 所以本模式的意义已经小的多,如果没特殊情况,可以考虑都切换到 {@link SimpleBufferTrigger} 版本.
// */
// static <E> GenericBatchConsumerTriggerBuilder<E> batchBlocking() {
// return new GenericBatchConsumerTriggerBuilder<>(
// BatchConsumeBlockingQueueTrigger.newBuilder());
// }
//
// /**
// * 该方法即将废弃,请使用{@link #batchBlocking()}替代.
// */
// @Deprecated
// static BatchConsumerTriggerBuilder<Object> batchBlockingTrigger() {
// return BatchConsumeBlockingQueueTrigger.newBuilder();
// }
//
// /**
// * 停止该实例,释放所持有资源.
// * <p>
// * 请注意自动关闭特性仅在处于{@code try}-with-resources时才会生效,其它场景请在服务停止的回调方法中显式调用该方法.
// */
// @Override
// void close(); // override to remove throws Exception.
// }
// Path: src/test/java/com/github/phantomthief/collection/impl/NameRegistryTest.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.collection.BufferTrigger;
package com.github.phantomthief.collection.impl;
/**
* @author w.vela
* Created on 2021-02-04.
*/
class NameRegistryTest {
private static final String[] NAME = {null};
static {
SimpleBufferTrigger.setupGlobalNameRegistry(() -> {
String name1 = NameRegistry.autoRegistry().name();
NAME[0] = name1;
return name1;
});
}
|
private BufferTrigger<String> buffer1 = BufferTrigger.<String, AtomicLong> simple()
|
PhantomThief/buffer-trigger
|
src/test/java/com/github/phantomthief/test/TickerBatchInvokerTest.java
|
// Path: src/main/java/com/github/phantomthief/util/TickerBatchInvoker.java
// public class TickerBatchInvoker<K, V> implements Function<K, CompletableFuture<V>> {
//
// private final ThrowableFunction<Collection<K>, Map<K, V>, ? extends Throwable> batchInvoker;
// private final Executor executor;
// private final BufferTrigger<TwoTuple<K, CompletableFuture<V>>> bufferTrigger;
//
// private TickerBatchInvoker(long ticker,
// ThrowableFunction<Collection<K>, Map<K, V>, ? extends Throwable> batchInvoker,
// Executor executor) {
// this.batchInvoker = batchInvoker;
// this.executor = executor;
// this.bufferTrigger = SimpleBufferTrigger.newBuilder()
// .setContainer(ConcurrentHashMap::new, this::enqueue)
// .on(ticker, MILLISECONDS, 1)
// .consumer(this::batchInvoke)
// .build();
// }
//
// public static Builder newBuilder() {
// return new Builder();
// }
//
// private boolean enqueue(Map<K, List<CompletableFuture<V>>> map,
// TwoTuple<K, CompletableFuture<V>> e) {
// map.compute(e.getFirst(), (k, list) -> {
// if (list == null) {
// list = new ArrayList<>();
// }
// synchronized (list) {
// list.add(e.getSecond());
// }
// return list;
// });
// return true;
// }
//
// private void batchInvoke(Map<K, List<CompletableFuture<V>>> map) {
// executor.execute(() -> {
// try {
// Map<K, V> result = batchInvoker.apply(map.keySet());
// map.forEach((key, futures) -> {
// V v = result.get(key);
// // 虽然框架会尽力保证enqueue/consume是互斥的,但是这里还是重复保证下
// synchronized (futures) {
// for (CompletableFuture<V> future : futures) {
// future.complete(v);
// }
// }
// });
// } catch (Throwable e) {
// for (List<CompletableFuture<V>> futures : map.values()) {
// synchronized (futures) {
// futures.stream()
// .filter(future -> !future.isDone())
// .forEach(future -> future.completeExceptionally(e));
// }
// }
// }
// });
// }
//
// @Override
// public CompletableFuture<V> apply(K key) {
// CompletableFuture<V> future = new CompletableFuture<>();
// bufferTrigger.enqueue(tuple(key, future));
// return future;
// }
//
// public static class Builder {
//
// private long ticker;
// private Executor executor;
//
// private Builder() {
// }
//
// public Builder ticker(long time, TimeUnit unit) {
// this.ticker = unit.toMillis(time);
// return this;
// }
//
// public Builder executor(Executor executor) {
// this.executor = executor;
// return this;
// }
//
// public Builder threads(int nThreads) {
// this.executor = Executors.newFixedThreadPool(nThreads);
// return this;
// }
//
// public <K, V> TickerBatchInvoker<K, V> build(
// ThrowableFunction<Collection<K>, Map<K, V>, ? extends Throwable> batchInvoker) {
// checkNotNull(batchInvoker);
// ensure();
// return new TickerBatchInvoker<>(ticker, batchInvoker, executor);
// }
//
// private void ensure() {
// if (ticker <= 0) {
// ticker = SECONDS.toMillis(1);
// }
// if (executor == null) {
// executor = Executors.newCachedThreadPool();
// }
// }
// }
// }
|
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.util.TickerBatchInvoker;
|
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 16/5/21.
*/
class TickerBatchInvokerTest {
private Map<Integer, String> load(Collection<Integer> keys) {
System.out.println("invoke:" + keys);
sleepUninterruptibly(2, SECONDS);
return keys.stream().collect(toMap(identity(), Object::toString));
}
private Map<Integer, String> loadEmpty(Collection<Integer> keys) {
System.out.println("invoke empty:" + keys);
return emptyMap();
}
private Map<Integer, String> loadException(Collection<Integer> keys)
throws IllegalStateException {
System.out.println("invoke empty:" + keys);
throw new IllegalStateException("test");
}
@Test
void test() {
|
// Path: src/main/java/com/github/phantomthief/util/TickerBatchInvoker.java
// public class TickerBatchInvoker<K, V> implements Function<K, CompletableFuture<V>> {
//
// private final ThrowableFunction<Collection<K>, Map<K, V>, ? extends Throwable> batchInvoker;
// private final Executor executor;
// private final BufferTrigger<TwoTuple<K, CompletableFuture<V>>> bufferTrigger;
//
// private TickerBatchInvoker(long ticker,
// ThrowableFunction<Collection<K>, Map<K, V>, ? extends Throwable> batchInvoker,
// Executor executor) {
// this.batchInvoker = batchInvoker;
// this.executor = executor;
// this.bufferTrigger = SimpleBufferTrigger.newBuilder()
// .setContainer(ConcurrentHashMap::new, this::enqueue)
// .on(ticker, MILLISECONDS, 1)
// .consumer(this::batchInvoke)
// .build();
// }
//
// public static Builder newBuilder() {
// return new Builder();
// }
//
// private boolean enqueue(Map<K, List<CompletableFuture<V>>> map,
// TwoTuple<K, CompletableFuture<V>> e) {
// map.compute(e.getFirst(), (k, list) -> {
// if (list == null) {
// list = new ArrayList<>();
// }
// synchronized (list) {
// list.add(e.getSecond());
// }
// return list;
// });
// return true;
// }
//
// private void batchInvoke(Map<K, List<CompletableFuture<V>>> map) {
// executor.execute(() -> {
// try {
// Map<K, V> result = batchInvoker.apply(map.keySet());
// map.forEach((key, futures) -> {
// V v = result.get(key);
// // 虽然框架会尽力保证enqueue/consume是互斥的,但是这里还是重复保证下
// synchronized (futures) {
// for (CompletableFuture<V> future : futures) {
// future.complete(v);
// }
// }
// });
// } catch (Throwable e) {
// for (List<CompletableFuture<V>> futures : map.values()) {
// synchronized (futures) {
// futures.stream()
// .filter(future -> !future.isDone())
// .forEach(future -> future.completeExceptionally(e));
// }
// }
// }
// });
// }
//
// @Override
// public CompletableFuture<V> apply(K key) {
// CompletableFuture<V> future = new CompletableFuture<>();
// bufferTrigger.enqueue(tuple(key, future));
// return future;
// }
//
// public static class Builder {
//
// private long ticker;
// private Executor executor;
//
// private Builder() {
// }
//
// public Builder ticker(long time, TimeUnit unit) {
// this.ticker = unit.toMillis(time);
// return this;
// }
//
// public Builder executor(Executor executor) {
// this.executor = executor;
// return this;
// }
//
// public Builder threads(int nThreads) {
// this.executor = Executors.newFixedThreadPool(nThreads);
// return this;
// }
//
// public <K, V> TickerBatchInvoker<K, V> build(
// ThrowableFunction<Collection<K>, Map<K, V>, ? extends Throwable> batchInvoker) {
// checkNotNull(batchInvoker);
// ensure();
// return new TickerBatchInvoker<>(ticker, batchInvoker, executor);
// }
//
// private void ensure() {
// if (ticker <= 0) {
// ticker = SECONDS.toMillis(1);
// }
// if (executor == null) {
// executor = Executors.newCachedThreadPool();
// }
// }
// }
// }
// Path: src/test/java/com/github/phantomthief/test/TickerBatchInvokerTest.java
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
import static java.util.Collections.emptyMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
import org.junit.jupiter.api.Test;
import com.github.phantomthief.util.TickerBatchInvoker;
package com.github.phantomthief.test;
/**
* @author w.vela
* Created on 16/5/21.
*/
class TickerBatchInvokerTest {
private Map<Integer, String> load(Collection<Integer> keys) {
System.out.println("invoke:" + keys);
sleepUninterruptibly(2, SECONDS);
return keys.stream().collect(toMap(identity(), Object::toString));
}
private Map<Integer, String> loadEmpty(Collection<Integer> keys) {
System.out.println("invoke empty:" + keys);
return emptyMap();
}
private Map<Integer, String> loadException(Collection<Integer> keys)
throws IllegalStateException {
System.out.println("invoke empty:" + keys);
throw new IllegalStateException("test");
}
@Test
void test() {
|
TickerBatchInvoker<Integer, String> batchInvoker = TickerBatchInvoker.newBuilder()
|
PhantomThief/buffer-trigger
|
src/main/java/com/github/phantomthief/collection/impl/MultiIntervalTriggerStrategy.java
|
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static class TriggerResult {
//
// private static final TriggerResult EMPTY = new TriggerResult(false, DAYS.toMillis(1));
// private final boolean doConsumer;
// private final long nextPeriod;
//
// private TriggerResult(boolean doConsumer, long nextPeriod) {
// this.doConsumer = doConsumer;
// this.nextPeriod = nextPeriod;
// }
//
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// public static TriggerResult empty() {
// return EMPTY;
// }
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public interface TriggerStrategy {
//
// /**
// * 获取触发器执行结果,用于判断是否可执行消费回调
// */
// TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount);
// }
|
import static com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult.trig;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.System.currentTimeMillis;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerStrategy;
|
long minTriggerPeriod() { // for test case
return minTriggerPeriod;
}
private long checkAndCalcMinPeriod() {
long minPeriod = Long.MAX_VALUE;
Long maxTrigChangeCount = null;
long lastPeriod = 0;
for (Entry<Long, Long> entry : triggerMap.entrySet()) {
long period = entry.getKey();
minPeriod = min(minPeriod, period);
if (lastPeriod > 0) {
minPeriod = min(minPeriod, abs(lastPeriod - period));
}
long trigChangedCount = entry.getValue();
if (maxTrigChangeCount == null) {
maxTrigChangeCount = trigChangedCount;
} else {
if (maxTrigChangeCount <= trigChangedCount) {
throw new IllegalArgumentException(
"found invalid trigger setting:" + triggerMap);
}
}
lastPeriod = period;
}
return minPeriod;
}
@Override
|
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static class TriggerResult {
//
// private static final TriggerResult EMPTY = new TriggerResult(false, DAYS.toMillis(1));
// private final boolean doConsumer;
// private final long nextPeriod;
//
// private TriggerResult(boolean doConsumer, long nextPeriod) {
// this.doConsumer = doConsumer;
// this.nextPeriod = nextPeriod;
// }
//
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// public static TriggerResult empty() {
// return EMPTY;
// }
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public interface TriggerStrategy {
//
// /**
// * 获取触发器执行结果,用于判断是否可执行消费回调
// */
// TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount);
// }
// Path: src/main/java/com/github/phantomthief/collection/impl/MultiIntervalTriggerStrategy.java
import static com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult.trig;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.System.currentTimeMillis;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerStrategy;
long minTriggerPeriod() { // for test case
return minTriggerPeriod;
}
private long checkAndCalcMinPeriod() {
long minPeriod = Long.MAX_VALUE;
Long maxTrigChangeCount = null;
long lastPeriod = 0;
for (Entry<Long, Long> entry : triggerMap.entrySet()) {
long period = entry.getKey();
minPeriod = min(minPeriod, period);
if (lastPeriod > 0) {
minPeriod = min(minPeriod, abs(lastPeriod - period));
}
long trigChangedCount = entry.getValue();
if (maxTrigChangeCount == null) {
maxTrigChangeCount = trigChangedCount;
} else {
if (maxTrigChangeCount <= trigChangedCount) {
throw new IllegalArgumentException(
"found invalid trigger setting:" + triggerMap);
}
}
lastPeriod = period;
}
return minPeriod;
}
@Override
|
public TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount) {
|
PhantomThief/buffer-trigger
|
src/main/java/com/github/phantomthief/collection/impl/MultiIntervalTriggerStrategy.java
|
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static class TriggerResult {
//
// private static final TriggerResult EMPTY = new TriggerResult(false, DAYS.toMillis(1));
// private final boolean doConsumer;
// private final long nextPeriod;
//
// private TriggerResult(boolean doConsumer, long nextPeriod) {
// this.doConsumer = doConsumer;
// this.nextPeriod = nextPeriod;
// }
//
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// public static TriggerResult empty() {
// return EMPTY;
// }
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public interface TriggerStrategy {
//
// /**
// * 获取触发器执行结果,用于判断是否可执行消费回调
// */
// TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount);
// }
|
import static com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult.trig;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.System.currentTimeMillis;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerStrategy;
|
if (maxTrigChangeCount == null) {
maxTrigChangeCount = trigChangedCount;
} else {
if (maxTrigChangeCount <= trigChangedCount) {
throw new IllegalArgumentException(
"found invalid trigger setting:" + triggerMap);
}
}
lastPeriod = period;
}
return minPeriod;
}
@Override
public TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount) {
checkArgument(!triggerMap.isEmpty());
boolean doConsumer = false;
long now = currentTimeMillis();
for (Entry<Long, Long> entry : triggerMap.entrySet()) {
if (now - lastConsumeTimestamp < entry.getKey()) {
continue;
}
if (changedCount >= entry.getValue()) {
doConsumer = true;
break;
}
}
|
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public static class TriggerResult {
//
// private static final TriggerResult EMPTY = new TriggerResult(false, DAYS.toMillis(1));
// private final boolean doConsumer;
// private final long nextPeriod;
//
// private TriggerResult(boolean doConsumer, long nextPeriod) {
// this.doConsumer = doConsumer;
// this.nextPeriod = nextPeriod;
// }
//
// public static TriggerResult trig(boolean doConsumer, long nextPeriod) {
// return new TriggerResult(doConsumer, nextPeriod);
// }
//
// public static TriggerResult empty() {
// return EMPTY;
// }
// }
//
// Path: src/main/java/com/github/phantomthief/collection/impl/SimpleBufferTrigger.java
// public interface TriggerStrategy {
//
// /**
// * 获取触发器执行结果,用于判断是否可执行消费回调
// */
// TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount);
// }
// Path: src/main/java/com/github/phantomthief/collection/impl/MultiIntervalTriggerStrategy.java
import static com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult.trig;
import static com.google.common.base.Preconditions.checkArgument;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.System.currentTimeMillis;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerResult;
import com.github.phantomthief.collection.impl.SimpleBufferTrigger.TriggerStrategy;
if (maxTrigChangeCount == null) {
maxTrigChangeCount = trigChangedCount;
} else {
if (maxTrigChangeCount <= trigChangedCount) {
throw new IllegalArgumentException(
"found invalid trigger setting:" + triggerMap);
}
}
lastPeriod = period;
}
return minPeriod;
}
@Override
public TriggerResult canTrigger(long lastConsumeTimestamp, long changedCount) {
checkArgument(!triggerMap.isEmpty());
boolean doConsumer = false;
long now = currentTimeMillis();
for (Entry<Long, Long> entry : triggerMap.entrySet()) {
if (now - lastConsumeTimestamp < entry.getKey()) {
continue;
}
if (changedCount >= entry.getValue()) {
doConsumer = true;
break;
}
}
|
return trig(doConsumer, minTriggerPeriod);
|
mindbody/Ironhide
|
lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/IronhideViews/Swipeable.java
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/SwipeAction.java
// public class SwipeAction {
//
// /**
// * Initial size is the number of combination of most used swipe speeds
// * (from {@link android.support.test.espresso.action.Swipe}) and the number of
// * {@link com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.SwipeDirection}s
// */
// private static final HashMap<Pair<Swiper, SwipeDirection>, GeneralSwipeAction> bufferedSwipeActions
// = new HashMap<>(SwipeDirection.values().length * Swipe.values().length);
//
//
// /**
// * Gets a swipe action.
// *
// * @param speed the speed of the swipe
// * @param direction the direction of the swipe
// * @return the swipe action requested
// */
// public static GeneralSwipeAction getSwipe(Swiper speed, SwipeDirection direction) {
// Pair<Swiper, SwipeDirection> key = new Pair<>(speed, direction);
//
// if (!bufferedSwipeActions.containsKey(key))
// bufferedSwipeActions.put(key, generateSwipe(speed, direction));
//
// return bufferedSwipeActions.get(key);
// }
//
// /**
// * Creates a new swipe action.
// *
// * @param speed the speed of the swipe
// * @param direction the direction of the swipe
// * @return the swipe action requested
// */
// private static GeneralSwipeAction generateSwipe(Swiper speed, SwipeDirection direction) {
// return new GeneralSwipeAction(speed, direction.start, direction.end, Press.FINGER);
// }
//
// /**
// * An enum to associate directions with start and end locations on a screen.
// */
// public enum SwipeDirection {
// UP (BOTTOM_CENTER, TOP_CENTER),
// DOWN (TOP_CENTER, BOTTOM_CENTER),
// LEFT (CENTER_RIGHT, CENTER_LEFT),
// RIGHT (CENTER_LEFT, CENTER_RIGHT);
//
// public final CoordinatesProvider start, end;
//
// private SwipeDirection(CoordinatesProvider start, CoordinatesProvider end) {
// this.start = start;
// this.end = end;
// }
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/PageObjects/PageObject.java
// public class PageObject {
//
// public static final int DEFAULT_PAUSE_TIME = 2000;
//
// /**
// * Pause the test run for {@link PageObject#DEFAULT_PAUSE_TIME} milliseconds
// * @return A generic of the passed in type
// */
// public <T extends PageObject> T pause(Class<T> type) {
// return pause(type, DEFAULT_PAUSE_TIME);
// }
//
// /**
// * Pause the test run for a given amount of time(in milliseconds).
// * @param timeInMillis Time, in milliseconds, to pause for.
// * @return A generic of the passed in type.
// */
// public <T extends PageObject> T pause(Class<T> type, int timeInMillis) {
// try {
// Thread.sleep(timeInMillis);
// return type.newInstance();
// } catch (InstantiationException | IllegalAccessException | InterruptedException e) {
// e.printStackTrace();
// }
// return null;
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/SwipeAction.java
// public static GeneralSwipeAction getSwipe(Swiper speed, SwipeDirection direction) {
// Pair<Swiper, SwipeDirection> key = new Pair<>(speed, direction);
//
// if (!bufferedSwipeActions.containsKey(key))
// bufferedSwipeActions.put(key, generateSwipe(speed, direction));
//
// return bufferedSwipeActions.get(key);
// }
|
import android.support.test.espresso.Root;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.Swiper;
import android.view.View;
import com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction;
import com.mindbodyonline.ironhide.PageObjects.PageObject;
import org.hamcrest.Matcher;
import static android.support.test.espresso.action.Swipe.FAST;
import static com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.getSwipe;
|
package com.mindbodyonline.ironhide.Infrastructure.IronhideViews;
/**
* Simple element that allows to perform a swipe on the screen.
* Allows fast/slow versions of Espresso's swipes, as well as changing the number of swipes done in
* one function call.
* Use this when the main purpose of the element will be to swipe the screen
*
* @param <T> The model the current element will return when interacted with
*/
public class Swipeable<T extends PageObject> extends BaseView<T> {
public static final int DEFAULT_TIMES = 1;
public static final Swiper DEFAULT_SPEED = FAST;
/** @see BaseView#BaseView(Class, org.hamcrest.Matcher) */
public Swipeable(Class<T> type, Matcher<View> selector) {
super(type, selector);
}
/** @see BaseView#BaseView(Class, int) */
public Swipeable(Class<T> type, int resourceId) {
super(type, resourceId);
}
/** {@inheritDoc} */
@Override
public <E extends PageObject> Swipeable<E> goesTo(Class<E> type) {
return new Swipeable<>(type, getSelector());
}
/**
* {@link Swipeable#swipe(
* android.support.test.espresso.action.Swiper,
* com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.SwipeDirection,
* int)}
* with {@link Swipeable#DEFAULT_SPEED}
* and {@link Swipeable#DEFAULT_TIMES}
*/
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/SwipeAction.java
// public class SwipeAction {
//
// /**
// * Initial size is the number of combination of most used swipe speeds
// * (from {@link android.support.test.espresso.action.Swipe}) and the number of
// * {@link com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.SwipeDirection}s
// */
// private static final HashMap<Pair<Swiper, SwipeDirection>, GeneralSwipeAction> bufferedSwipeActions
// = new HashMap<>(SwipeDirection.values().length * Swipe.values().length);
//
//
// /**
// * Gets a swipe action.
// *
// * @param speed the speed of the swipe
// * @param direction the direction of the swipe
// * @return the swipe action requested
// */
// public static GeneralSwipeAction getSwipe(Swiper speed, SwipeDirection direction) {
// Pair<Swiper, SwipeDirection> key = new Pair<>(speed, direction);
//
// if (!bufferedSwipeActions.containsKey(key))
// bufferedSwipeActions.put(key, generateSwipe(speed, direction));
//
// return bufferedSwipeActions.get(key);
// }
//
// /**
// * Creates a new swipe action.
// *
// * @param speed the speed of the swipe
// * @param direction the direction of the swipe
// * @return the swipe action requested
// */
// private static GeneralSwipeAction generateSwipe(Swiper speed, SwipeDirection direction) {
// return new GeneralSwipeAction(speed, direction.start, direction.end, Press.FINGER);
// }
//
// /**
// * An enum to associate directions with start and end locations on a screen.
// */
// public enum SwipeDirection {
// UP (BOTTOM_CENTER, TOP_CENTER),
// DOWN (TOP_CENTER, BOTTOM_CENTER),
// LEFT (CENTER_RIGHT, CENTER_LEFT),
// RIGHT (CENTER_LEFT, CENTER_RIGHT);
//
// public final CoordinatesProvider start, end;
//
// private SwipeDirection(CoordinatesProvider start, CoordinatesProvider end) {
// this.start = start;
// this.end = end;
// }
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/PageObjects/PageObject.java
// public class PageObject {
//
// public static final int DEFAULT_PAUSE_TIME = 2000;
//
// /**
// * Pause the test run for {@link PageObject#DEFAULT_PAUSE_TIME} milliseconds
// * @return A generic of the passed in type
// */
// public <T extends PageObject> T pause(Class<T> type) {
// return pause(type, DEFAULT_PAUSE_TIME);
// }
//
// /**
// * Pause the test run for a given amount of time(in milliseconds).
// * @param timeInMillis Time, in milliseconds, to pause for.
// * @return A generic of the passed in type.
// */
// public <T extends PageObject> T pause(Class<T> type, int timeInMillis) {
// try {
// Thread.sleep(timeInMillis);
// return type.newInstance();
// } catch (InstantiationException | IllegalAccessException | InterruptedException e) {
// e.printStackTrace();
// }
// return null;
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/SwipeAction.java
// public static GeneralSwipeAction getSwipe(Swiper speed, SwipeDirection direction) {
// Pair<Swiper, SwipeDirection> key = new Pair<>(speed, direction);
//
// if (!bufferedSwipeActions.containsKey(key))
// bufferedSwipeActions.put(key, generateSwipe(speed, direction));
//
// return bufferedSwipeActions.get(key);
// }
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/IronhideViews/Swipeable.java
import android.support.test.espresso.Root;
import android.support.test.espresso.ViewAction;
import android.support.test.espresso.action.Swiper;
import android.view.View;
import com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction;
import com.mindbodyonline.ironhide.PageObjects.PageObject;
import org.hamcrest.Matcher;
import static android.support.test.espresso.action.Swipe.FAST;
import static com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.getSwipe;
package com.mindbodyonline.ironhide.Infrastructure.IronhideViews;
/**
* Simple element that allows to perform a swipe on the screen.
* Allows fast/slow versions of Espresso's swipes, as well as changing the number of swipes done in
* one function call.
* Use this when the main purpose of the element will be to swipe the screen
*
* @param <T> The model the current element will return when interacted with
*/
public class Swipeable<T extends PageObject> extends BaseView<T> {
public static final int DEFAULT_TIMES = 1;
public static final Swiper DEFAULT_SPEED = FAST;
/** @see BaseView#BaseView(Class, org.hamcrest.Matcher) */
public Swipeable(Class<T> type, Matcher<View> selector) {
super(type, selector);
}
/** @see BaseView#BaseView(Class, int) */
public Swipeable(Class<T> type, int resourceId) {
super(type, resourceId);
}
/** {@inheritDoc} */
@Override
public <E extends PageObject> Swipeable<E> goesTo(Class<E> type) {
return new Swipeable<>(type, getSelector());
}
/**
* {@link Swipeable#swipe(
* android.support.test.espresso.action.Swiper,
* com.mindbodyonline.ironhide.Infrastructure.Extensions.SwipeAction.SwipeDirection,
* int)}
* with {@link Swipeable#DEFAULT_SPEED}
* and {@link Swipeable#DEFAULT_TIMES}
*/
|
public T swipe(SwipeAction.SwipeDirection direction) {
|
mindbody/Ironhide
|
lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/IronhideViews/TextField.java
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/TextViewMatchers.java
// public class TextViewMatchers {
//
// /**
// * Checks to see if a TextView's text is empty or null.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyOrNullString() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getText() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty or null string");
// }
// };
// }
//
// /**
// * Checks to see if a TextView's text is empty.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyString() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getText() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty string");
// }
// };
// }
//
// // Hint matchers
//
//
// /**
// * Checks to see if a TextView's hint text is empty or null.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyOrNullHint() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getHint() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty or null string");
// }
// };
// }
//
// /**
// * Checks to see if a TextView's hint text is empty.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyHint() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getHint() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty string");
// }
// };
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/PageObjects/PageObject.java
// public class PageObject {
//
// public static final int DEFAULT_PAUSE_TIME = 2000;
//
// /**
// * Pause the test run for {@link PageObject#DEFAULT_PAUSE_TIME} milliseconds
// * @return A generic of the passed in type
// */
// public <T extends PageObject> T pause(Class<T> type) {
// return pause(type, DEFAULT_PAUSE_TIME);
// }
//
// /**
// * Pause the test run for a given amount of time(in milliseconds).
// * @param timeInMillis Time, in milliseconds, to pause for.
// * @return A generic of the passed in type.
// */
// public <T extends PageObject> T pause(Class<T> type, int timeInMillis) {
// try {
// Thread.sleep(timeInMillis);
// return type.newInstance();
// } catch (InstantiationException | IllegalAccessException | InterruptedException e) {
// e.printStackTrace();
// }
// return null;
// }
// }
|
import android.support.test.espresso.Root;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;
import com.mindbodyonline.ironhide.Infrastructure.Extensions.TextViewMatchers;
import com.mindbodyonline.ironhide.PageObjects.PageObject;
import org.hamcrest.Matcher;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;
import static org.hamcrest.Matchers.startsWith;
|
return withHintText(endsWith(fromId(resourceId)));
}
/**
* Checks to see if a TextView's text is equal to (ignoring case) a certain string given the string's resource id.
*
* @param resourceId The string's resource id
* @return The model reached by interacting with this element.
*/
public T hintEqualToIgnoringCase(int resourceId) {
return withHintText(equalToIgnoringCase(fromId(resourceId)));
}
/**
* Checks to see if a TextView's text is equal to (ignoring white space around words) a certain string given the string's resource id.
*
* @param resourceId The string's resource id
* @return The model reached by interacting with this element.
*/
public T hintEqualToIgnoringWhiteSpace(int resourceId) {
return withHintText(equalToIgnoringWhiteSpace(fromId(resourceId)));
}
/**
* Checks to see if a TextView's text is empty or null.
* NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
*
* @return The model reached by interacting with this element.
*/
public T isEmptyOrNullHint() {
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/TextViewMatchers.java
// public class TextViewMatchers {
//
// /**
// * Checks to see if a TextView's text is empty or null.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyOrNullString() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getText() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty or null string");
// }
// };
// }
//
// /**
// * Checks to see if a TextView's text is empty.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyString() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getText() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty string");
// }
// };
// }
//
// // Hint matchers
//
//
// /**
// * Checks to see if a TextView's hint text is empty or null.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyOrNullHint() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getHint() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty or null string");
// }
// };
// }
//
// /**
// * Checks to see if a TextView's hint text is empty.
// * NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
// * @return A Matcher to check using Espresso ViewAssertions.matches method
// */
// public static Matcher<View> isEmptyHint() {
// return new BoundedMatcher<View, TextView>(TextView.class) {
// @Override
// protected boolean matchesSafely(TextView textView) {
// return textView != null
// && (textView.getHint() == null || textView.getText().length() == 0);
// }
//
// @Override
// public void describeTo(Description description) {
// description.appendText("with text empty string");
// }
// };
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/PageObjects/PageObject.java
// public class PageObject {
//
// public static final int DEFAULT_PAUSE_TIME = 2000;
//
// /**
// * Pause the test run for {@link PageObject#DEFAULT_PAUSE_TIME} milliseconds
// * @return A generic of the passed in type
// */
// public <T extends PageObject> T pause(Class<T> type) {
// return pause(type, DEFAULT_PAUSE_TIME);
// }
//
// /**
// * Pause the test run for a given amount of time(in milliseconds).
// * @param timeInMillis Time, in milliseconds, to pause for.
// * @return A generic of the passed in type.
// */
// public <T extends PageObject> T pause(Class<T> type, int timeInMillis) {
// try {
// Thread.sleep(timeInMillis);
// return type.newInstance();
// } catch (InstantiationException | IllegalAccessException | InterruptedException e) {
// e.printStackTrace();
// }
// return null;
// }
// }
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/IronhideViews/TextField.java
import android.support.test.espresso.Root;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;
import com.mindbodyonline.ironhide.Infrastructure.Extensions.TextViewMatchers;
import com.mindbodyonline.ironhide.PageObjects.PageObject;
import org.hamcrest.Matcher;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;
import static org.hamcrest.Matchers.startsWith;
return withHintText(endsWith(fromId(resourceId)));
}
/**
* Checks to see if a TextView's text is equal to (ignoring case) a certain string given the string's resource id.
*
* @param resourceId The string's resource id
* @return The model reached by interacting with this element.
*/
public T hintEqualToIgnoringCase(int resourceId) {
return withHintText(equalToIgnoringCase(fromId(resourceId)));
}
/**
* Checks to see if a TextView's text is equal to (ignoring white space around words) a certain string given the string's resource id.
*
* @param resourceId The string's resource id
* @return The model reached by interacting with this element.
*/
public T hintEqualToIgnoringWhiteSpace(int resourceId) {
return withHintText(equalToIgnoringWhiteSpace(fromId(resourceId)));
}
/**
* Checks to see if a TextView's text is empty or null.
* NOTE: see issue 72 for Espresso (https://code.google.com/p/android-test-kit/issues/detail?id=72)
*
* @return The model reached by interacting with this element.
*/
public T isEmptyOrNullHint() {
|
return checkMatches(TextViewMatchers.isEmptyOrNullHint());
|
mindbody/Ironhide
|
lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/IronhideViews/DynamicListAdapter.java
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/PageObjects/PageObject.java
// public class PageObject {
//
// public static final int DEFAULT_PAUSE_TIME = 2000;
//
// /**
// * Pause the test run for {@link PageObject#DEFAULT_PAUSE_TIME} milliseconds
// * @return A generic of the passed in type
// */
// public <T extends PageObject> T pause(Class<T> type) {
// return pause(type, DEFAULT_PAUSE_TIME);
// }
//
// /**
// * Pause the test run for a given amount of time(in milliseconds).
// * @param timeInMillis Time, in milliseconds, to pause for.
// * @return A generic of the passed in type.
// */
// public <T extends PageObject> T pause(Class<T> type, int timeInMillis) {
// try {
// Thread.sleep(timeInMillis);
// return type.newInstance();
// } catch (InstantiationException | IllegalAccessException | InterruptedException e) {
// e.printStackTrace();
// }
// return null;
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/BaseViewMatchers.java
// public static Matcher<View> hasIndex(final int index) {
// return checkHasIndex(index);
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/BaseViewMatchers.java
// public static Matcher<View> instanceOf(final Class<?> type) {
// return checkInstanceOf(type);
// }
|
import android.view.View;
import com.mindbodyonline.ironhide.PageObjects.PageObject;
import org.hamcrest.Matcher;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers.hasIndex;
import static com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers.instanceOf;
import static org.hamcrest.Matchers.allOf;
|
package com.mindbodyonline.ironhide.Infrastructure.IronhideViews;
/**
* Simple element that allows to interact with ListViews that have children added dynamically.
* Enables access to ListItems inside a dynamic ListView that does not use an adapter.
* This element is rarely used, as these types of ListViews are considered bad practice
*
* @param <T> The model the current element will return when interacted with
*/
public class DynamicListAdapter<T extends PageObject> {
private final Class<T> type;
private final Matcher<View> childMatcher;
/**
* A generically typed DynamicListAdapter with selector:
* {@link com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers#instanceOf(Class)}
* @param itemType the class type to use for {@link com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers#instanceOf(Class)}
*/
public DynamicListAdapter(Class<T> type, Class itemType) {
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/PageObjects/PageObject.java
// public class PageObject {
//
// public static final int DEFAULT_PAUSE_TIME = 2000;
//
// /**
// * Pause the test run for {@link PageObject#DEFAULT_PAUSE_TIME} milliseconds
// * @return A generic of the passed in type
// */
// public <T extends PageObject> T pause(Class<T> type) {
// return pause(type, DEFAULT_PAUSE_TIME);
// }
//
// /**
// * Pause the test run for a given amount of time(in milliseconds).
// * @param timeInMillis Time, in milliseconds, to pause for.
// * @return A generic of the passed in type.
// */
// public <T extends PageObject> T pause(Class<T> type, int timeInMillis) {
// try {
// Thread.sleep(timeInMillis);
// return type.newInstance();
// } catch (InstantiationException | IllegalAccessException | InterruptedException e) {
// e.printStackTrace();
// }
// return null;
// }
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/BaseViewMatchers.java
// public static Matcher<View> hasIndex(final int index) {
// return checkHasIndex(index);
// }
//
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/Extensions/BaseViewMatchers.java
// public static Matcher<View> instanceOf(final Class<?> type) {
// return checkInstanceOf(type);
// }
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Infrastructure/IronhideViews/DynamicListAdapter.java
import android.view.View;
import com.mindbodyonline.ironhide.PageObjects.PageObject;
import org.hamcrest.Matcher;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers.hasIndex;
import static com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers.instanceOf;
import static org.hamcrest.Matchers.allOf;
package com.mindbodyonline.ironhide.Infrastructure.IronhideViews;
/**
* Simple element that allows to interact with ListViews that have children added dynamically.
* Enables access to ListItems inside a dynamic ListView that does not use an adapter.
* This element is rarely used, as these types of ListViews are considered bad practice
*
* @param <T> The model the current element will return when interacted with
*/
public class DynamicListAdapter<T extends PageObject> {
private final Class<T> type;
private final Matcher<View> childMatcher;
/**
* A generically typed DynamicListAdapter with selector:
* {@link com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers#instanceOf(Class)}
* @param itemType the class type to use for {@link com.mindbodyonline.ironhide.Infrastructure.Extensions.BaseViewMatchers#instanceOf(Class)}
*/
public DynamicListAdapter(Class<T> type, Class itemType) {
|
this(type, instanceOf(itemType));
|
mindbody/Ironhide
|
app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/LongListMatchersTest.java
|
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/LongListActivity.java
// public class LongListActivity extends Activity {
//
// @VisibleForTesting
// public static final String STR = "STR";
// @VisibleForTesting
// public static final String LEN = "LEN";
// @VisibleForTesting
// public static final String FOOTER = "FOOTER";
//
// private List<Map<String, Object>> data = new ArrayList<>();
// private LayoutInflater layoutInflater;
//
// @Override
// public void onCreate(Bundle bundle) {
// super.onCreate(bundle);
// populateData();
// setContentView(R.layout.list_activity);
// ((TextView) findViewById(R.id.selection_row_value)).setText("");
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
//
// ListView listView = (ListView) findViewById(R.id.list);
// String[] from = new String[] {STR, LEN};
// int[] to = new int[] {R.id.item_content, R.id.item_size};
// layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//
// ListAdapter adapter = new SimpleAdapter(this, data, R.layout.list_item, from, to) {
// @Override
// public View getView(final int position, View convertView, ViewGroup parent) {
// if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.list_item, null);
// }
//
// TextView textViewOne = (TextView) convertView.findViewById(R.id.item_content);
// if (textViewOne != null) {
// textViewOne.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("1");
// }
// });
// }
//
// TextView textViewTwo = (TextView) convertView.findViewById(R.id.item_size);
// if (textViewTwo != null) {
// textViewTwo.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("2");
// }
// });
// }
// return super.getView(position, convertView, parent);
// }
// };
//
// View footerView = layoutInflater.inflate(R.layout.list_item, listView, false);
// ((TextView) footerView.findViewById(R.id.item_content)).setText("count:");
// ((TextView) footerView.findViewById(R.id.item_size)).setText(String.valueOf(data.size()));
// listView.addFooterView(footerView, FOOTER, true);
//
// listView.setAdapter(adapter);
// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(
// AdapterView<?> unusedParent, View clickedView, int position, long id) {
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// }
// });
// }
//
// public Map<String, Object> makeItem(int forRow) {
// Map<String, Object> dataRow = new HashMap<>();
// dataRow.put(STR, "item: " + forRow);
// dataRow.put(LEN, ((String) dataRow.get(STR)).length());
// return dataRow;
// }
//
// private void populateData() {
// for (int i = 0; i < 100; i++) {
// data.add(makeItem(i));
// }
// }
//
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemContent(String expectedText) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkNotNull(expectedText);
// return withItemContent(equalTo(expectedText));
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemSize(int itemSize) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkArgument(itemSize > -1);
// return withItemSize(equalTo(itemSize));
// }
|
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import com.mindbodyonline.ironhidetestapp.LongListActivity;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemContent;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemSize;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
|
package com.mindbodyonline.ironhidetestapp.tests;
/**
* UnitTests for LongListMatchers matcher factory.
*/
public final class LongListMatchersTest extends ActivityUnitTestCase<LongListActivity> {
public LongListMatchersTest() {
super(LongListActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
startActivity(new Intent(getInstrumentation().getTargetContext(), LongListActivity.class),
null, null);
}
public void testWithContent() {
|
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/LongListActivity.java
// public class LongListActivity extends Activity {
//
// @VisibleForTesting
// public static final String STR = "STR";
// @VisibleForTesting
// public static final String LEN = "LEN";
// @VisibleForTesting
// public static final String FOOTER = "FOOTER";
//
// private List<Map<String, Object>> data = new ArrayList<>();
// private LayoutInflater layoutInflater;
//
// @Override
// public void onCreate(Bundle bundle) {
// super.onCreate(bundle);
// populateData();
// setContentView(R.layout.list_activity);
// ((TextView) findViewById(R.id.selection_row_value)).setText("");
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
//
// ListView listView = (ListView) findViewById(R.id.list);
// String[] from = new String[] {STR, LEN};
// int[] to = new int[] {R.id.item_content, R.id.item_size};
// layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//
// ListAdapter adapter = new SimpleAdapter(this, data, R.layout.list_item, from, to) {
// @Override
// public View getView(final int position, View convertView, ViewGroup parent) {
// if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.list_item, null);
// }
//
// TextView textViewOne = (TextView) convertView.findViewById(R.id.item_content);
// if (textViewOne != null) {
// textViewOne.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("1");
// }
// });
// }
//
// TextView textViewTwo = (TextView) convertView.findViewById(R.id.item_size);
// if (textViewTwo != null) {
// textViewTwo.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("2");
// }
// });
// }
// return super.getView(position, convertView, parent);
// }
// };
//
// View footerView = layoutInflater.inflate(R.layout.list_item, listView, false);
// ((TextView) footerView.findViewById(R.id.item_content)).setText("count:");
// ((TextView) footerView.findViewById(R.id.item_size)).setText(String.valueOf(data.size()));
// listView.addFooterView(footerView, FOOTER, true);
//
// listView.setAdapter(adapter);
// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(
// AdapterView<?> unusedParent, View clickedView, int position, long id) {
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// }
// });
// }
//
// public Map<String, Object> makeItem(int forRow) {
// Map<String, Object> dataRow = new HashMap<>();
// dataRow.put(STR, "item: " + forRow);
// dataRow.put(LEN, ((String) dataRow.get(STR)).length());
// return dataRow;
// }
//
// private void populateData() {
// for (int i = 0; i < 100; i++) {
// data.add(makeItem(i));
// }
// }
//
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemContent(String expectedText) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkNotNull(expectedText);
// return withItemContent(equalTo(expectedText));
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemSize(int itemSize) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkArgument(itemSize > -1);
// return withItemSize(equalTo(itemSize));
// }
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/LongListMatchersTest.java
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import com.mindbodyonline.ironhidetestapp.LongListActivity;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemContent;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemSize;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
package com.mindbodyonline.ironhidetestapp.tests;
/**
* UnitTests for LongListMatchers matcher factory.
*/
public final class LongListMatchersTest extends ActivityUnitTestCase<LongListActivity> {
public LongListMatchersTest() {
super(LongListActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
startActivity(new Intent(getInstrumentation().getTargetContext(), LongListActivity.class),
null, null);
}
public void testWithContent() {
|
assertThat(getActivity().makeItem(54), withItemContent("item: 54"));
|
mindbody/Ironhide
|
app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/LongListMatchersTest.java
|
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/LongListActivity.java
// public class LongListActivity extends Activity {
//
// @VisibleForTesting
// public static final String STR = "STR";
// @VisibleForTesting
// public static final String LEN = "LEN";
// @VisibleForTesting
// public static final String FOOTER = "FOOTER";
//
// private List<Map<String, Object>> data = new ArrayList<>();
// private LayoutInflater layoutInflater;
//
// @Override
// public void onCreate(Bundle bundle) {
// super.onCreate(bundle);
// populateData();
// setContentView(R.layout.list_activity);
// ((TextView) findViewById(R.id.selection_row_value)).setText("");
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
//
// ListView listView = (ListView) findViewById(R.id.list);
// String[] from = new String[] {STR, LEN};
// int[] to = new int[] {R.id.item_content, R.id.item_size};
// layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//
// ListAdapter adapter = new SimpleAdapter(this, data, R.layout.list_item, from, to) {
// @Override
// public View getView(final int position, View convertView, ViewGroup parent) {
// if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.list_item, null);
// }
//
// TextView textViewOne = (TextView) convertView.findViewById(R.id.item_content);
// if (textViewOne != null) {
// textViewOne.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("1");
// }
// });
// }
//
// TextView textViewTwo = (TextView) convertView.findViewById(R.id.item_size);
// if (textViewTwo != null) {
// textViewTwo.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("2");
// }
// });
// }
// return super.getView(position, convertView, parent);
// }
// };
//
// View footerView = layoutInflater.inflate(R.layout.list_item, listView, false);
// ((TextView) footerView.findViewById(R.id.item_content)).setText("count:");
// ((TextView) footerView.findViewById(R.id.item_size)).setText(String.valueOf(data.size()));
// listView.addFooterView(footerView, FOOTER, true);
//
// listView.setAdapter(adapter);
// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(
// AdapterView<?> unusedParent, View clickedView, int position, long id) {
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// }
// });
// }
//
// public Map<String, Object> makeItem(int forRow) {
// Map<String, Object> dataRow = new HashMap<>();
// dataRow.put(STR, "item: " + forRow);
// dataRow.put(LEN, ((String) dataRow.get(STR)).length());
// return dataRow;
// }
//
// private void populateData() {
// for (int i = 0; i < 100; i++) {
// data.add(makeItem(i));
// }
// }
//
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemContent(String expectedText) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkNotNull(expectedText);
// return withItemContent(equalTo(expectedText));
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemSize(int itemSize) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkArgument(itemSize > -1);
// return withItemSize(equalTo(itemSize));
// }
|
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import com.mindbodyonline.ironhidetestapp.LongListActivity;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemContent;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemSize;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
|
package com.mindbodyonline.ironhidetestapp.tests;
/**
* UnitTests for LongListMatchers matcher factory.
*/
public final class LongListMatchersTest extends ActivityUnitTestCase<LongListActivity> {
public LongListMatchersTest() {
super(LongListActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
startActivity(new Intent(getInstrumentation().getTargetContext(), LongListActivity.class),
null, null);
}
public void testWithContent() {
assertThat(getActivity().makeItem(54), withItemContent("item: 54"));
assertThat(getActivity().makeItem(54), withItemContent(endsWith("54")));
assertFalse(withItemContent("hello world").matches(getActivity().makeItem(54)));
}
@SuppressWarnings("unchecked")
public void testWithItemSize() {
|
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/LongListActivity.java
// public class LongListActivity extends Activity {
//
// @VisibleForTesting
// public static final String STR = "STR";
// @VisibleForTesting
// public static final String LEN = "LEN";
// @VisibleForTesting
// public static final String FOOTER = "FOOTER";
//
// private List<Map<String, Object>> data = new ArrayList<>();
// private LayoutInflater layoutInflater;
//
// @Override
// public void onCreate(Bundle bundle) {
// super.onCreate(bundle);
// populateData();
// setContentView(R.layout.list_activity);
// ((TextView) findViewById(R.id.selection_row_value)).setText("");
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
//
// ListView listView = (ListView) findViewById(R.id.list);
// String[] from = new String[] {STR, LEN};
// int[] to = new int[] {R.id.item_content, R.id.item_size};
// layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//
// ListAdapter adapter = new SimpleAdapter(this, data, R.layout.list_item, from, to) {
// @Override
// public View getView(final int position, View convertView, ViewGroup parent) {
// if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.list_item, null);
// }
//
// TextView textViewOne = (TextView) convertView.findViewById(R.id.item_content);
// if (textViewOne != null) {
// textViewOne.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("1");
// }
// });
// }
//
// TextView textViewTwo = (TextView) convertView.findViewById(R.id.item_size);
// if (textViewTwo != null) {
// textViewTwo.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// ((TextView) findViewById(R.id.selection_column_value)).setText("2");
// }
// });
// }
// return super.getView(position, convertView, parent);
// }
// };
//
// View footerView = layoutInflater.inflate(R.layout.list_item, listView, false);
// ((TextView) footerView.findViewById(R.id.item_content)).setText("count:");
// ((TextView) footerView.findViewById(R.id.item_size)).setText(String.valueOf(data.size()));
// listView.addFooterView(footerView, FOOTER, true);
//
// listView.setAdapter(adapter);
// listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
// @Override
// public void onItemClick(
// AdapterView<?> unusedParent, View clickedView, int position, long id) {
// ((TextView) findViewById(R.id.selection_column_value)).setText("");
// ((TextView) findViewById(R.id.selection_row_value)).setText(String.valueOf(position));
// }
// });
// }
//
// public Map<String, Object> makeItem(int forRow) {
// Map<String, Object> dataRow = new HashMap<>();
// dataRow.put(STR, "item: " + forRow);
// dataRow.put(LEN, ((String) dataRow.get(STR)).length());
// return dataRow;
// }
//
// private void populateData() {
// for (int i = 0; i < 100; i++) {
// data.add(makeItem(i));
// }
// }
//
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemContent(String expectedText) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkNotNull(expectedText);
// return withItemContent(equalTo(expectedText));
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/LongListMatchers.java
// public static Matcher<Object> withItemSize(int itemSize) {
// // use preconditions to fail fast when a test is creating an invalid matcher.
// checkArgument(itemSize > -1);
// return withItemSize(equalTo(itemSize));
// }
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/LongListMatchersTest.java
import android.content.Intent;
import android.test.ActivityUnitTestCase;
import com.mindbodyonline.ironhidetestapp.LongListActivity;
import static android.support.test.espresso.matcher.ViewMatchers.assertThat;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemContent;
import static com.mindbodyonline.ironhidetestapp.LongListMatchers.withItemSize;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
package com.mindbodyonline.ironhidetestapp.tests;
/**
* UnitTests for LongListMatchers matcher factory.
*/
public final class LongListMatchersTest extends ActivityUnitTestCase<LongListActivity> {
public LongListMatchersTest() {
super(LongListActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
startActivity(new Intent(getInstrumentation().getTargetContext(), LongListActivity.class),
null, null);
}
public void testWithContent() {
assertThat(getActivity().makeItem(54), withItemContent("item: 54"));
assertThat(getActivity().makeItem(54), withItemContent(endsWith("54")));
assertFalse(withItemContent("hello world").matches(getActivity().makeItem(54)));
}
@SuppressWarnings("unchecked")
public void testWithItemSize() {
|
assertThat(getActivity().makeItem(54), withItemSize(8));
|
mindbody/Ironhide
|
app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/InjectActivityTest.java
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Fixture/BaseInstrumentTestCase.java
// @RunWith(AndroidJUnit4.class)
// public class BaseInstrumentTestCase<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
//
// protected T initActivity;
//
// /**
// * @see ActivityInstrumentationTestCase2#ActivityInstrumentationTestCase2(Class)
// */
// public BaseInstrumentTestCase(Class<T> activityClass) {
// super(activityClass);
// }
//
// /**
// * {@inheritDoc}
// * The default setup for AndroidJUnit tests.
// * If overrode, include the @Before tag.
// */
// @Override
// @Before
// public void setUp() throws Exception {
// injectInstrumentation(InstrumentationRegistry.getInstrumentation());
// initActivity = getActivity();
// setFailureHandler(new BaseFailureHandler(this));
// }
//
// /**
// * {@inheritDoc}
// * The default tear down for AndroidJUnit tests.
// * If overrode, include the @After tag.
// */
// @Override
// @After
// public void tearDown() throws Exception {
// super.tearDown();
// }
//
// /** @see android.support.test.espresso.Espresso#setFailureHandler(android.support.test.espresso.FailureHandler) */
// protected void onFailure(FailureHandler delegate, Throwable error, Matcher<View> viewMatcher) {
// delegate.handle(error, viewMatcher);
// }
//
// /**
// * A failure handler that calls {@link BaseInstrumentTestCase#onFailure(FailureHandler, Throwable, Matcher)}
// * so that failures can be more easily handled. Does not prevent use of ones own FailureHandler
// * to handle errors as seen fit.
// */
// private static class BaseFailureHandler implements FailureHandler {
// private final FailureHandler delegate;
// private final BaseInstrumentTestCase fixture;
//
// public BaseFailureHandler(BaseInstrumentTestCase fixture) {
// this.fixture = fixture;
// this.delegate = new DefaultFailureHandler(fixture.getInstrumentation().getTargetContext());
// }
//
// @Override
// public void handle(Throwable error, Matcher<View> viewMatcher) {
// fixture.onFailure(delegate, error, viewMatcher);
// }
// }
// }
//
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/DisplayActivity.java
// public class DisplayActivity extends Activity {
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.display_activity);
// TextView textView = (TextView) findViewById(R.id.display_data);
// textView.setText(getIntent().getStringExtra(SendActivity.EXTRA_DATA));
// }
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/models/DisplayModel.java
// public class DisplayModel extends PageObject {
// public Clickable<DisplayModel> displayText = new Clickable<>(DisplayModel.class, R.id.display_data);
// }
|
import android.content.Intent;
import android.test.suitebuilder.annotation.LargeTest;
import com.mindbodyonline.ironhide.Fixture.BaseInstrumentTestCase;
import com.mindbodyonline.ironhidetestapp.DisplayActivity;
import com.mindbodyonline.ironhidetestapp.models.DisplayModel;
import org.junit.Test;
|
package com.mindbodyonline.ironhidetestapp.tests;
/**
* Demonstrates the usage of
* {@link android.test.ActivityInstrumentationTestCase2#setActivityIntent(android.content.Intent)}
*/
@LargeTest
public class InjectActivityTest extends BaseInstrumentTestCase<DisplayActivity> {
private static final String INJECTED_TEXT = "this is my cool injection text string";
public InjectActivityTest() {
super(DisplayActivity.class);
}
@Override
public void setUp() throws Exception {
Intent toStart = new Intent(Intent.ACTION_MAIN);
toStart.putExtra("com.mindbodyonline.ironhidetestapp.DATA" /* aka. SendActivity.EXTRA_DATA*/, INJECTED_TEXT);
setActivityIntent(toStart);
// call this after so that we can start the activity with the intent we want
super.setUp();
}
@Test
public void testInjectedText() {
|
// Path: lib/src/main/java/com/mindbodyonline/ironhide/Fixture/BaseInstrumentTestCase.java
// @RunWith(AndroidJUnit4.class)
// public class BaseInstrumentTestCase<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
//
// protected T initActivity;
//
// /**
// * @see ActivityInstrumentationTestCase2#ActivityInstrumentationTestCase2(Class)
// */
// public BaseInstrumentTestCase(Class<T> activityClass) {
// super(activityClass);
// }
//
// /**
// * {@inheritDoc}
// * The default setup for AndroidJUnit tests.
// * If overrode, include the @Before tag.
// */
// @Override
// @Before
// public void setUp() throws Exception {
// injectInstrumentation(InstrumentationRegistry.getInstrumentation());
// initActivity = getActivity();
// setFailureHandler(new BaseFailureHandler(this));
// }
//
// /**
// * {@inheritDoc}
// * The default tear down for AndroidJUnit tests.
// * If overrode, include the @After tag.
// */
// @Override
// @After
// public void tearDown() throws Exception {
// super.tearDown();
// }
//
// /** @see android.support.test.espresso.Espresso#setFailureHandler(android.support.test.espresso.FailureHandler) */
// protected void onFailure(FailureHandler delegate, Throwable error, Matcher<View> viewMatcher) {
// delegate.handle(error, viewMatcher);
// }
//
// /**
// * A failure handler that calls {@link BaseInstrumentTestCase#onFailure(FailureHandler, Throwable, Matcher)}
// * so that failures can be more easily handled. Does not prevent use of ones own FailureHandler
// * to handle errors as seen fit.
// */
// private static class BaseFailureHandler implements FailureHandler {
// private final FailureHandler delegate;
// private final BaseInstrumentTestCase fixture;
//
// public BaseFailureHandler(BaseInstrumentTestCase fixture) {
// this.fixture = fixture;
// this.delegate = new DefaultFailureHandler(fixture.getInstrumentation().getTargetContext());
// }
//
// @Override
// public void handle(Throwable error, Matcher<View> viewMatcher) {
// fixture.onFailure(delegate, error, viewMatcher);
// }
// }
// }
//
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/DisplayActivity.java
// public class DisplayActivity extends Activity {
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.display_activity);
// TextView textView = (TextView) findViewById(R.id.display_data);
// textView.setText(getIntent().getStringExtra(SendActivity.EXTRA_DATA));
// }
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/models/DisplayModel.java
// public class DisplayModel extends PageObject {
// public Clickable<DisplayModel> displayText = new Clickable<>(DisplayModel.class, R.id.display_data);
// }
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/InjectActivityTest.java
import android.content.Intent;
import android.test.suitebuilder.annotation.LargeTest;
import com.mindbodyonline.ironhide.Fixture.BaseInstrumentTestCase;
import com.mindbodyonline.ironhidetestapp.DisplayActivity;
import com.mindbodyonline.ironhidetestapp.models.DisplayModel;
import org.junit.Test;
package com.mindbodyonline.ironhidetestapp.tests;
/**
* Demonstrates the usage of
* {@link android.test.ActivityInstrumentationTestCase2#setActivityIntent(android.content.Intent)}
*/
@LargeTest
public class InjectActivityTest extends BaseInstrumentTestCase<DisplayActivity> {
private static final String INJECTED_TEXT = "this is my cool injection text string";
public InjectActivityTest() {
super(DisplayActivity.class);
}
@Override
public void setUp() throws Exception {
Intent toStart = new Intent(Intent.ACTION_MAIN);
toStart.putExtra("com.mindbodyonline.ironhidetestapp.DATA" /* aka. SendActivity.EXTRA_DATA*/, INJECTED_TEXT);
setActivityIntent(toStart);
// call this after so that we can start the activity with the intent we want
super.setUp();
}
@Test
public void testInjectedText() {
|
new DisplayModel().displayText.withText(INJECTED_TEXT);
|
mindbody/Ironhide
|
app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/BasicTest.java
|
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/SimpleActivity.java
// public class SimpleActivity extends Activity implements OnItemSelectedListener{
//
// static final String EXTRA_DATA = "com.mindbodyonline.ironhidetestapp.DATA";
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.simple_activity);
//
// Spinner spinner = (Spinner) findViewById(R.id.spinner_simple);
// ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
// R.array.spinner_array, android.R.layout.simple_spinner_item);
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// spinner.setAdapter(adapter);
// spinner.setOnItemSelectedListener(this);
// }
//
// public void simpleButtonClicked(View view) {
// TextView textView = (TextView) findViewById(R.id.text_simple);
// String message = "Hello Espresso!";
// textView.setText(message);
// }
//
// /** Called when user clicks the Send button */
// public void sendButtonClicked(@SuppressWarnings("unused") View view) {
// Intent intent = new Intent(this, DisplayActivity.class);
// EditText editText = (EditText) findViewById(R.id.sendtext_simple);
// intent.putExtra(EXTRA_DATA, editText.getText().toString());
// startActivity(intent);
// }
//
// public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
// TextView textView = (TextView) findViewById(R.id.spinnertext_simple);
// textView.setText(String.format("One %s a day!", parent.getItemAtPosition(pos)));
// }
//
// public void onNothingSelected(AdapterView<?> parent) {
// }
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/TestFixture.java
// public class TestFixture <T extends Activity> extends BaseInstrumentTestCase<T>{
//
// protected ActionBarModel ActionBarPage = new ActionBarModel();
// protected LongListModel LongListPage = new LongListModel();
// protected SimpleModel SimplePage = new SimpleModel();
// protected DrawerModel DrawerPage = new DrawerModel();
// protected DisplayModel DisplayPage = new DisplayModel();
// protected MenuModel MenuPage = new MenuModel();
// protected SendModel SendPage = new SendModel();
// protected ScrollModel ScrollPage = new ScrollModel();
// protected ViewPagerModel PagerPage = new ViewPagerModel();
// protected SyncModel SyncPage = new SyncModel();
// protected ZoomModel ZoomPage = new ZoomModel();
//
// public TestFixture(Class<T> activityClass) {
// super(activityClass);
// }
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/models/SimpleModel.java
// public class SimpleModel extends PageObject {
//
// public Clickable<SimpleModel> SimpleButton = new Clickable<>(SimpleModel.class, R.id.button_simple);
//
// public Clickable<SimpleModel> SimpleText = new Clickable<>(SimpleModel.class, R.id.text_simple);
//
// public TextField<SimpleModel> SimpleSendText = new TextField<>(SimpleModel.class, R.id.sendtext_simple);
//
// public Clickable<DisplayModel> SimpleSend = new Clickable<>(DisplayModel.class, R.id.send_simple);
//
// public SpinnerView<SimpleModel> SimpleSpinner = new SpinnerView<>(SimpleModel.class, R.id.spinner_simple);
//
// public ListAdapter<SimpleModel> SpinnerList = new ListAdapter<>(SimpleModel.class, String.class);
// }
|
import android.test.suitebuilder.annotation.LargeTest;
import com.mindbodyonline.ironhidetestapp.R;
import com.mindbodyonline.ironhidetestapp.SimpleActivity;
import com.mindbodyonline.ironhidetestapp.TestFixture;
import com.mindbodyonline.ironhidetestapp.models.SimpleModel;
import org.junit.Test;
|
package com.mindbodyonline.ironhidetestapp.tests;
/**
* Highlights basic
* {@link android.support.test.espresso.Espresso#onView(org.hamcrest.Matcher)}
* functionality.
*/
@LargeTest
public class BasicTest extends TestFixture<SimpleActivity> {
public BasicTest() {
super(SimpleActivity.class);
}
@Test
public void testSimpleClickAndCheckText() {
SimplePage
.SimpleButton.click()
.SimpleText.withText("Hello Espresso!")
;
}
@Test
public void testTypingAndPressBack() {
SimplePage
.SimpleSendText.typeText(R.string.hello_world)
.SimpleSendText.closeKeyboard()
.SimpleSend.click()
.displayText.withText(R.string.hello_world)
|
// Path: app/src/main/java/com/mindbodyonline/ironhidetestapp/SimpleActivity.java
// public class SimpleActivity extends Activity implements OnItemSelectedListener{
//
// static final String EXTRA_DATA = "com.mindbodyonline.ironhidetestapp.DATA";
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.simple_activity);
//
// Spinner spinner = (Spinner) findViewById(R.id.spinner_simple);
// ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
// R.array.spinner_array, android.R.layout.simple_spinner_item);
// adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// spinner.setAdapter(adapter);
// spinner.setOnItemSelectedListener(this);
// }
//
// public void simpleButtonClicked(View view) {
// TextView textView = (TextView) findViewById(R.id.text_simple);
// String message = "Hello Espresso!";
// textView.setText(message);
// }
//
// /** Called when user clicks the Send button */
// public void sendButtonClicked(@SuppressWarnings("unused") View view) {
// Intent intent = new Intent(this, DisplayActivity.class);
// EditText editText = (EditText) findViewById(R.id.sendtext_simple);
// intent.putExtra(EXTRA_DATA, editText.getText().toString());
// startActivity(intent);
// }
//
// public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
// TextView textView = (TextView) findViewById(R.id.spinnertext_simple);
// textView.setText(String.format("One %s a day!", parent.getItemAtPosition(pos)));
// }
//
// public void onNothingSelected(AdapterView<?> parent) {
// }
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/TestFixture.java
// public class TestFixture <T extends Activity> extends BaseInstrumentTestCase<T>{
//
// protected ActionBarModel ActionBarPage = new ActionBarModel();
// protected LongListModel LongListPage = new LongListModel();
// protected SimpleModel SimplePage = new SimpleModel();
// protected DrawerModel DrawerPage = new DrawerModel();
// protected DisplayModel DisplayPage = new DisplayModel();
// protected MenuModel MenuPage = new MenuModel();
// protected SendModel SendPage = new SendModel();
// protected ScrollModel ScrollPage = new ScrollModel();
// protected ViewPagerModel PagerPage = new ViewPagerModel();
// protected SyncModel SyncPage = new SyncModel();
// protected ZoomModel ZoomPage = new ZoomModel();
//
// public TestFixture(Class<T> activityClass) {
// super(activityClass);
// }
// }
//
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/models/SimpleModel.java
// public class SimpleModel extends PageObject {
//
// public Clickable<SimpleModel> SimpleButton = new Clickable<>(SimpleModel.class, R.id.button_simple);
//
// public Clickable<SimpleModel> SimpleText = new Clickable<>(SimpleModel.class, R.id.text_simple);
//
// public TextField<SimpleModel> SimpleSendText = new TextField<>(SimpleModel.class, R.id.sendtext_simple);
//
// public Clickable<DisplayModel> SimpleSend = new Clickable<>(DisplayModel.class, R.id.send_simple);
//
// public SpinnerView<SimpleModel> SimpleSpinner = new SpinnerView<>(SimpleModel.class, R.id.spinner_simple);
//
// public ListAdapter<SimpleModel> SpinnerList = new ListAdapter<>(SimpleModel.class, String.class);
// }
// Path: app/src/androidTest/java/com/mindbodyonline/ironhidetestapp/tests/BasicTest.java
import android.test.suitebuilder.annotation.LargeTest;
import com.mindbodyonline.ironhidetestapp.R;
import com.mindbodyonline.ironhidetestapp.SimpleActivity;
import com.mindbodyonline.ironhidetestapp.TestFixture;
import com.mindbodyonline.ironhidetestapp.models.SimpleModel;
import org.junit.Test;
package com.mindbodyonline.ironhidetestapp.tests;
/**
* Highlights basic
* {@link android.support.test.espresso.Espresso#onView(org.hamcrest.Matcher)}
* functionality.
*/
@LargeTest
public class BasicTest extends TestFixture<SimpleActivity> {
public BasicTest() {
super(SimpleActivity.class);
}
@Test
public void testSimpleClickAndCheckText() {
SimplePage
.SimpleButton.click()
.SimpleText.withText("Hello Espresso!")
;
}
@Test
public void testTypingAndPressBack() {
SimplePage
.SimpleSendText.typeText(R.string.hello_world)
.SimpleSendText.closeKeyboard()
.SimpleSend.click()
.displayText.withText(R.string.hello_world)
|
.displayText.goesTo(SimpleModel.class).pressBack()
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/29/2016.
*/
public class ClientService extends Service implements ClientSocketThread.ServiceCallback {
public static final String ACTION = "action";
public static final String DISCOVERY_REPLY = "reply";
public static final int NOTIFICATION_ID = 521;
// Keys for extras
public static final String PAYLOAD = "payload";
// Possible service actions:
public static final int DISCOVERY_REQUEST = 1;
public static final int SESSION_MESSAGE = 2;
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/29/2016.
*/
public class ClientService extends Service implements ClientSocketThread.ServiceCallback {
public static final String ACTION = "action";
public static final String DISCOVERY_REPLY = "reply";
public static final int NOTIFICATION_ID = 521;
// Keys for extras
public static final String PAYLOAD = "payload";
// Possible service actions:
public static final int DISCOVERY_REQUEST = 1;
public static final int SESSION_MESSAGE = 2;
|
private Payload<?> registerPayload;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/29/2016.
*/
public class ClientService extends Service implements ClientSocketThread.ServiceCallback {
public static final String ACTION = "action";
public static final String DISCOVERY_REPLY = "reply";
public static final int NOTIFICATION_ID = 521;
// Keys for extras
public static final String PAYLOAD = "payload";
// Possible service actions:
public static final int DISCOVERY_REQUEST = 1;
public static final int SESSION_MESSAGE = 2;
private Payload<?> registerPayload;
private ClientSocketThread clientSocketThread;
private SendHandler sendHandler;
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/29/2016.
*/
public class ClientService extends Service implements ClientSocketThread.ServiceCallback {
public static final String ACTION = "action";
public static final String DISCOVERY_REPLY = "reply";
public static final int NOTIFICATION_ID = 521;
// Keys for extras
public static final String PAYLOAD = "payload";
// Possible service actions:
public static final int DISCOVERY_REQUEST = 1;
public static final int SESSION_MESSAGE = 2;
private Payload<?> registerPayload;
private ClientSocketThread clientSocketThread;
private SendHandler sendHandler;
|
private DiscoveryReply reply;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
|
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
|
Thread t = new Thread(new SendHandler(new IncomingServerMessage(MessageType.REGISTER, message), reply.getIp(), reply.getPort()));
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
|
Thread t = new Thread(new SendHandler(new IncomingServerMessage(MessageType.REGISTER, message), reply.getIp(), reply.getPort()));
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
Thread t = new Thread(new SendHandler(new IncomingServerMessage(MessageType.REGISTER, message), reply.getIp(), reply.getPort()));
t.start();
}
@Override
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
public int onStartCommand(Intent intent, int flags, int startId) {
DiscoveryReply reply = (DiscoveryReply) intent.getSerializableExtra(DISCOVERY_REPLY);
if (reply != null) {
this.reply = reply;
}
int action = intent.getIntExtra(ACTION, 0);
processAction(action, intent);
return START_STICKY;
}
private void processAction(int action, Intent intent) {
if (action == 0)
return;
if (action == DISCOVERY_REQUEST)
registerPayload = (Payload<?>) intent.getSerializableExtra(PAYLOAD);
else if (action == SESSION_MESSAGE)
sendSessionMessage((Payload<?>) intent.getSerializableExtra(PAYLOAD));
}
@Override
public void onInitializedSocket(int port) {
RegisterMessage message = new RegisterMessage(registerPayload, getLocalIp(), port);
Thread t = new Thread(new SendHandler(new IncomingServerMessage(MessageType.REGISTER, message), reply.getIp(), reply.getPort()));
t.start();
}
@Override
|
public void onSessionMessage(SessionMessage message) {
|
itsJoKr/LocalNetwork
|
app/src/main/java/dev/jokr/localnetworkapp/GameSession.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
// public abstract class LocalSession {
//
// /*
// * Class that represent session of messaging between devices.
// * All session events (like sending or receiving a message) and logic connected to them
// * should be implemented here, not in Activity class or others.
// *
// *
// * Code here will be executed in service.
// *
// */
//
// // Communicator for interacting with running service
// private Communicator communicator;
//
// public LocalSession() {}
//
// /*
// * This method sends session message to specified recipient. Recipient will
// * receive message in their LocalClient instance.
// */
// public void sendMessage(long recipientId, Payload<?> payload) {
// communicator.sendMessage(recipientId, payload);
// }
//
// /*
// * This method is used to send message to all clients connected.
// */
// public void sendBroadcastMessage(Payload<?> payload) {
// communicator.sendBroadcastMessage(payload);
// }
//
// /*
// * Logic in this class is executed in service. If you want show some data on the UI, you can use
// * this method to send data to your Activity/Fragment or other classes.
// */
// public void sendUiEvent(Payload<?> payload) {
// communicator.sendUiEvent(payload);
// }
//
// /*
// * This method is used for setting communicator with running service. Called before onCreate.
// */
// public void preCreateInit(Communicator communicator) {
// this.communicator = communicator;
// }
//
// /*
// * This is where you should start your session logic. You receive bundle (if you set any from
// * Local Server) and connected clients.
// */
// public abstract void onCreate(Bundle bundle, ConnectedClients connectedClients);
//
// /*
// * In this method you will receive message sent from clients.
// */
// public abstract void onReceiveMessage(long recipientId, Payload payload);
//
// /*
// * You can send events from your UI (activities, fragments...) to LocalSession at any time.
// * You will receive data in this method.
// */
// public abstract void onEvent(Payload<?> payload);
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.os.Bundle;
import android.util.Log;
import dev.jokr.localnet.LocalSession;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnetworkapp;
/**
* Created by JoKr on 8/31/2016.
*/
public class GameSession extends LocalSession {
/*
* You extend LocalSession and put all your logic here. Check LocalSession class
* in library for more info.
*/
@Override
|
// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
// public abstract class LocalSession {
//
// /*
// * Class that represent session of messaging between devices.
// * All session events (like sending or receiving a message) and logic connected to them
// * should be implemented here, not in Activity class or others.
// *
// *
// * Code here will be executed in service.
// *
// */
//
// // Communicator for interacting with running service
// private Communicator communicator;
//
// public LocalSession() {}
//
// /*
// * This method sends session message to specified recipient. Recipient will
// * receive message in their LocalClient instance.
// */
// public void sendMessage(long recipientId, Payload<?> payload) {
// communicator.sendMessage(recipientId, payload);
// }
//
// /*
// * This method is used to send message to all clients connected.
// */
// public void sendBroadcastMessage(Payload<?> payload) {
// communicator.sendBroadcastMessage(payload);
// }
//
// /*
// * Logic in this class is executed in service. If you want show some data on the UI, you can use
// * this method to send data to your Activity/Fragment or other classes.
// */
// public void sendUiEvent(Payload<?> payload) {
// communicator.sendUiEvent(payload);
// }
//
// /*
// * This method is used for setting communicator with running service. Called before onCreate.
// */
// public void preCreateInit(Communicator communicator) {
// this.communicator = communicator;
// }
//
// /*
// * This is where you should start your session logic. You receive bundle (if you set any from
// * Local Server) and connected clients.
// */
// public abstract void onCreate(Bundle bundle, ConnectedClients connectedClients);
//
// /*
// * In this method you will receive message sent from clients.
// */
// public abstract void onReceiveMessage(long recipientId, Payload payload);
//
// /*
// * You can send events from your UI (activities, fragments...) to LocalSession at any time.
// * You will receive data in this method.
// */
// public abstract void onEvent(Payload<?> payload);
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: app/src/main/java/dev/jokr/localnetworkapp/GameSession.java
import android.os.Bundle;
import android.util.Log;
import dev.jokr.localnet.LocalSession;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnetworkapp;
/**
* Created by JoKr on 8/31/2016.
*/
public class GameSession extends LocalSession {
/*
* You extend LocalSession and put all your logic here. Check LocalSession class
* in library for more info.
*/
@Override
|
public void onCreate(Bundle bundle, ConnectedClients connectedClients){
|
itsJoKr/LocalNetwork
|
app/src/main/java/dev/jokr/localnetworkapp/GameSession.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
// public abstract class LocalSession {
//
// /*
// * Class that represent session of messaging between devices.
// * All session events (like sending or receiving a message) and logic connected to them
// * should be implemented here, not in Activity class or others.
// *
// *
// * Code here will be executed in service.
// *
// */
//
// // Communicator for interacting with running service
// private Communicator communicator;
//
// public LocalSession() {}
//
// /*
// * This method sends session message to specified recipient. Recipient will
// * receive message in their LocalClient instance.
// */
// public void sendMessage(long recipientId, Payload<?> payload) {
// communicator.sendMessage(recipientId, payload);
// }
//
// /*
// * This method is used to send message to all clients connected.
// */
// public void sendBroadcastMessage(Payload<?> payload) {
// communicator.sendBroadcastMessage(payload);
// }
//
// /*
// * Logic in this class is executed in service. If you want show some data on the UI, you can use
// * this method to send data to your Activity/Fragment or other classes.
// */
// public void sendUiEvent(Payload<?> payload) {
// communicator.sendUiEvent(payload);
// }
//
// /*
// * This method is used for setting communicator with running service. Called before onCreate.
// */
// public void preCreateInit(Communicator communicator) {
// this.communicator = communicator;
// }
//
// /*
// * This is where you should start your session logic. You receive bundle (if you set any from
// * Local Server) and connected clients.
// */
// public abstract void onCreate(Bundle bundle, ConnectedClients connectedClients);
//
// /*
// * In this method you will receive message sent from clients.
// */
// public abstract void onReceiveMessage(long recipientId, Payload payload);
//
// /*
// * You can send events from your UI (activities, fragments...) to LocalSession at any time.
// * You will receive data in this method.
// */
// public abstract void onEvent(Payload<?> payload);
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.os.Bundle;
import android.util.Log;
import dev.jokr.localnet.LocalSession;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnetworkapp;
/**
* Created by JoKr on 8/31/2016.
*/
public class GameSession extends LocalSession {
/*
* You extend LocalSession and put all your logic here. Check LocalSession class
* in library for more info.
*/
@Override
public void onCreate(Bundle bundle, ConnectedClients connectedClients){
Log.d("USER", "SESSION: onCreate");
// long id = (long) connectedClients.getAllClientsIds().toArray()[0];
// sendMessage(id, new Payload<MyMessage>(new ));
}
@Override
|
// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
// public abstract class LocalSession {
//
// /*
// * Class that represent session of messaging between devices.
// * All session events (like sending or receiving a message) and logic connected to them
// * should be implemented here, not in Activity class or others.
// *
// *
// * Code here will be executed in service.
// *
// */
//
// // Communicator for interacting with running service
// private Communicator communicator;
//
// public LocalSession() {}
//
// /*
// * This method sends session message to specified recipient. Recipient will
// * receive message in their LocalClient instance.
// */
// public void sendMessage(long recipientId, Payload<?> payload) {
// communicator.sendMessage(recipientId, payload);
// }
//
// /*
// * This method is used to send message to all clients connected.
// */
// public void sendBroadcastMessage(Payload<?> payload) {
// communicator.sendBroadcastMessage(payload);
// }
//
// /*
// * Logic in this class is executed in service. If you want show some data on the UI, you can use
// * this method to send data to your Activity/Fragment or other classes.
// */
// public void sendUiEvent(Payload<?> payload) {
// communicator.sendUiEvent(payload);
// }
//
// /*
// * This method is used for setting communicator with running service. Called before onCreate.
// */
// public void preCreateInit(Communicator communicator) {
// this.communicator = communicator;
// }
//
// /*
// * This is where you should start your session logic. You receive bundle (if you set any from
// * Local Server) and connected clients.
// */
// public abstract void onCreate(Bundle bundle, ConnectedClients connectedClients);
//
// /*
// * In this method you will receive message sent from clients.
// */
// public abstract void onReceiveMessage(long recipientId, Payload payload);
//
// /*
// * You can send events from your UI (activities, fragments...) to LocalSession at any time.
// * You will receive data in this method.
// */
// public abstract void onEvent(Payload<?> payload);
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: app/src/main/java/dev/jokr/localnetworkapp/GameSession.java
import android.os.Bundle;
import android.util.Log;
import dev.jokr.localnet.LocalSession;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnetworkapp;
/**
* Created by JoKr on 8/31/2016.
*/
public class GameSession extends LocalSession {
/*
* You extend LocalSession and put all your logic here. Check LocalSession class
* in library for more info.
*/
@Override
public void onCreate(Bundle bundle, ConnectedClients connectedClients){
Log.d("USER", "SESSION: onCreate");
// long id = (long) connectedClients.getAllClientsIds().toArray()[0];
// sendMessage(id, new Payload<MyMessage>(new ));
}
@Override
|
public void onReceiveMessage(long recipientId, Payload payload) {
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/DiscoverySocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class DiscoverySocketThread implements Runnable {
private DiscoveryReply reply;
private DatagramSocket socket;
public DiscoverySocketThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/DiscoverySocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class DiscoverySocketThread implements Runnable {
private DiscoveryReply reply;
private DatagramSocket socket;
public DiscoverySocketThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
|
int port = NetworkUtil.BASE_PORT;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/DiscoverySocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class DiscoverySocketThread implements Runnable {
private DiscoveryReply reply;
private DatagramSocket socket;
public DiscoverySocketThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
int port = NetworkUtil.BASE_PORT;
boolean portAvailable = false;
do {
if (NetworkUtil.available(port))
portAvailable = true;
else
port--;
} while (!portAvailable);
socket = new DatagramSocket(port, InetAddress.getByName("0.0.0.0"));
socket.setBroadcast(true);
while (true) {
// Receive broadcast packet
Log.d("USER", "Waiting for packet...");
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
// Send reply
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/DiscoverySocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class DiscoverySocketThread implements Runnable {
private DiscoveryReply reply;
private DatagramSocket socket;
public DiscoverySocketThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
int port = NetworkUtil.BASE_PORT;
boolean portAvailable = false;
do {
if (NetworkUtil.available(port))
portAvailable = true;
else
port--;
} while (!portAvailable);
socket = new DatagramSocket(port, InetAddress.getByName("0.0.0.0"));
socket.setBroadcast(true);
while (true) {
// Receive broadcast packet
Log.d("USER", "Waiting for packet...");
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
// Send reply
|
byte[] replyPacket = SerializationUtil.serialize(reply);
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalClient.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
// public class ClientJoinHandler implements Runnable {
//
// private DatagramSocket socket;
// private ServerDiscoveryCallback callback;
//
// public ClientJoinHandler(ServerDiscoveryCallback callback) {
// this.callback = callback;
// }
//
// @Override
// public void run() {
// try {
// socket = new DatagramSocket(0);
// socket.setBroadcast(true);
//
// // data is not important for braodcast discovery request
// byte[] sendData = "DISCOVER_ME".getBytes();
// InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
//
// int basePort = NetworkUtil.BASE_PORT;
// for (int i=0; i<5; i++) {
// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
// socket.send(sendPacket);
// Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
// }
// byte[] buffer = new byte[15000];
// DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
// socket.setSoTimeout(2500);
// socket.receive(receivePacket);
// Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
//
// byte[] bytes = receivePacket.getData();
// DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
// Log.d("USER", "Reply: " + reply.getIp() + ":" + reply.getPort());
// discoveryReply(reply);
// } catch (SocketTimeoutException e) {
// discoveryTimeout();
// } catch (SocketException e) {
// e.printStackTrace();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
// private void discoveryReply(final DiscoveryReply reply) {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscovered(reply);
// }
// });
// }
//
// private void discoveryTimeout() {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscoveryTimeout();
// }
// });
// }
//
// public interface ServerDiscoveryCallback {
// public void serverDiscovered(DiscoveryReply reply);
// public void serverDiscoveryTimeout();
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.discovery.ClientJoinHandler;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
public class LocalClient implements ClientJoinHandler.ServerDiscoveryCallback {
/*
* Class for local client.
*/
public static final String SESSION_MESSAGE = "session_message";
private Context context;
private MessageReceiver messageReceiver;
private DiscoveryStatusReceiver discoveryReceiver;
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
// public class ClientJoinHandler implements Runnable {
//
// private DatagramSocket socket;
// private ServerDiscoveryCallback callback;
//
// public ClientJoinHandler(ServerDiscoveryCallback callback) {
// this.callback = callback;
// }
//
// @Override
// public void run() {
// try {
// socket = new DatagramSocket(0);
// socket.setBroadcast(true);
//
// // data is not important for braodcast discovery request
// byte[] sendData = "DISCOVER_ME".getBytes();
// InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
//
// int basePort = NetworkUtil.BASE_PORT;
// for (int i=0; i<5; i++) {
// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
// socket.send(sendPacket);
// Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
// }
// byte[] buffer = new byte[15000];
// DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
// socket.setSoTimeout(2500);
// socket.receive(receivePacket);
// Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
//
// byte[] bytes = receivePacket.getData();
// DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
// Log.d("USER", "Reply: " + reply.getIp() + ":" + reply.getPort());
// discoveryReply(reply);
// } catch (SocketTimeoutException e) {
// discoveryTimeout();
// } catch (SocketException e) {
// e.printStackTrace();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
// private void discoveryReply(final DiscoveryReply reply) {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscovered(reply);
// }
// });
// }
//
// private void discoveryTimeout() {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscoveryTimeout();
// }
// });
// }
//
// public interface ServerDiscoveryCallback {
// public void serverDiscovered(DiscoveryReply reply);
// public void serverDiscoveryTimeout();
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalClient.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.discovery.ClientJoinHandler;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
public class LocalClient implements ClientJoinHandler.ServerDiscoveryCallback {
/*
* Class for local client.
*/
public static final String SESSION_MESSAGE = "session_message";
private Context context;
private MessageReceiver messageReceiver;
private DiscoveryStatusReceiver discoveryReceiver;
|
private Payload<?> registerPayload;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalClient.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
// public class ClientJoinHandler implements Runnable {
//
// private DatagramSocket socket;
// private ServerDiscoveryCallback callback;
//
// public ClientJoinHandler(ServerDiscoveryCallback callback) {
// this.callback = callback;
// }
//
// @Override
// public void run() {
// try {
// socket = new DatagramSocket(0);
// socket.setBroadcast(true);
//
// // data is not important for braodcast discovery request
// byte[] sendData = "DISCOVER_ME".getBytes();
// InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
//
// int basePort = NetworkUtil.BASE_PORT;
// for (int i=0; i<5; i++) {
// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
// socket.send(sendPacket);
// Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
// }
// byte[] buffer = new byte[15000];
// DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
// socket.setSoTimeout(2500);
// socket.receive(receivePacket);
// Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
//
// byte[] bytes = receivePacket.getData();
// DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
// Log.d("USER", "Reply: " + reply.getIp() + ":" + reply.getPort());
// discoveryReply(reply);
// } catch (SocketTimeoutException e) {
// discoveryTimeout();
// } catch (SocketException e) {
// e.printStackTrace();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
// private void discoveryReply(final DiscoveryReply reply) {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscovered(reply);
// }
// });
// }
//
// private void discoveryTimeout() {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscoveryTimeout();
// }
// });
// }
//
// public interface ServerDiscoveryCallback {
// public void serverDiscovered(DiscoveryReply reply);
// public void serverDiscoveryTimeout();
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.discovery.ClientJoinHandler;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
public void sendSessionMessage(Payload<?> payload) {
Intent i = new Intent(context, ClientService.class);
i.putExtra(ClientService.ACTION, ClientService.SESSION_MESSAGE);
i.putExtra(ClientService.PAYLOAD, payload);
context.startService(i);
}
/*
* Set interface implementation for receiving session messages from server
*/
public void setReceiver(MessageReceiver receiver) {
this.messageReceiver = receiver;
}
/*
* Set interface implementation for receiving discovery phase events
*/
public void setDiscoveryReceiver(DiscoveryStatusReceiver discoveryReceiver) {
this.discoveryReceiver = discoveryReceiver;
}
/*
* Stops the service
*/
public void shutdown() {
Intent i = new Intent(context, ClientService.class);
context.stopService(i);
}
@Override
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
// public class ClientJoinHandler implements Runnable {
//
// private DatagramSocket socket;
// private ServerDiscoveryCallback callback;
//
// public ClientJoinHandler(ServerDiscoveryCallback callback) {
// this.callback = callback;
// }
//
// @Override
// public void run() {
// try {
// socket = new DatagramSocket(0);
// socket.setBroadcast(true);
//
// // data is not important for braodcast discovery request
// byte[] sendData = "DISCOVER_ME".getBytes();
// InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
//
// int basePort = NetworkUtil.BASE_PORT;
// for (int i=0; i<5; i++) {
// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
// socket.send(sendPacket);
// Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
// }
// byte[] buffer = new byte[15000];
// DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
// socket.setSoTimeout(2500);
// socket.receive(receivePacket);
// Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
//
// byte[] bytes = receivePacket.getData();
// DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
// Log.d("USER", "Reply: " + reply.getIp() + ":" + reply.getPort());
// discoveryReply(reply);
// } catch (SocketTimeoutException e) {
// discoveryTimeout();
// } catch (SocketException e) {
// e.printStackTrace();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
// private void discoveryReply(final DiscoveryReply reply) {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscovered(reply);
// }
// });
// }
//
// private void discoveryTimeout() {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscoveryTimeout();
// }
// });
// }
//
// public interface ServerDiscoveryCallback {
// public void serverDiscovered(DiscoveryReply reply);
// public void serverDiscoveryTimeout();
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalClient.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.discovery.ClientJoinHandler;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
public void sendSessionMessage(Payload<?> payload) {
Intent i = new Intent(context, ClientService.class);
i.putExtra(ClientService.ACTION, ClientService.SESSION_MESSAGE);
i.putExtra(ClientService.PAYLOAD, payload);
context.startService(i);
}
/*
* Set interface implementation for receiving session messages from server
*/
public void setReceiver(MessageReceiver receiver) {
this.messageReceiver = receiver;
}
/*
* Set interface implementation for receiving discovery phase events
*/
public void setDiscoveryReceiver(DiscoveryStatusReceiver discoveryReceiver) {
this.discoveryReceiver = discoveryReceiver;
}
/*
* Stops the service
*/
public void shutdown() {
Intent i = new Intent(context, ClientService.class);
context.stopService(i);
}
@Override
|
public void serverDiscovered(DiscoveryReply reply) {
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalClient.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
// public class ClientJoinHandler implements Runnable {
//
// private DatagramSocket socket;
// private ServerDiscoveryCallback callback;
//
// public ClientJoinHandler(ServerDiscoveryCallback callback) {
// this.callback = callback;
// }
//
// @Override
// public void run() {
// try {
// socket = new DatagramSocket(0);
// socket.setBroadcast(true);
//
// // data is not important for braodcast discovery request
// byte[] sendData = "DISCOVER_ME".getBytes();
// InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
//
// int basePort = NetworkUtil.BASE_PORT;
// for (int i=0; i<5; i++) {
// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
// socket.send(sendPacket);
// Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
// }
// byte[] buffer = new byte[15000];
// DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
// socket.setSoTimeout(2500);
// socket.receive(receivePacket);
// Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
//
// byte[] bytes = receivePacket.getData();
// DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
// Log.d("USER", "Reply: " + reply.getIp() + ":" + reply.getPort());
// discoveryReply(reply);
// } catch (SocketTimeoutException e) {
// discoveryTimeout();
// } catch (SocketException e) {
// e.printStackTrace();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
// private void discoveryReply(final DiscoveryReply reply) {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscovered(reply);
// }
// });
// }
//
// private void discoveryTimeout() {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscoveryTimeout();
// }
// });
// }
//
// public interface ServerDiscoveryCallback {
// public void serverDiscovered(DiscoveryReply reply);
// public void serverDiscoveryTimeout();
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.discovery.ClientJoinHandler;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
context.stopService(i);
}
@Override
public void serverDiscovered(DiscoveryReply reply) {
if (discoveryReceiver != null)
discoveryReceiver.onServerDiscovered();
Intent i = new Intent(context, ClientService.class);
i.putExtra(ClientService.ACTION, ClientService.DISCOVERY_REQUEST);
i.putExtra(ClientService.PAYLOAD, registerPayload);
i.putExtra(ClientService.DISCOVERY_REPLY, reply);
context.startService(i);
}
@Override
public void serverDiscoveryTimeout() {
if (discoveryReceiver != null)
discoveryReceiver.onDiscoveryTimeout();
}
private void registerMessageBroadcastReceiver() {
BroadcastReceiver receiver = new MessageBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(SESSION_MESSAGE);
LocalBroadcastManager.getInstance(context).registerReceiver(receiver, intentFilter);
}
private class MessageBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
// public class ClientJoinHandler implements Runnable {
//
// private DatagramSocket socket;
// private ServerDiscoveryCallback callback;
//
// public ClientJoinHandler(ServerDiscoveryCallback callback) {
// this.callback = callback;
// }
//
// @Override
// public void run() {
// try {
// socket = new DatagramSocket(0);
// socket.setBroadcast(true);
//
// // data is not important for braodcast discovery request
// byte[] sendData = "DISCOVER_ME".getBytes();
// InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
//
// int basePort = NetworkUtil.BASE_PORT;
// for (int i=0; i<5; i++) {
// DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
// socket.send(sendPacket);
// Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
// }
// byte[] buffer = new byte[15000];
// DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
// socket.setSoTimeout(2500);
// socket.receive(receivePacket);
// Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
//
// byte[] bytes = receivePacket.getData();
// DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
// Log.d("USER", "Reply: " + reply.getIp() + ":" + reply.getPort());
// discoveryReply(reply);
// } catch (SocketTimeoutException e) {
// discoveryTimeout();
// } catch (SocketException e) {
// e.printStackTrace();
// } catch (UnknownHostException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//
//
// private void discoveryReply(final DiscoveryReply reply) {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscovered(reply);
// }
// });
// }
//
// private void discoveryTimeout() {
// new Handler(Looper.getMainLooper()).post(new Runnable() {
// @Override
// public void run() {
// callback.serverDiscoveryTimeout();
// }
// });
// }
//
// public interface ServerDiscoveryCallback {
// public void serverDiscovered(DiscoveryReply reply);
// public void serverDiscoveryTimeout();
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalClient.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.discovery.ClientJoinHandler;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
context.stopService(i);
}
@Override
public void serverDiscovered(DiscoveryReply reply) {
if (discoveryReceiver != null)
discoveryReceiver.onServerDiscovered();
Intent i = new Intent(context, ClientService.class);
i.putExtra(ClientService.ACTION, ClientService.DISCOVERY_REQUEST);
i.putExtra(ClientService.PAYLOAD, registerPayload);
i.putExtra(ClientService.DISCOVERY_REPLY, reply);
context.startService(i);
}
@Override
public void serverDiscoveryTimeout() {
if (discoveryReceiver != null)
discoveryReceiver.onDiscoveryTimeout();
}
private void registerMessageBroadcastReceiver() {
BroadcastReceiver receiver = new MessageBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(SESSION_MESSAGE);
LocalBroadcastManager.getInstance(context).registerReceiver(receiver, intentFilter);
}
private class MessageBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
|
SessionMessage message = (SessionMessage) intent.getExtras().getSerializable(SessionMessage.class.getName());
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
|
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
|
if (message.getType().equals(MessageType.REGISTER)) {
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
if (message.getType().equals(MessageType.REGISTER)) {
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
if (message.getType().equals(MessageType.REGISTER)) {
|
notifyClientConnected((RegisterMessage) message.getMessage());
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
if (message.getType().equals(MessageType.REGISTER)) {
notifyClientConnected((RegisterMessage) message.getMessage());
} else if (message.getType().equals(MessageType.SESSION)) {
InetSocketAddress adr = (InetSocketAddress) socket.getRemoteSocketAddress();
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/IncomingServerMessage.java
// public class IncomingServerMessage implements Serializable {
//
// private String type;
// private Object message;
//
// public IncomingServerMessage(String type, Object message) {
// this.type = type;
// this.message = message;
// }
//
// public String getType() {
// return type;
// }
//
// public Object getMessage() {
// return message;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/MessageType.java
// public class MessageType {
//
// public static final String REGISTER = "register";
// public static final String SESSION = "session";
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ServerSocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import dev.jokr.localnet.models.IncomingServerMessage;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.MessageType;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
class ServerSocketThread implements Runnable {
private ServiceCallback callback;
private Socket socket;
public ServerSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
Log.d("USER", "starting ServerSocket...");
final ServerSocket serverSocket = new ServerSocket(0);
notifySocketInitialized(serverSocket.getLocalPort());
while (true) {
socket = serverSocket.accept();
Log.d("USER", "ServerSocket :: got incomingMessage");
ObjectInputStream input = new ObjectInputStream(socket.getInputStream());
IncomingServerMessage message = (IncomingServerMessage) input.readObject();
if (message.getType().equals(MessageType.REGISTER)) {
notifyClientConnected((RegisterMessage) message.getMessage());
} else if (message.getType().equals(MessageType.SESSION)) {
InetSocketAddress adr = (InetSocketAddress) socket.getRemoteSocketAddress();
|
notifySessionMessage((SessionMessage) message.getMessage(), adr.getAddress().getHostAddress());
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/discovery/DiscoveryThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class DiscoveryThread implements Runnable {
private DatagramSocket socket;
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/DiscoveryThread.java
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class DiscoveryThread implements Runnable {
private DatagramSocket socket;
|
private DiscoveryReply reply;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/discovery/DiscoveryThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class DiscoveryThread implements Runnable {
private DatagramSocket socket;
private DiscoveryReply reply;
public DiscoveryThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/DiscoveryThread.java
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class DiscoveryThread implements Runnable {
private DatagramSocket socket;
private DiscoveryReply reply;
public DiscoveryThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
|
int port = NetworkUtil.BASE_PORT;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/discovery/DiscoveryThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class DiscoveryThread implements Runnable {
private DatagramSocket socket;
private DiscoveryReply reply;
public DiscoveryThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
int port = NetworkUtil.BASE_PORT;
do {
socket = new DatagramSocket(port, InetAddress.getByName("0.0.0.0"));
port--;
} while (socket == null);
socket.setBroadcast(true);
while (true) {
// Receive broadcast packet
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
// Send reply
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/DiscoveryThread.java
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class DiscoveryThread implements Runnable {
private DatagramSocket socket;
private DiscoveryReply reply;
public DiscoveryThread(DiscoveryReply reply) {
this.reply = reply;
}
@Override
public void run() {
try {
int port = NetworkUtil.BASE_PORT;
do {
socket = new DatagramSocket(port, InetAddress.getByName("0.0.0.0"));
port--;
} while (socket == null);
socket.setBroadcast(true);
while (true) {
// Receive broadcast packet
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
// Send reply
|
byte[] replyPacket = SerializationUtil.serialize(reply);
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ServerService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import android.util.Log;
import java.util.HashMap;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.NetworkUtil;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
public class ServerService extends Service implements ServerSocketThread.ServiceCallback, Communicator {
public static final String ACTION = "action";
public static final int NOTIFICATION_ID = 521;
// Keys for extras
public static final String CLASS = "class";
public static final String BUNDLE = "bundle";
public static final String PAYLOAD = "payload";
// Possible service actions:
public static final int START_SESSION = 1;
public static final int SESSION_EVENT = 2;
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ServerService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import android.util.Log;
import java.util.HashMap;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.NetworkUtil;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
public class ServerService extends Service implements ServerSocketThread.ServiceCallback, Communicator {
public static final String ACTION = "action";
public static final int NOTIFICATION_ID = 521;
// Keys for extras
public static final String CLASS = "class";
public static final String BUNDLE = "bundle";
public static final String PAYLOAD = "payload";
// Possible service actions:
public static final int START_SESSION = 1;
public static final int SESSION_EVENT = 2;
|
private HashMap<Long, RegisterMessage> registeredClients;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ServerService.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
|
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import android.util.Log;
import java.util.HashMap;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.NetworkUtil;
|
e.printStackTrace();
}
}
private void sendSessionStartMessage() {
SessionMessage message = new SessionMessage(null, SessionMessage.START);
for (RegisterMessage client : registeredClients.values()) {
Thread t = new Thread(new SendHandler(message, client.getIp(), client.getPort()));
t.start();
}
}
private void runServiceInForeground() {
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("LocalNet Session")
.setContentText("Session is currently running")
.setSmallIcon(R.drawable.ic_play_circle_filled_black_24dp)
.build();
startForeground(NOTIFICATION_ID, notification);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onInitializedSocket(int port) {
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ServerService.java
import android.app.Notification;
import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.NotificationCompat;
import android.text.format.Formatter;
import android.util.Log;
import java.util.HashMap;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
import dev.jokr.localnet.utils.NetworkUtil;
e.printStackTrace();
}
}
private void sendSessionStartMessage() {
SessionMessage message = new SessionMessage(null, SessionMessage.START);
for (RegisterMessage client : registeredClients.values()) {
Thread t = new Thread(new SendHandler(message, client.getIp(), client.getPort()));
t.start();
}
}
private void runServiceInForeground() {
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("LocalNet Session")
.setContentText("Session is currently running")
.setSmallIcon(R.drawable.ic_play_circle_filled_black_24dp)
.build();
startForeground(NOTIFICATION_ID, notification);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onInitializedSocket(int port) {
|
discoverySocketThread = new Thread(new DiscoverySocketThread(new DiscoveryReply(getLocalIp(), port)));
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalSession.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.os.Bundle;
import java.util.HashMap;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/30/2016.
*/
public abstract class LocalSession {
/*
* Class that represent session of messaging between devices.
* All session events (like sending or receiving a message) and logic connected to them
* should be implemented here, not in Activity class or others.
*
*
* Code here will be executed in service.
*
*/
// Communicator for interacting with running service
private Communicator communicator;
public LocalSession() {}
/*
* This method sends session message to specified recipient. Recipient will
* receive message in their LocalClient instance.
*/
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
import android.os.Bundle;
import java.util.HashMap;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/30/2016.
*/
public abstract class LocalSession {
/*
* Class that represent session of messaging between devices.
* All session events (like sending or receiving a message) and logic connected to them
* should be implemented here, not in Activity class or others.
*
*
* Code here will be executed in service.
*
*/
// Communicator for interacting with running service
private Communicator communicator;
public LocalSession() {}
/*
* This method sends session message to specified recipient. Recipient will
* receive message in their LocalClient instance.
*/
|
public void sendMessage(long recipientId, Payload<?> payload) {
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalSession.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.os.Bundle;
import java.util.HashMap;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/30/2016.
*/
public abstract class LocalSession {
/*
* Class that represent session of messaging between devices.
* All session events (like sending or receiving a message) and logic connected to them
* should be implemented here, not in Activity class or others.
*
*
* Code here will be executed in service.
*
*/
// Communicator for interacting with running service
private Communicator communicator;
public LocalSession() {}
/*
* This method sends session message to specified recipient. Recipient will
* receive message in their LocalClient instance.
*/
public void sendMessage(long recipientId, Payload<?> payload) {
communicator.sendMessage(recipientId, payload);
}
/*
* This method is used to send message to all clients connected.
*/
public void sendBroadcastMessage(Payload<?> payload) {
communicator.sendBroadcastMessage(payload);
}
/*
* Logic in this class is executed in service. If you want show some data on the UI, you can use
* this method to send data to your Activity/Fragment or other classes.
*/
public void sendUiEvent(Payload<?> payload) {
communicator.sendUiEvent(payload);
}
/*
* This method is used for setting communicator with running service. Called before onCreate.
*/
public void preCreateInit(Communicator communicator) {
this.communicator = communicator;
}
/*
* This is where you should start your session logic. You receive bundle (if you set any from
* Local Server) and connected clients.
*/
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/ConnectedClients.java
// public class ConnectedClients {
//
// private HashMap<Long, RegisterMessage> registeredClients;
//
// public ConnectedClients(HashMap<Long, RegisterMessage> registeredClients) {
// this.registeredClients = registeredClients;
// }
//
// public Payload<?> getPayload(int clientId) {
// if (registeredClients.containsKey(clientId))
// return registeredClients.get(clientId).getPayload();
// else
// return null;
// }
//
// public Set<Long> getAllClientsIds() {
// return registeredClients.keySet();
// }
//
// public int getClientsSize() {
// return registeredClients.size();
// }
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalSession.java
import android.os.Bundle;
import java.util.HashMap;
import dev.jokr.localnet.models.ConnectedClients;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/30/2016.
*/
public abstract class LocalSession {
/*
* Class that represent session of messaging between devices.
* All session events (like sending or receiving a message) and logic connected to them
* should be implemented here, not in Activity class or others.
*
*
* Code here will be executed in service.
*
*/
// Communicator for interacting with running service
private Communicator communicator;
public LocalSession() {}
/*
* This method sends session message to specified recipient. Recipient will
* receive message in their LocalClient instance.
*/
public void sendMessage(long recipientId, Payload<?> payload) {
communicator.sendMessage(recipientId, payload);
}
/*
* This method is used to send message to all clients connected.
*/
public void sendBroadcastMessage(Payload<?> payload) {
communicator.sendBroadcastMessage(payload);
}
/*
* Logic in this class is executed in service. If you want show some data on the UI, you can use
* this method to send data to your Activity/Fragment or other classes.
*/
public void sendUiEvent(Payload<?> payload) {
communicator.sendUiEvent(payload);
}
/*
* This method is used for setting communicator with running service. Called before onCreate.
*/
public void preCreateInit(Communicator communicator) {
this.communicator = communicator;
}
/*
* This is where you should start your session logic. You receive bundle (if you set any from
* Local Server) and connected clients.
*/
|
public abstract void onCreate(Bundle bundle, ConnectedClients connectedClients);
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class ClientJoinHandler implements Runnable {
private DatagramSocket socket;
private ServerDiscoveryCallback callback;
public ClientJoinHandler(ServerDiscoveryCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
socket = new DatagramSocket(0);
socket.setBroadcast(true);
// data is not important for braodcast discovery request
byte[] sendData = "DISCOVER_ME".getBytes();
InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class ClientJoinHandler implements Runnable {
private DatagramSocket socket;
private ServerDiscoveryCallback callback;
public ClientJoinHandler(ServerDiscoveryCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
socket = new DatagramSocket(0);
socket.setBroadcast(true);
// data is not important for braodcast discovery request
byte[] sendData = "DISCOVER_ME".getBytes();
InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
|
int basePort = NetworkUtil.BASE_PORT;
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class ClientJoinHandler implements Runnable {
private DatagramSocket socket;
private ServerDiscoveryCallback callback;
public ClientJoinHandler(ServerDiscoveryCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
socket = new DatagramSocket(0);
socket.setBroadcast(true);
// data is not important for braodcast discovery request
byte[] sendData = "DISCOVER_ME".getBytes();
InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
int basePort = NetworkUtil.BASE_PORT;
for (int i=0; i<5; i++) {
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
socket.send(sendPacket);
Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
}
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.setSoTimeout(2500);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
byte[] bytes = receivePacket.getData();
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class ClientJoinHandler implements Runnable {
private DatagramSocket socket;
private ServerDiscoveryCallback callback;
public ClientJoinHandler(ServerDiscoveryCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
socket = new DatagramSocket(0);
socket.setBroadcast(true);
// data is not important for braodcast discovery request
byte[] sendData = "DISCOVER_ME".getBytes();
InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
int basePort = NetworkUtil.BASE_PORT;
for (int i=0; i<5; i++) {
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
socket.send(sendPacket);
Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
}
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.setSoTimeout(2500);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
byte[] bytes = receivePacket.getData();
|
DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
|
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class ClientJoinHandler implements Runnable {
private DatagramSocket socket;
private ServerDiscoveryCallback callback;
public ClientJoinHandler(ServerDiscoveryCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
socket = new DatagramSocket(0);
socket.setBroadcast(true);
// data is not important for braodcast discovery request
byte[] sendData = "DISCOVER_ME".getBytes();
InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
int basePort = NetworkUtil.BASE_PORT;
for (int i=0; i<5; i++) {
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
socket.send(sendPacket);
Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
}
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.setSoTimeout(2500);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
byte[] bytes = receivePacket.getData();
|
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/models/DiscoveryReply.java
// public class DiscoveryReply implements Serializable {
//
// private String ip;
// private int port;
//
// public DiscoveryReply(String ip, int port) {
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/NetworkUtil.java
// public class NetworkUtil {
//
//
// // My favourite number. We need hardcoded port because we cannot broadcast over all ports
// public static final int BASE_PORT = 52100;
//
// /**
// * Checks to see if a specific port is available.
// *
// * @param port the port to check for availability
// */
// public static boolean available(int port) {
// ServerSocket ss = null;
// DatagramSocket ds = null;
// try {
// ss = new ServerSocket(port);
// ss.setReuseAddress(true);
// ds = new DatagramSocket(port);
// ds.setReuseAddress(true);
// return true;
// } catch (IOException e) {
// } finally {
// if (ds != null) {
// ds.close();
// }
//
// if (ss != null) {
// try {
// ss.close();
// } catch (IOException e) {
// /* should not be thrown */
// }
// }
// }
//
// return false;
// }
//
//
// public static long getIdFromIpAddress(String ipAddr) {
// int[] ip = new int[4];
// String[] parts = ipAddr.split("\\.");
//
// for (int i = 0; i < 4; i++) {
// ip[i] = Integer.parseInt(parts[i]);
// }
//
// long ipNumbers = 0;
// for (int i = 0; i < 4; i++) {
// ipNumbers += ip[i] << (24 - (8 * i));
// }
//
// return ipNumbers;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/utils/SerializationUtil.java
// public class SerializationUtil {
//
// public static byte[] serialize(Object o) {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// ObjectOutput out = null;
// byte[] bytes = null;
// try {
// out = new ObjectOutputStream(bos);
// out.writeObject(o);
// bytes = bos.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// if (out != null) {
// out.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// bos.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return bytes;
// }
//
// public static Object deserialize(byte[] bytes) {
// ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
// ObjectInput in = null;
// Object o = null;
// try {
// in = new ObjectInputStream(bis);
// o = in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// bis.close();
// } catch (IOException ex) {
// // ignore close exception
// }
// try {
// if (in != null) {
// in.close();
// }
// } catch (IOException ex) {
// // ignore close exception
// }
// }
// return o;
// }
//
// }
// Path: localnet/src/main/java/dev/jokr/localnet/discovery/ClientJoinHandler.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import dev.jokr.localnet.discovery.models.DiscoveryReply;
import dev.jokr.localnet.utils.NetworkUtil;
import dev.jokr.localnet.utils.SerializationUtil;
package dev.jokr.localnet.discovery;
/**
* Created by JoKr on 8/27/2016.
*/
public class ClientJoinHandler implements Runnable {
private DatagramSocket socket;
private ServerDiscoveryCallback callback;
public ClientJoinHandler(ServerDiscoveryCallback callback) {
this.callback = callback;
}
@Override
public void run() {
try {
socket = new DatagramSocket(0);
socket.setBroadcast(true);
// data is not important for braodcast discovery request
byte[] sendData = "DISCOVER_ME".getBytes();
InetAddress broadcastAddr = InetAddress.getByName("255.255.255.255");
int basePort = NetworkUtil.BASE_PORT;
for (int i=0; i<5; i++) {
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcastAddr, basePort-i);
socket.send(sendPacket);
Log.d("USER", "Packet sent to 255.255.255.255:" + (basePort-i));
}
byte[] buffer = new byte[15000];
DatagramPacket receivePacket = new DatagramPacket(buffer, buffer.length);
socket.setSoTimeout(2500);
socket.receive(receivePacket);
Log.d("USER", "Received packet from: " + receivePacket.getAddress().getHostAddress());
byte[] bytes = receivePacket.getData();
|
DiscoveryReply reply = (DiscoveryReply) SerializationUtil.deserialize(bytes);
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/ClientSocketThread.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/29/2016.
*/
class ClientSocketThread implements Runnable {
private ServiceCallback callback;
public ClientSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(0);
} catch (IOException e) {
e.printStackTrace();
}
Log.d("USER", "Listening on " + serverSocket.getLocalPort());
notifySocketInitialized(serverSocket.getLocalPort());
while(true) {
try {
Socket socket = serverSocket.accept();
ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/ClientSocketThread.java
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/29/2016.
*/
class ClientSocketThread implements Runnable {
private ServiceCallback callback;
public ClientSocketThread(ServiceCallback callback) {
this.callback = callback;
}
@Override
public void run() {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(0);
} catch (IOException e) {
e.printStackTrace();
}
Log.d("USER", "Listening on " + serverSocket.getLocalPort());
notifySocketInitialized(serverSocket.getLocalPort());
while(true) {
try {
Socket socket = serverSocket.accept();
ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
|
SessionMessage sessionMessage = (SessionMessage) objectInputStream.readObject();
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalServer.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
|
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
public class LocalServer {
/*
* Class for local server. You need one device to act as a server.
* With init() server is started in discovery mode.
* To end discovery mode and start session, call setSession(Class c). You will need to pass
* implementation abstract class LocalSession which is main class for running session logic.
*/
public static final String UI_EVENT = "ui_event";
public static final String CONNECTED_CLIENT = "conn_client";
private Context context;
private OnUiEventReceiver receiver;
public LocalServer(Context context) {
this.context = context;
registerMessageBroadcastReceiver();
}
/*
* This method will start server in discovery mode. Clients can join using LocalClient.
*/
public void init() {
Intent i = new Intent(context, ServerService.class);
context.startService(i);
}
/*
* This method is used to end discovery mode and start session. It receives instance of
* LocalSession class as a Class parameter.
* LocalServer will instantiate it in service and call onCreate method in it.
*/
public void setSession(Class c) {
sendSessionData(c, null);
}
/*
* Same as setSession, but as you can't use constructor, you can use this class to pass bundle
* of arguments to your LocalSession implementation. You will receive this bundle in onCreate
* in your LocalSession implementation.
*/
public void setSession(Class c, Bundle b) {
sendSessionData(c, b);
}
/*
* This will stop service. Make sure not to call anything on this class after shutdown.
*/
public void shutdown() {
Intent i = new Intent(context, ServerService.class);
context.stopService(i);
// i.putExtra(ServerService.ACTION, ServerService.STOP);
// context.startService(i);
}
/*
* This method is used to send data to your LocalSession implementation.
*/
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalServer.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
package dev.jokr.localnet;
/**
* Created by JoKr on 8/28/2016.
*/
public class LocalServer {
/*
* Class for local server. You need one device to act as a server.
* With init() server is started in discovery mode.
* To end discovery mode and start session, call setSession(Class c). You will need to pass
* implementation abstract class LocalSession which is main class for running session logic.
*/
public static final String UI_EVENT = "ui_event";
public static final String CONNECTED_CLIENT = "conn_client";
private Context context;
private OnUiEventReceiver receiver;
public LocalServer(Context context) {
this.context = context;
registerMessageBroadcastReceiver();
}
/*
* This method will start server in discovery mode. Clients can join using LocalClient.
*/
public void init() {
Intent i = new Intent(context, ServerService.class);
context.startService(i);
}
/*
* This method is used to end discovery mode and start session. It receives instance of
* LocalSession class as a Class parameter.
* LocalServer will instantiate it in service and call onCreate method in it.
*/
public void setSession(Class c) {
sendSessionData(c, null);
}
/*
* Same as setSession, but as you can't use constructor, you can use this class to pass bundle
* of arguments to your LocalSession implementation. You will receive this bundle in onCreate
* in your LocalSession implementation.
*/
public void setSession(Class c, Bundle b) {
sendSessionData(c, b);
}
/*
* This will stop service. Make sure not to call anything on this class after shutdown.
*/
public void shutdown() {
Intent i = new Intent(context, ServerService.class);
context.stopService(i);
// i.putExtra(ServerService.ACTION, ServerService.STOP);
// context.startService(i);
}
/*
* This method is used to send data to your LocalSession implementation.
*/
|
public void sendLocalSessionEvent(Payload<?> payload) {
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalServer.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
|
* Set receiver if you want to receive events from LocalSession and be notified about
* new client connections.
*/
public void setReceiver(OnUiEventReceiver receiver) {
this.receiver = receiver;
}
private void sendSessionData(Class c, Bundle b) {
Intent i = new Intent(context, ServerService.class);
i.putExtra(ServerService.ACTION, ServerService.START_SESSION);
i.putExtra(ServerService.CLASS, c);
i.putExtra(ServerService.BUNDLE, b);
context.startService(i);
}
private void registerMessageBroadcastReceiver() {
BroadcastReceiver messageReceiver = new EventBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(UI_EVENT);
LocalBroadcastManager.getInstance(context).registerReceiver(messageReceiver, intentFilter);
BroadcastReceiver connectedClientReceiver = new ConnectedClientBroadcastReceiver();
IntentFilter intentFilter2 = new IntentFilter();
intentFilter2.addAction(CONNECTED_CLIENT);
LocalBroadcastManager.getInstance(context).registerReceiver(connectedClientReceiver, intentFilter2);
}
private class EventBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalServer.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
* Set receiver if you want to receive events from LocalSession and be notified about
* new client connections.
*/
public void setReceiver(OnUiEventReceiver receiver) {
this.receiver = receiver;
}
private void sendSessionData(Class c, Bundle b) {
Intent i = new Intent(context, ServerService.class);
i.putExtra(ServerService.ACTION, ServerService.START_SESSION);
i.putExtra(ServerService.CLASS, c);
i.putExtra(ServerService.BUNDLE, b);
context.startService(i);
}
private void registerMessageBroadcastReceiver() {
BroadcastReceiver messageReceiver = new EventBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(UI_EVENT);
LocalBroadcastManager.getInstance(context).registerReceiver(messageReceiver, intentFilter);
BroadcastReceiver connectedClientReceiver = new ConnectedClientBroadcastReceiver();
IntentFilter intentFilter2 = new IntentFilter();
intentFilter2.addAction(CONNECTED_CLIENT);
LocalBroadcastManager.getInstance(context).registerReceiver(connectedClientReceiver, intentFilter2);
}
private class EventBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
|
SessionMessage message = (SessionMessage) intent.getExtras().getSerializable(SessionMessage.class.getName());
|
itsJoKr/LocalNetwork
|
localnet/src/main/java/dev/jokr/localnet/LocalServer.java
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
|
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
|
i.putExtra(ServerService.CLASS, c);
i.putExtra(ServerService.BUNDLE, b);
context.startService(i);
}
private void registerMessageBroadcastReceiver() {
BroadcastReceiver messageReceiver = new EventBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(UI_EVENT);
LocalBroadcastManager.getInstance(context).registerReceiver(messageReceiver, intentFilter);
BroadcastReceiver connectedClientReceiver = new ConnectedClientBroadcastReceiver();
IntentFilter intentFilter2 = new IntentFilter();
intentFilter2.addAction(CONNECTED_CLIENT);
LocalBroadcastManager.getInstance(context).registerReceiver(connectedClientReceiver, intentFilter2);
}
private class EventBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SessionMessage message = (SessionMessage) intent.getExtras().getSerializable(SessionMessage.class.getName());
if (receiver != null) {
receiver.onUiEvent(message.getPayload());
}
}
}
private class ConnectedClientBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
|
// Path: localnet/src/main/java/dev/jokr/localnet/models/Payload.java
// public class Payload<T> implements Serializable {
//
// private T payload;
//
// public Payload(T payload) {
// this.payload = payload;
// }
//
// public T getPayload() {
// return payload;
// }
//
//
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/RegisterMessage.java
// public class RegisterMessage implements Serializable {
//
// private Payload<?> payload;
// private String ip;
// private int port;
//
// public RegisterMessage(Payload<?> payload, String ip, int port) {
// this.payload = payload;
// this.ip = ip;
// this.port = port;
// }
//
// public String getIp() {
// return ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
//
// Path: localnet/src/main/java/dev/jokr/localnet/models/SessionMessage.java
// public class SessionMessage implements Serializable {
//
// public static final int NONE = 0;
// public static final int START = 1;
// public static final int END = 2;
//
// private Payload<?> payload;
// private int signal;
//
//
// public SessionMessage(Payload<?> payload) {
// this.payload = payload;
// this.signal = NONE;
// }
//
// public SessionMessage(Payload<?> payload, int signal) {
// this.payload = payload;
// this.signal = signal;
// }
//
// public int getSignal() {
// return signal;
// }
//
// public Payload<?> getPayload() {
// return payload;
// }
// }
// Path: localnet/src/main/java/dev/jokr/localnet/LocalServer.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import dev.jokr.localnet.models.Payload;
import dev.jokr.localnet.models.RegisterMessage;
import dev.jokr.localnet.models.SessionMessage;
i.putExtra(ServerService.CLASS, c);
i.putExtra(ServerService.BUNDLE, b);
context.startService(i);
}
private void registerMessageBroadcastReceiver() {
BroadcastReceiver messageReceiver = new EventBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(UI_EVENT);
LocalBroadcastManager.getInstance(context).registerReceiver(messageReceiver, intentFilter);
BroadcastReceiver connectedClientReceiver = new ConnectedClientBroadcastReceiver();
IntentFilter intentFilter2 = new IntentFilter();
intentFilter2.addAction(CONNECTED_CLIENT);
LocalBroadcastManager.getInstance(context).registerReceiver(connectedClientReceiver, intentFilter2);
}
private class EventBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SessionMessage message = (SessionMessage) intent.getExtras().getSerializable(SessionMessage.class.getName());
if (receiver != null) {
receiver.onUiEvent(message.getPayload());
}
}
}
private class ConnectedClientBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
|
RegisterMessage message = (RegisterMessage) intent.getExtras().getSerializable(RegisterMessage.class.getName());
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/item/ItemDummyPickAxe.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/RegistryEntries.java
// public class RegistryEntries {
//
// @ObjectHolder("integratedtunnels:part_interface_item")
// public static final Item ITEM_PART_INTERFACE = null;
// @ObjectHolder("integratedtunnels:dummy_pickaxe")
// public static final Item ITEM_DUMMY_PICKAXE = null;
//
// @ObjectHolder("integratedtunnels:part_interface_settings")
// public static final ContainerType<ContainerInterfaceSettings> CONTAINER_INTERFACE_SETTINGS = null;
//
// }
|
import com.google.common.collect.Maps;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTier;
import net.minecraft.item.ToolItem;
import org.cyclops.integratedtunnels.RegistryEntries;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
|
package org.cyclops.integratedtunnels.item;
/**
* A dummy pickaxe that can harvest everything.
* @author rubensworks
*/
public class ItemDummyPickAxe extends ToolItem {
private static final Map<EnchantmentData, ItemStack> ITEMSTACKS = Maps.newHashMap();
public ItemDummyPickAxe(Item.Properties properties) {
super(1000, 1000, ItemTier.DIAMOND, Collections.emptySet(), properties);
}
@Override
public boolean canHarvestBlock(BlockState blockIn) {
return true;
}
@Override
public boolean canHarvestBlock(ItemStack stack, BlockState state) {
return true;
}
public static ItemStack getItemStack(boolean silkTouch, int fortune) {
EnchantmentData data = new EnchantmentData(silkTouch, fortune);
return ITEMSTACKS.computeIfAbsent(data, (key) -> {
|
// Path: src/main/java/org/cyclops/integratedtunnels/RegistryEntries.java
// public class RegistryEntries {
//
// @ObjectHolder("integratedtunnels:part_interface_item")
// public static final Item ITEM_PART_INTERFACE = null;
// @ObjectHolder("integratedtunnels:dummy_pickaxe")
// public static final Item ITEM_DUMMY_PICKAXE = null;
//
// @ObjectHolder("integratedtunnels:part_interface_settings")
// public static final ContainerType<ContainerInterfaceSettings> CONTAINER_INTERFACE_SETTINGS = null;
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/item/ItemDummyPickAxe.java
import com.google.common.collect.Maps;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTier;
import net.minecraft.item.ToolItem;
import org.cyclops.integratedtunnels.RegistryEntries;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
package org.cyclops.integratedtunnels.item;
/**
* A dummy pickaxe that can harvest everything.
* @author rubensworks
*/
public class ItemDummyPickAxe extends ToolItem {
private static final Map<EnchantmentData, ItemStack> ITEMSTACKS = Maps.newHashMap();
public ItemDummyPickAxe(Item.Properties properties) {
super(1000, 1000, ItemTier.DIAMOND, Collections.emptySet(), properties);
}
@Override
public boolean canHarvestBlock(BlockState blockIn) {
return true;
}
@Override
public boolean canHarvestBlock(ItemStack stack, BlockState state) {
return true;
}
public static ItemStack getItemStack(boolean silkTouch, int fortune) {
EnchantmentData data = new EnchantmentData(silkTouch, fortune);
return ITEMSTACKS.computeIfAbsent(data, (key) -> {
|
ItemStack itemStack = new ItemStack(RegistryEntries.ITEM_DUMMY_PICKAXE, 1);
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetStorage.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetStorage extends ChanneledTarget<IItemNetwork, ItemStack> implements IItemTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<ItemStack, Integer> storage;
private final int slot;
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetStorage.java
import net.minecraft.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetStorage extends ChanneledTarget<IItemNetwork, ItemStack> implements IItemTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<ItemStack, Integer> storage;
private final int slot;
|
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetStorage.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetStorage extends ChanneledTarget<IItemNetwork, ItemStack> implements IItemTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<ItemStack, Integer> storage;
private final int slot;
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public ItemTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<ItemStack, Integer> storage, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetStorage.java
import net.minecraft.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetStorage extends ChanneledTarget<IItemNetwork, ItemStack> implements IItemTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<ItemStack, Integer> storage;
private final int slot;
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public ItemTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<ItemStack, Integer> storage, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
|
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetStorage.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetStorage extends ChanneledTarget<IItemNetwork, ItemStack> implements IItemTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<ItemStack, Integer> storage;
private final int slot;
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public ItemTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<ItemStack, Integer> storage, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetStorage.java
import net.minecraft.item.ItemStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetStorage extends ChanneledTarget<IItemNetwork, ItemStack> implements IItemTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<ItemStack, Integer> storage;
private final int slot;
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public ItemTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<ItemStack, Integer> storage, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
super(network, network.getCapability(ItemNetworkConfig.CAPABILITY).orElse(null), partState,
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/operator/PositionedOperatorIngredientIndexItem.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
|
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import org.cyclops.cyclopscore.datastructure.DimPos;
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeLong;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
|
package org.cyclops.integratedtunnels.part.aspect.operator;
/**
* @author rubensworks
*/
public class PositionedOperatorIngredientIndexItem extends PositionedOperatorIngredientIndex<ItemStack, Integer> {
public PositionedOperatorIngredientIndexItem(DimPos pos, Direction side, int channel) {
super("countbyitem", new Function(), ValueTypes.OBJECT_ITEMSTACK, ValueTypes.LONG, pos, side, channel);
}
@Override
protected Capability<? extends IPositionedAddonsNetworkIngredients<ItemStack, Integer>> getNetworkCapability() {
|
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/operator/PositionedOperatorIngredientIndexItem.java
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import org.cyclops.cyclopscore.datastructure.DimPos;
import org.cyclops.integrateddynamics.api.evaluate.EvaluationException;
import org.cyclops.integrateddynamics.api.evaluate.variable.IValue;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeLong;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypes;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
package org.cyclops.integratedtunnels.part.aspect.operator;
/**
* @author rubensworks
*/
public class PositionedOperatorIngredientIndexItem extends PositionedOperatorIngredientIndex<ItemStack, Integer> {
public PositionedOperatorIngredientIndexItem(DimPos pos, Direction side, int channel) {
super("countbyitem", new Function(), ValueTypes.OBJECT_ITEMSTACK, ValueTypes.LONG, pos, side, channel);
}
@Override
protected Capability<? extends IPositionedAddonsNetworkIngredients<ItemStack, Integer>> getNetworkCapability() {
|
return ItemNetworkConfig.CAPABILITY;
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/capability/network/TunnelNetworkCapabilityConstructors.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/FluidNetwork.java
// public class FluidNetwork extends PositionedAddonsNetworkIngredients<FluidStack, Integer> implements IFluidNetwork {
//
// public FluidNetwork(IngredientComponent<FluidStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return GeneralConfig.fluidRateLimit;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/ItemNetwork.java
// public class ItemNetwork extends PositionedAddonsNetworkIngredients<ItemStack, Integer> implements IItemNetwork {
//
// public ItemNetwork(IngredientComponent<ItemStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return 64;
// }
// }
|
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.api.network.AttachCapabilitiesEventNetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integratedtunnels.core.network.FluidNetwork;
import org.cyclops.integratedtunnels.core.network.ItemNetwork;
|
package org.cyclops.integratedtunnels.capability.network;
/**
* Constructor event for network capabilities.
* @author rubensworks
*/
public class TunnelNetworkCapabilityConstructors {
@SubscribeEvent
public void onNetworkLoad(AttachCapabilitiesEventNetwork event) {
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/FluidNetwork.java
// public class FluidNetwork extends PositionedAddonsNetworkIngredients<FluidStack, Integer> implements IFluidNetwork {
//
// public FluidNetwork(IngredientComponent<FluidStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return GeneralConfig.fluidRateLimit;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/ItemNetwork.java
// public class ItemNetwork extends PositionedAddonsNetworkIngredients<ItemStack, Integer> implements IItemNetwork {
//
// public ItemNetwork(IngredientComponent<ItemStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return 64;
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/TunnelNetworkCapabilityConstructors.java
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.api.network.AttachCapabilitiesEventNetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integratedtunnels.core.network.FluidNetwork;
import org.cyclops.integratedtunnels.core.network.ItemNetwork;
package org.cyclops.integratedtunnels.capability.network;
/**
* Constructor event for network capabilities.
* @author rubensworks
*/
public class TunnelNetworkCapabilityConstructors {
@SubscribeEvent
public void onNetworkLoad(AttachCapabilitiesEventNetwork event) {
|
ItemNetwork itemNetwork = new ItemNetwork(IngredientComponent.ITEMSTACK);
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/capability/network/TunnelNetworkCapabilityConstructors.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/FluidNetwork.java
// public class FluidNetwork extends PositionedAddonsNetworkIngredients<FluidStack, Integer> implements IFluidNetwork {
//
// public FluidNetwork(IngredientComponent<FluidStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return GeneralConfig.fluidRateLimit;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/ItemNetwork.java
// public class ItemNetwork extends PositionedAddonsNetworkIngredients<ItemStack, Integer> implements IItemNetwork {
//
// public ItemNetwork(IngredientComponent<ItemStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return 64;
// }
// }
|
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.api.network.AttachCapabilitiesEventNetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integratedtunnels.core.network.FluidNetwork;
import org.cyclops.integratedtunnels.core.network.ItemNetwork;
|
package org.cyclops.integratedtunnels.capability.network;
/**
* Constructor event for network capabilities.
* @author rubensworks
*/
public class TunnelNetworkCapabilityConstructors {
@SubscribeEvent
public void onNetworkLoad(AttachCapabilitiesEventNetwork event) {
ItemNetwork itemNetwork = new ItemNetwork(IngredientComponent.ITEMSTACK);
IItemHandler itemHandler = itemNetwork.getChannelExternal(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
IPositionedAddonsNetworkIngredients.DEFAULT_CHANNEL);
event.addCapability(new ResourceLocation(Reference.MOD_ID, "item_network"),
new DefaultCapabilityProvider<>(() -> ItemNetworkConfig.CAPABILITY, itemNetwork));
event.addCapability(new ResourceLocation(Reference.MOD_ID, "item_storage_network"),
new DefaultCapabilityProvider<>(() -> CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, itemHandler));
event.addFullNetworkListener(itemNetwork);
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/FluidNetwork.java
// public class FluidNetwork extends PositionedAddonsNetworkIngredients<FluidStack, Integer> implements IFluidNetwork {
//
// public FluidNetwork(IngredientComponent<FluidStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return GeneralConfig.fluidRateLimit;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/ItemNetwork.java
// public class ItemNetwork extends PositionedAddonsNetworkIngredients<ItemStack, Integer> implements IItemNetwork {
//
// public ItemNetwork(IngredientComponent<ItemStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return 64;
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/TunnelNetworkCapabilityConstructors.java
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.api.network.AttachCapabilitiesEventNetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetworkIngredients;
import org.cyclops.integratedtunnels.core.network.FluidNetwork;
import org.cyclops.integratedtunnels.core.network.ItemNetwork;
package org.cyclops.integratedtunnels.capability.network;
/**
* Constructor event for network capabilities.
* @author rubensworks
*/
public class TunnelNetworkCapabilityConstructors {
@SubscribeEvent
public void onNetworkLoad(AttachCapabilitiesEventNetwork event) {
ItemNetwork itemNetwork = new ItemNetwork(IngredientComponent.ITEMSTACK);
IItemHandler itemHandler = itemNetwork.getChannelExternal(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY,
IPositionedAddonsNetworkIngredients.DEFAULT_CHANNEL);
event.addCapability(new ResourceLocation(Reference.MOD_ID, "item_network"),
new DefaultCapabilityProvider<>(() -> ItemNetworkConfig.CAPABILITY, itemNetwork));
event.addCapability(new ResourceLocation(Reference.MOD_ID, "item_storage_network"),
new DefaultCapabilityProvider<>(() -> CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, itemHandler));
event.addFullNetworkListener(itemNetwork);
|
FluidNetwork fluidNetwork = new FluidNetwork(IngredientComponent.FLUIDSTACK);
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/Capabilities.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
|
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.cyclops.commoncapabilities.api.capability.inventorystate.IInventoryState;
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
import org.cyclops.integrateddynamics.api.network.IEnergyNetwork;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
|
package org.cyclops.integratedtunnels;
/**
* Used capabilities for this mod.
* @author rubensworks
*/
public class Capabilities {
@CapabilityInject(IEnergyNetwork.class)
public static Capability<IEnergyNetwork> NETWORK_ENERGY = null;
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/Capabilities.java
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.cyclops.commoncapabilities.api.capability.inventorystate.IInventoryState;
import org.cyclops.commoncapabilities.api.capability.itemhandler.ISlotlessItemHandler;
import org.cyclops.integrateddynamics.api.network.IEnergyNetwork;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
package org.cyclops.integratedtunnels;
/**
* Used capabilities for this mod.
* @author rubensworks
*/
public class Capabilities {
@CapabilityInject(IEnergyNetwork.class)
public static Capability<IEnergyNetwork> NETWORK_ENERGY = null;
|
@CapabilityInject(IFluidNetwork.class)
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/listproxy/TunnelValueTypeListProxyFactories.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/Reference.java
// @SuppressWarnings("javadoc")
// public class Reference {
//
// // Mod info
// public static final String MOD_ID = "integratedtunnels";
// public static final String GA_TRACKING_ID = "UA-65307010-10";
// public static final String VERSION_URL = "https://raw.githubusercontent.com/CyclopsMC/Versions/master/" + MinecraftHelpers.getMinecraftVersionMajorMinor() + "/IntegratedTunnels.txt";
//
// // MOD ID's
// public static final String MOD_FORGE = "forge";
// public static final String MOD_CYCLOPSCORE = "cyclopscore";
// public static final String MOD_INTEGRATEDDYNAMICS = "integrateddynamics";
// }
|
import net.minecraft.util.ResourceLocation;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeFluidStack;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeListProxyFactories;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeListProxyNBTFactory;
import org.cyclops.integratedtunnels.Reference;
|
package org.cyclops.integratedtunnels.part.aspect.listproxy;
/**
* @author rubensworks
*/
public class TunnelValueTypeListProxyFactories {
public static ValueTypeListProxyNBTFactory<ValueObjectTypeItemStack, ValueObjectTypeItemStack.ValueItemStack, ValueTypeListProxyPositionedItemNetwork> POSITIONED_ITEM_NETWORK;
public static ValueTypeListProxyNBTFactory<ValueObjectTypeFluidStack, ValueObjectTypeFluidStack.ValueFluidStack, ValueTypeListProxyPositionedFluidNetwork> POSITIONED_FLUID_NETWORK;
public static void load() {
if (POSITIONED_ITEM_NETWORK == null) {
POSITIONED_ITEM_NETWORK = ValueTypeListProxyFactories.REGISTRY.register(new ValueTypeListProxyNBTFactory<>(
|
// Path: src/main/java/org/cyclops/integratedtunnels/Reference.java
// @SuppressWarnings("javadoc")
// public class Reference {
//
// // Mod info
// public static final String MOD_ID = "integratedtunnels";
// public static final String GA_TRACKING_ID = "UA-65307010-10";
// public static final String VERSION_URL = "https://raw.githubusercontent.com/CyclopsMC/Versions/master/" + MinecraftHelpers.getMinecraftVersionMajorMinor() + "/IntegratedTunnels.txt";
//
// // MOD ID's
// public static final String MOD_FORGE = "forge";
// public static final String MOD_CYCLOPSCORE = "cyclopscore";
// public static final String MOD_INTEGRATEDDYNAMICS = "integrateddynamics";
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/listproxy/TunnelValueTypeListProxyFactories.java
import net.minecraft.util.ResourceLocation;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeFluidStack;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeListProxyFactories;
import org.cyclops.integrateddynamics.core.evaluate.variable.ValueTypeListProxyNBTFactory;
import org.cyclops.integratedtunnels.Reference;
package org.cyclops.integratedtunnels.part.aspect.listproxy;
/**
* @author rubensworks
*/
public class TunnelValueTypeListProxyFactories {
public static ValueTypeListProxyNBTFactory<ValueObjectTypeItemStack, ValueObjectTypeItemStack.ValueItemStack, ValueTypeListProxyPositionedItemNetwork> POSITIONED_ITEM_NETWORK;
public static ValueTypeListProxyNBTFactory<ValueObjectTypeFluidStack, ValueObjectTypeFluidStack.ValueFluidStack, ValueTypeListProxyPositionedFluidNetwork> POSITIONED_FLUID_NETWORK;
public static void load() {
if (POSITIONED_ITEM_NETWORK == null) {
POSITIONED_ITEM_NETWORK = ValueTypeListProxyFactories.REGISTRY.register(new ValueTypeListProxyNBTFactory<>(
|
new ResourceLocation(Reference.MOD_ID, "positioned_item_network"),
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetStorage.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetStorage extends ChanneledTarget<IFluidNetwork, FluidStack> implements IFluidTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<FluidStack, Integer> storage;
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetStorage.java
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetStorage extends ChanneledTarget<IFluidNetwork, FluidStack> implements IFluidTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<FluidStack, Integer> storage;
|
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetStorage.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetStorage extends ChanneledTarget<IFluidNetwork, FluidStack> implements IFluidTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<FluidStack, Integer> storage;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public FluidTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<FluidStack, Integer> storage,
IngredientPredicate<FluidStack, Integer> fluidStackMatcher, PartTarget partTarget,
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetStorage.java
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetStorage extends ChanneledTarget<IFluidNetwork, FluidStack> implements IFluidTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<FluidStack, Integer> storage;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public FluidTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<FluidStack, Integer> storage,
IngredientPredicate<FluidStack, Integer> fluidStackMatcher, PartTarget partTarget,
|
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetStorage.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetStorage extends ChanneledTarget<IFluidNetwork, FluidStack> implements IFluidTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<FluidStack, Integer> storage;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public FluidTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<FluidStack, Integer> storage,
IngredientPredicate<FluidStack, Integer> fluidStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetStorage.java
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetStorage extends ChanneledTarget<IFluidNetwork, FluidStack> implements IFluidTarget {
private final ITunnelConnection connection;
private final IIngredientComponentStorage<FluidStack, Integer> storage;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public FluidTargetStorage(ITunnelTransfer transfer, INetwork network,
IIngredientComponentStorage<FluidStack, Integer> storage,
IngredientPredicate<FluidStack, Integer> fluidStackMatcher, PartTarget partTarget,
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
super(network, network.getCapability(FluidNetworkConfig.CAPABILITY).orElse(null), partState,
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/IChanneledTarget.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStatePositionedAddon.java
// public class PartStatePositionedAddon<P extends IPartTypeWriter, N extends IPositionedAddonsNetwork, T> extends PartStateRoundRobin<P> {
//
// private final boolean canReceive;
// private final boolean canExtract;
// @Nullable
// private N positionedAddonsNetwork;
// @Nullable
// private PositionedAddonsNetworkIngredientsFilter<T> storageFilter;
//
// public PartStatePositionedAddon(int inventorySize, boolean canReceive, boolean canExtract) {
// super(inventorySize);
// this.canReceive = canReceive;
// this.canExtract = canExtract;
// }
//
// @Nullable
// public N getPositionedAddonsNetwork() {
// return positionedAddonsNetwork;
// }
//
// public void setPositionedAddonsNetwork(@Nullable N positionedAddonsNetwork) {
// this.positionedAddonsNetwork = positionedAddonsNetwork;
// }
//
// public boolean canReceive() {
// return canReceive;
// }
//
// public boolean canExtract() {
// return canExtract;
// }
//
// @Nullable
// public PositionedAddonsNetworkIngredientsFilter<T> getStorageFilter() {
// return storageFilter;
// }
//
// public void setStorageFilter(@Nullable PositionedAddonsNetworkIngredientsFilter<T> storageFilter) {
// this.storageFilter = storageFilter;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
|
import org.apache.logging.log4j.Level;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.PartStateException;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* A helper class for movement targets with a certain network type.
* @author rubensworks
*/
public interface IChanneledTarget<N extends IPositionedAddonsNetwork, T> {
public INetwork getNetwork();
public N getChanneledNetwork();
public boolean hasValidTarget();
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStatePositionedAddon.java
// public class PartStatePositionedAddon<P extends IPartTypeWriter, N extends IPositionedAddonsNetwork, T> extends PartStateRoundRobin<P> {
//
// private final boolean canReceive;
// private final boolean canExtract;
// @Nullable
// private N positionedAddonsNetwork;
// @Nullable
// private PositionedAddonsNetworkIngredientsFilter<T> storageFilter;
//
// public PartStatePositionedAddon(int inventorySize, boolean canReceive, boolean canExtract) {
// super(inventorySize);
// this.canReceive = canReceive;
// this.canExtract = canExtract;
// }
//
// @Nullable
// public N getPositionedAddonsNetwork() {
// return positionedAddonsNetwork;
// }
//
// public void setPositionedAddonsNetwork(@Nullable N positionedAddonsNetwork) {
// this.positionedAddonsNetwork = positionedAddonsNetwork;
// }
//
// public boolean canReceive() {
// return canReceive;
// }
//
// public boolean canExtract() {
// return canExtract;
// }
//
// @Nullable
// public PositionedAddonsNetworkIngredientsFilter<T> getStorageFilter() {
// return storageFilter;
// }
//
// public void setStorageFilter(@Nullable PositionedAddonsNetworkIngredientsFilter<T> storageFilter) {
// this.storageFilter = storageFilter;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/IChanneledTarget.java
import org.apache.logging.log4j.Level;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.PartStateException;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* A helper class for movement targets with a certain network type.
* @author rubensworks
*/
public interface IChanneledTarget<N extends IPositionedAddonsNetwork, T> {
public INetwork getNetwork();
public N getChanneledNetwork();
public boolean hasValidTarget();
|
public PartStateRoundRobin<?> getPartState();
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/IChanneledTarget.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStatePositionedAddon.java
// public class PartStatePositionedAddon<P extends IPartTypeWriter, N extends IPositionedAddonsNetwork, T> extends PartStateRoundRobin<P> {
//
// private final boolean canReceive;
// private final boolean canExtract;
// @Nullable
// private N positionedAddonsNetwork;
// @Nullable
// private PositionedAddonsNetworkIngredientsFilter<T> storageFilter;
//
// public PartStatePositionedAddon(int inventorySize, boolean canReceive, boolean canExtract) {
// super(inventorySize);
// this.canReceive = canReceive;
// this.canExtract = canExtract;
// }
//
// @Nullable
// public N getPositionedAddonsNetwork() {
// return positionedAddonsNetwork;
// }
//
// public void setPositionedAddonsNetwork(@Nullable N positionedAddonsNetwork) {
// this.positionedAddonsNetwork = positionedAddonsNetwork;
// }
//
// public boolean canReceive() {
// return canReceive;
// }
//
// public boolean canExtract() {
// return canExtract;
// }
//
// @Nullable
// public PositionedAddonsNetworkIngredientsFilter<T> getStorageFilter() {
// return storageFilter;
// }
//
// public void setStorageFilter(@Nullable PositionedAddonsNetworkIngredientsFilter<T> storageFilter) {
// this.storageFilter = storageFilter;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
|
import org.apache.logging.log4j.Level;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.PartStateException;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* A helper class for movement targets with a certain network type.
* @author rubensworks
*/
public interface IChanneledTarget<N extends IPositionedAddonsNetwork, T> {
public INetwork getNetwork();
public N getChanneledNetwork();
public boolean hasValidTarget();
public PartStateRoundRobin<?> getPartState();
|
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStatePositionedAddon.java
// public class PartStatePositionedAddon<P extends IPartTypeWriter, N extends IPositionedAddonsNetwork, T> extends PartStateRoundRobin<P> {
//
// private final boolean canReceive;
// private final boolean canExtract;
// @Nullable
// private N positionedAddonsNetwork;
// @Nullable
// private PositionedAddonsNetworkIngredientsFilter<T> storageFilter;
//
// public PartStatePositionedAddon(int inventorySize, boolean canReceive, boolean canExtract) {
// super(inventorySize);
// this.canReceive = canReceive;
// this.canExtract = canExtract;
// }
//
// @Nullable
// public N getPositionedAddonsNetwork() {
// return positionedAddonsNetwork;
// }
//
// public void setPositionedAddonsNetwork(@Nullable N positionedAddonsNetwork) {
// this.positionedAddonsNetwork = positionedAddonsNetwork;
// }
//
// public boolean canReceive() {
// return canReceive;
// }
//
// public boolean canExtract() {
// return canExtract;
// }
//
// @Nullable
// public PositionedAddonsNetworkIngredientsFilter<T> getStorageFilter() {
// return storageFilter;
// }
//
// public void setStorageFilter(@Nullable PositionedAddonsNetworkIngredientsFilter<T> storageFilter) {
// this.storageFilter = storageFilter;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/IChanneledTarget.java
import org.apache.logging.log4j.Level;
import org.cyclops.integrateddynamics.IntegratedDynamics;
import org.cyclops.integrateddynamics.api.PartStateException;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.core.helper.NetworkHelpers;
import org.cyclops.integrateddynamics.core.helper.PartHelpers;
import org.cyclops.integratedtunnels.core.part.PartStatePositionedAddon;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* A helper class for movement targets with a certain network type.
* @author rubensworks
*/
public interface IChanneledTarget<N extends IPositionedAddonsNetwork, T> {
public INetwork getNetwork();
public N getChanneledNetwork();
public boolean hasValidTarget();
public PartStateRoundRobin<?> getPartState();
|
public default PartStatePositionedAddon<?, ?, T> getPartStatePositionedAddon() {
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetCapabilityProvider.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IFluidNetwork, FluidStack, Integer>
implements IFluidTarget {
private final ITunnelConnection connection;
private final PartTarget partTarget;
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetCapabilityProvider.java
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IFluidNetwork, FluidStack, Integer>
implements IFluidTarget {
private final ITunnelConnection connection;
private final PartTarget partTarget;
|
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetCapabilityProvider.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IFluidNetwork, FluidStack, Integer>
implements IFluidTarget {
private final ITunnelConnection connection;
private final PartTarget partTarget;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final IAspectProperties properties;
public FluidTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network, @Nullable ICapabilityProvider capabilityProvider,
Direction side, IngredientPredicate<FluidStack, Integer> fluidStackMatcher,
PartTarget partTarget, IAspectProperties properties,
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetCapabilityProvider.java
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IFluidNetwork, FluidStack, Integer>
implements IFluidTarget {
private final ITunnelConnection connection;
private final PartTarget partTarget;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final IAspectProperties properties;
public FluidTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network, @Nullable ICapabilityProvider capabilityProvider,
Direction side, IngredientPredicate<FluidStack, Integer> fluidStackMatcher,
PartTarget partTarget, IAspectProperties properties,
|
@Nullable PartStateRoundRobin<?> partState) {
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetCapabilityProvider.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IFluidNetwork, FluidStack, Integer>
implements IFluidTarget {
private final ITunnelConnection connection;
private final PartTarget partTarget;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final IAspectProperties properties;
public FluidTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network, @Nullable ICapabilityProvider capabilityProvider,
Direction side, IngredientPredicate<FluidStack, Integer> fluidStackMatcher,
PartTarget partTarget, IAspectProperties properties,
@Nullable PartStateRoundRobin<?> partState) {
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/FluidTargetCapabilityProvider.java
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class FluidTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IFluidNetwork, FluidStack, Integer>
implements IFluidTarget {
private final ITunnelConnection connection;
private final PartTarget partTarget;
private final IngredientPredicate<FluidStack, Integer> fluidStackMatcher;
private final IAspectProperties properties;
public FluidTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network, @Nullable ICapabilityProvider capabilityProvider,
Direction side, IngredientPredicate<FluidStack, Integer> fluidStackMatcher,
PartTarget partTarget, IAspectProperties properties,
@Nullable PartStateRoundRobin<?> partState) {
|
super(network, capabilityProvider, side, network.getCapability(FluidNetworkConfig.CAPABILITY).orElse(null), partState,
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/ItemNetwork.java
// public class ItemNetwork extends PositionedAddonsNetworkIngredients<ItemStack, Integer> implements IItemNetwork {
//
// public ItemNetwork(IngredientComponent<ItemStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return 64;
// }
// }
|
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.cyclops.commoncapabilities.CommonCapabilities;
import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityStorage;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.core.network.ItemNetwork;
|
package org.cyclops.integratedtunnels.capability.network;
/**
* Config for the item network capability.
* @author rubensworks
*
*/
public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
@CapabilityInject(IItemNetwork.class)
public static Capability<IItemNetwork> CAPABILITY = null;
public ItemNetworkConfig() {
super(
CommonCapabilities._instance,
"itemNetwork",
IItemNetwork.class,
new DefaultCapabilityStorage<IItemNetwork>(),
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/ItemNetwork.java
// public class ItemNetwork extends PositionedAddonsNetworkIngredients<ItemStack, Integer> implements IItemNetwork {
//
// public ItemNetwork(IngredientComponent<ItemStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return 64;
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.cyclops.commoncapabilities.CommonCapabilities;
import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityStorage;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.core.network.ItemNetwork;
package org.cyclops.integratedtunnels.capability.network;
/**
* Config for the item network capability.
* @author rubensworks
*
*/
public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
@CapabilityInject(IItemNetwork.class)
public static Capability<IItemNetwork> CAPABILITY = null;
public ItemNetworkConfig() {
super(
CommonCapabilities._instance,
"itemNetwork",
IItemNetwork.class,
new DefaultCapabilityStorage<IItemNetwork>(),
|
() -> new ItemNetwork(null)
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/IFluidTarget.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public interface IFluidTarget extends IChanneledTarget<IFluidNetwork, FluidStack> {
public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel();
public IIngredientComponentStorage<FluidStack, Integer> getStorage();
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/IFluidTarget.java
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public interface IFluidTarget extends IChanneledTarget<IFluidNetwork, FluidStack> {
public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel();
public IIngredientComponentStorage<FluidStack, Integer> getStorage();
|
public IngredientPredicate<FluidStack, Integer> getFluidStackMatcher();
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/IFluidTarget.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public interface IFluidTarget extends IChanneledTarget<IFluidNetwork, FluidStack> {
public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel();
public IIngredientComponentStorage<FluidStack, Integer> getStorage();
public IngredientPredicate<FluidStack, Integer> getFluidStackMatcher();
public PartTarget getPartTarget();
public IAspectProperties getProperties();
public ITunnelConnection getConnection();
public static IFluidTarget ofCapabilityProvider(ITunnelTransfer transfer, PartTarget partTarget, IAspectProperties properties,
IngredientPredicate<FluidStack, Integer> fluidStackMatcher) {
PartPos center = partTarget.getCenter();
PartPos target = partTarget.getTarget();
INetwork network = IChanneledTarget.getNetworkChecked(center);
TileEntity tile = target.getPos().getWorld(true).getTileEntity(target.getPos().getBlockPos());
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/IFluidTarget.java
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartPos;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public interface IFluidTarget extends IChanneledTarget<IFluidNetwork, FluidStack> {
public IIngredientComponentStorage<FluidStack, Integer> getFluidChannel();
public IIngredientComponentStorage<FluidStack, Integer> getStorage();
public IngredientPredicate<FluidStack, Integer> getFluidStackMatcher();
public PartTarget getPartTarget();
public IAspectProperties getProperties();
public ITunnelConnection getConnection();
public static IFluidTarget ofCapabilityProvider(ITunnelTransfer transfer, PartTarget partTarget, IAspectProperties properties,
IngredientPredicate<FluidStack, Integer> fluidStackMatcher) {
PartPos center = partTarget.getCenter();
PartPos target = partTarget.getTarget();
INetwork network = IChanneledTarget.getNetworkChecked(center);
TileEntity tile = target.getPos().getWorld(true).getTileEntity(target.getPos().getBlockPos());
|
PartStateRoundRobin<?> partState = IChanneledTarget.getPartState(center);
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/core/world/BlockBreakPlaceRegistry.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/world/IBlockPlaceHandler.java
// public interface IBlockPlaceHandler {
//
// /**
// * If this can handle the given item placement as block.
// * @param itemStack The item.
// * @param world The world.
// * @param pos The position.
// * @param side The side that this item is being placed at.
// * @param hitX The X position that is being targeted.
// * @param hitY The Y position that is being targeted.
// * @param hitZ The Z position that is being targeted.
// * @param player The placing player.
// * @return If this can handle the given item placement as block.
// */
// public boolean shouldApply(ItemStack itemStack, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ, PlayerEntity player);
//
// /**
// * Place the given item as block.
// * @param itemStack The item.
// * @param world The world.
// * @param pos The position.
// * @param side The side that this item is being placed at.
// * @param hitX The X position that is being targeted.
// * @param hitY The Y position that is being targeted.
// * @param hitZ The Z position that is being targeted.
// * @param player The placing player.
// */
// public void placeBlock(ItemStack itemStack, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ, PlayerEntity player);
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/api/world/IBlockPlaceHandlerRegistry.java
// public interface IBlockPlaceHandlerRegistry extends IRegistry {
//
// /**
// * Add an item placement breaking handler.
// * Multiple handlers can exist for an item.
// * @param item An item.
// * @param placeAction A handler.
// * @return The registered handler.
// */
// public IBlockPlaceHandler register(Item item, IBlockPlaceHandler placeAction);
//
// /**
// * @return All registered block breaking handlers.
// */
// public Collection<IBlockPlaceHandler> getHandlers();
//
// /**
// * @param item An item.
// * @return All registered block placement handlers for the given item.
// */
// public Collection<IBlockPlaceHandler> getHandlers(Item item);
//
// /**
// * Get the first possible block breaking handler for the given item.
// * @param itemStack The item.
// * @param world The world.
// * @param pos The position.
// * @param side The side that this item is being placed at.
// * @param hitX The X position that is being targeted.
// * @param hitY The Y position that is being targeted.
// * @param hitZ The Z position that is being targeted.
// * @param player The placing player.
// * @return A block placement handler or null.
// */
// @Nullable
// public IBlockPlaceHandler getHandler(ItemStack itemStack, World world, BlockPos pos, Direction side,
// float hitX, float hitY, float hitZ, PlayerEntity player);
//
// }
|
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.cyclops.integratedtunnels.api.world.IBlockPlaceHandler;
import org.cyclops.integratedtunnels.api.world.IBlockPlaceHandlerRegistry;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
|
package org.cyclops.integratedtunnels.core.world;
/**
* Implementation of {@link IBlockPlaceHandlerRegistry}.
* @author rubensworks
*/
public class BlockBreakPlaceRegistry implements IBlockPlaceHandlerRegistry {
private static BlockBreakPlaceRegistry INSTANCE = new BlockBreakPlaceRegistry();
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/world/IBlockPlaceHandler.java
// public interface IBlockPlaceHandler {
//
// /**
// * If this can handle the given item placement as block.
// * @param itemStack The item.
// * @param world The world.
// * @param pos The position.
// * @param side The side that this item is being placed at.
// * @param hitX The X position that is being targeted.
// * @param hitY The Y position that is being targeted.
// * @param hitZ The Z position that is being targeted.
// * @param player The placing player.
// * @return If this can handle the given item placement as block.
// */
// public boolean shouldApply(ItemStack itemStack, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ, PlayerEntity player);
//
// /**
// * Place the given item as block.
// * @param itemStack The item.
// * @param world The world.
// * @param pos The position.
// * @param side The side that this item is being placed at.
// * @param hitX The X position that is being targeted.
// * @param hitY The Y position that is being targeted.
// * @param hitZ The Z position that is being targeted.
// * @param player The placing player.
// */
// public void placeBlock(ItemStack itemStack, World world, BlockPos pos, Direction side, float hitX, float hitY, float hitZ, PlayerEntity player);
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/api/world/IBlockPlaceHandlerRegistry.java
// public interface IBlockPlaceHandlerRegistry extends IRegistry {
//
// /**
// * Add an item placement breaking handler.
// * Multiple handlers can exist for an item.
// * @param item An item.
// * @param placeAction A handler.
// * @return The registered handler.
// */
// public IBlockPlaceHandler register(Item item, IBlockPlaceHandler placeAction);
//
// /**
// * @return All registered block breaking handlers.
// */
// public Collection<IBlockPlaceHandler> getHandlers();
//
// /**
// * @param item An item.
// * @return All registered block placement handlers for the given item.
// */
// public Collection<IBlockPlaceHandler> getHandlers(Item item);
//
// /**
// * Get the first possible block breaking handler for the given item.
// * @param itemStack The item.
// * @param world The world.
// * @param pos The position.
// * @param side The side that this item is being placed at.
// * @param hitX The X position that is being targeted.
// * @param hitY The Y position that is being targeted.
// * @param hitZ The Z position that is being targeted.
// * @param player The placing player.
// * @return A block placement handler or null.
// */
// @Nullable
// public IBlockPlaceHandler getHandler(ItemStack itemStack, World world, BlockPos pos, Direction side,
// float hitX, float hitY, float hitZ, PlayerEntity player);
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/core/world/BlockBreakPlaceRegistry.java
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.Sets;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.cyclops.integratedtunnels.api.world.IBlockPlaceHandler;
import org.cyclops.integratedtunnels.api.world.IBlockPlaceHandlerRegistry;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
package org.cyclops.integratedtunnels.core.world;
/**
* Implementation of {@link IBlockPlaceHandlerRegistry}.
* @author rubensworks
*/
public class BlockBreakPlaceRegistry implements IBlockPlaceHandlerRegistry {
private static BlockBreakPlaceRegistry INSTANCE = new BlockBreakPlaceRegistry();
|
private final Multimap<Item, IBlockPlaceHandler> handlers = Multimaps.newSetMultimap(Maps.<Item, Collection<IBlockPlaceHandler>>newIdentityHashMap(), Sets::newIdentityHashSet);
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/item/ItemDummyPickAxeConfig.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/IntegratedTunnels.java
// @Mod(Reference.MOD_ID)
// public class IntegratedTunnels extends ModBaseVersionable<IntegratedTunnels> {
//
// /**
// * The unique instance of this mod.
// */
// public static IntegratedTunnels _instance;
//
// public IntegratedTunnels() {
// super(Reference.MOD_ID, (instance) -> _instance = instance);
//
// // Registries
// getRegistryManager().addRegistry(IBlockBreakHandlerRegistry.class, BlockBreakHandlerRegistry.getInstance());
// getRegistryManager().addRegistry(IBlockPlaceHandlerRegistry.class, BlockBreakPlaceRegistry.getInstance());
//
// FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
// }
//
// public void onRegistriesCreate(RegistryEvent.NewRegistry event) {
// TunnelIngredientComponentCapabilities.load();
// TunnelAspects.load();
// PartTypes.load();
// BlockBreakHandlers.load();
// BlockPlaceHandlers.load();
// }
//
// @Override
// protected void setup(FMLCommonSetupEvent event) {
// super.setup(event);
//
// MinecraftForge.EVENT_BUS.register(new TunnelNetworkCapabilityConstructors());
//
// // Initialize info book
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.manual",
// "/data/" + Reference.MOD_ID + "/info/tunnels_info.xml");
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.tutorials",
// "/data/" + Reference.MOD_ID + "/info/tunnels_tutorials.xml");
//
// // Register value list proxies
// TunnelValueTypeListProxyFactories.load();
//
// // Inject aspects into ID parts
// AspectRegistry.getInstance().register(org.cyclops.integrateddynamics.core.part.PartTypes.NETWORK_READER, Lists.newArrayList(
// TunnelAspects.Read.Item.LONG_COUNT,
// TunnelAspects.Read.Item.LONG_COUNTMAX,
// TunnelAspects.Read.Item.LIST_ITEMSTACKS,
// TunnelAspects.Read.Item.OPERATOR_GETITEMCOUNT,
// TunnelAspects.Read.Item.INTEGER_INTERFACES,
//
// TunnelAspects.Read.Fluid.LONG_COUNT,
// TunnelAspects.Read.Fluid.LONG_COUNTMAX,
// TunnelAspects.Read.Fluid.LIST_FLUIDSTACKS,
// TunnelAspects.Read.Fluid.OPERATOR_GETFLUIDCOUNT,
// TunnelAspects.Read.Fluid.INTEGER_INTERFACES
// ));
// }
//
// @Override
// public ItemGroup constructDefaultItemGroup() {
// return new ItemGroupMod(this, () -> RegistryEntries.ITEM_PART_INTERFACE);
// }
//
// @Override
// public void onConfigsRegister(ConfigHandler configHandler) {
// super.onConfigsRegister(configHandler);
//
// configHandler.addConfigurable(new GeneralConfig());
//
// configHandler.addConfigurable(new ItemNetworkConfig());
// configHandler.addConfigurable(new FluidNetworkConfig());
//
// configHandler.addConfigurable(new ItemDummyPickAxeConfig());
//
// configHandler.addConfigurable(new ContainerInterfaceSettingsConfig());
// }
//
// @Override
// @OnlyIn(Dist.CLIENT)
// protected IClientProxy constructClientProxy() {
// return new ClientProxy();
// }
//
// @Override
// protected ICommonProxy constructCommonProxy() {
// return new CommonProxy();
// }
//
// /**
// * Log a new info message for this mod.
// * @param message The message to show.
// */
// public static void clog(String message) {
// clog(Level.INFO, message);
// }
//
// /**
// * Log a new message of the given level for this mod.
// * @param level The level in which the message must be shown.
// * @param message The message to show.
// */
// public static void clog(Level level, String message) {
// IntegratedTunnels._instance.getLoggerHelper().log(level, message);
// }
//
// }
|
import net.minecraft.item.Item;
import org.cyclops.cyclopscore.config.extendedconfig.ItemConfig;
import org.cyclops.integratedtunnels.IntegratedTunnels;
|
package org.cyclops.integratedtunnels.item;
/**
* Config for a dummy pickaxe that can harvest everything.
* @author rubensworks
*/
public class ItemDummyPickAxeConfig extends ItemConfig {
public ItemDummyPickAxeConfig() {
super(
|
// Path: src/main/java/org/cyclops/integratedtunnels/IntegratedTunnels.java
// @Mod(Reference.MOD_ID)
// public class IntegratedTunnels extends ModBaseVersionable<IntegratedTunnels> {
//
// /**
// * The unique instance of this mod.
// */
// public static IntegratedTunnels _instance;
//
// public IntegratedTunnels() {
// super(Reference.MOD_ID, (instance) -> _instance = instance);
//
// // Registries
// getRegistryManager().addRegistry(IBlockBreakHandlerRegistry.class, BlockBreakHandlerRegistry.getInstance());
// getRegistryManager().addRegistry(IBlockPlaceHandlerRegistry.class, BlockBreakPlaceRegistry.getInstance());
//
// FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
// }
//
// public void onRegistriesCreate(RegistryEvent.NewRegistry event) {
// TunnelIngredientComponentCapabilities.load();
// TunnelAspects.load();
// PartTypes.load();
// BlockBreakHandlers.load();
// BlockPlaceHandlers.load();
// }
//
// @Override
// protected void setup(FMLCommonSetupEvent event) {
// super.setup(event);
//
// MinecraftForge.EVENT_BUS.register(new TunnelNetworkCapabilityConstructors());
//
// // Initialize info book
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.manual",
// "/data/" + Reference.MOD_ID + "/info/tunnels_info.xml");
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.tutorials",
// "/data/" + Reference.MOD_ID + "/info/tunnels_tutorials.xml");
//
// // Register value list proxies
// TunnelValueTypeListProxyFactories.load();
//
// // Inject aspects into ID parts
// AspectRegistry.getInstance().register(org.cyclops.integrateddynamics.core.part.PartTypes.NETWORK_READER, Lists.newArrayList(
// TunnelAspects.Read.Item.LONG_COUNT,
// TunnelAspects.Read.Item.LONG_COUNTMAX,
// TunnelAspects.Read.Item.LIST_ITEMSTACKS,
// TunnelAspects.Read.Item.OPERATOR_GETITEMCOUNT,
// TunnelAspects.Read.Item.INTEGER_INTERFACES,
//
// TunnelAspects.Read.Fluid.LONG_COUNT,
// TunnelAspects.Read.Fluid.LONG_COUNTMAX,
// TunnelAspects.Read.Fluid.LIST_FLUIDSTACKS,
// TunnelAspects.Read.Fluid.OPERATOR_GETFLUIDCOUNT,
// TunnelAspects.Read.Fluid.INTEGER_INTERFACES
// ));
// }
//
// @Override
// public ItemGroup constructDefaultItemGroup() {
// return new ItemGroupMod(this, () -> RegistryEntries.ITEM_PART_INTERFACE);
// }
//
// @Override
// public void onConfigsRegister(ConfigHandler configHandler) {
// super.onConfigsRegister(configHandler);
//
// configHandler.addConfigurable(new GeneralConfig());
//
// configHandler.addConfigurable(new ItemNetworkConfig());
// configHandler.addConfigurable(new FluidNetworkConfig());
//
// configHandler.addConfigurable(new ItemDummyPickAxeConfig());
//
// configHandler.addConfigurable(new ContainerInterfaceSettingsConfig());
// }
//
// @Override
// @OnlyIn(Dist.CLIENT)
// protected IClientProxy constructClientProxy() {
// return new ClientProxy();
// }
//
// @Override
// protected ICommonProxy constructCommonProxy() {
// return new CommonProxy();
// }
//
// /**
// * Log a new info message for this mod.
// * @param message The message to show.
// */
// public static void clog(String message) {
// clog(Level.INFO, message);
// }
//
// /**
// * Log a new message of the given level for this mod.
// * @param level The level in which the message must be shown.
// * @param message The message to show.
// */
// public static void clog(Level level, String message) {
// IntegratedTunnels._instance.getLoggerHelper().log(level, message);
// }
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/item/ItemDummyPickAxeConfig.java
import net.minecraft.item.Item;
import org.cyclops.cyclopscore.config.extendedconfig.ItemConfig;
import org.cyclops.integratedtunnels.IntegratedTunnels;
package org.cyclops.integratedtunnels.item;
/**
* Config for a dummy pickaxe that can harvest everything.
* @author rubensworks
*/
public class ItemDummyPickAxeConfig extends ItemConfig {
public ItemDummyPickAxeConfig() {
super(
|
IntegratedTunnels._instance,
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/proxy/ClientProxy.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/IntegratedTunnels.java
// @Mod(Reference.MOD_ID)
// public class IntegratedTunnels extends ModBaseVersionable<IntegratedTunnels> {
//
// /**
// * The unique instance of this mod.
// */
// public static IntegratedTunnels _instance;
//
// public IntegratedTunnels() {
// super(Reference.MOD_ID, (instance) -> _instance = instance);
//
// // Registries
// getRegistryManager().addRegistry(IBlockBreakHandlerRegistry.class, BlockBreakHandlerRegistry.getInstance());
// getRegistryManager().addRegistry(IBlockPlaceHandlerRegistry.class, BlockBreakPlaceRegistry.getInstance());
//
// FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
// }
//
// public void onRegistriesCreate(RegistryEvent.NewRegistry event) {
// TunnelIngredientComponentCapabilities.load();
// TunnelAspects.load();
// PartTypes.load();
// BlockBreakHandlers.load();
// BlockPlaceHandlers.load();
// }
//
// @Override
// protected void setup(FMLCommonSetupEvent event) {
// super.setup(event);
//
// MinecraftForge.EVENT_BUS.register(new TunnelNetworkCapabilityConstructors());
//
// // Initialize info book
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.manual",
// "/data/" + Reference.MOD_ID + "/info/tunnels_info.xml");
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.tutorials",
// "/data/" + Reference.MOD_ID + "/info/tunnels_tutorials.xml");
//
// // Register value list proxies
// TunnelValueTypeListProxyFactories.load();
//
// // Inject aspects into ID parts
// AspectRegistry.getInstance().register(org.cyclops.integrateddynamics.core.part.PartTypes.NETWORK_READER, Lists.newArrayList(
// TunnelAspects.Read.Item.LONG_COUNT,
// TunnelAspects.Read.Item.LONG_COUNTMAX,
// TunnelAspects.Read.Item.LIST_ITEMSTACKS,
// TunnelAspects.Read.Item.OPERATOR_GETITEMCOUNT,
// TunnelAspects.Read.Item.INTEGER_INTERFACES,
//
// TunnelAspects.Read.Fluid.LONG_COUNT,
// TunnelAspects.Read.Fluid.LONG_COUNTMAX,
// TunnelAspects.Read.Fluid.LIST_FLUIDSTACKS,
// TunnelAspects.Read.Fluid.OPERATOR_GETFLUIDCOUNT,
// TunnelAspects.Read.Fluid.INTEGER_INTERFACES
// ));
// }
//
// @Override
// public ItemGroup constructDefaultItemGroup() {
// return new ItemGroupMod(this, () -> RegistryEntries.ITEM_PART_INTERFACE);
// }
//
// @Override
// public void onConfigsRegister(ConfigHandler configHandler) {
// super.onConfigsRegister(configHandler);
//
// configHandler.addConfigurable(new GeneralConfig());
//
// configHandler.addConfigurable(new ItemNetworkConfig());
// configHandler.addConfigurable(new FluidNetworkConfig());
//
// configHandler.addConfigurable(new ItemDummyPickAxeConfig());
//
// configHandler.addConfigurable(new ContainerInterfaceSettingsConfig());
// }
//
// @Override
// @OnlyIn(Dist.CLIENT)
// protected IClientProxy constructClientProxy() {
// return new ClientProxy();
// }
//
// @Override
// protected ICommonProxy constructCommonProxy() {
// return new CommonProxy();
// }
//
// /**
// * Log a new info message for this mod.
// * @param message The message to show.
// */
// public static void clog(String message) {
// clog(Level.INFO, message);
// }
//
// /**
// * Log a new message of the given level for this mod.
// * @param level The level in which the message must be shown.
// * @param message The message to show.
// */
// public static void clog(Level level, String message) {
// IntegratedTunnels._instance.getLoggerHelper().log(level, message);
// }
//
// }
|
import org.cyclops.cyclopscore.init.ModBase;
import org.cyclops.cyclopscore.proxy.ClientProxyComponent;
import org.cyclops.integratedtunnels.IntegratedTunnels;
|
package org.cyclops.integratedtunnels.proxy;
/**
* Proxy for the client side.
*
* @author rubensworks
*
*/
public class ClientProxy extends ClientProxyComponent {
public ClientProxy() {
super(new CommonProxy());
}
@Override
public ModBase getMod() {
|
// Path: src/main/java/org/cyclops/integratedtunnels/IntegratedTunnels.java
// @Mod(Reference.MOD_ID)
// public class IntegratedTunnels extends ModBaseVersionable<IntegratedTunnels> {
//
// /**
// * The unique instance of this mod.
// */
// public static IntegratedTunnels _instance;
//
// public IntegratedTunnels() {
// super(Reference.MOD_ID, (instance) -> _instance = instance);
//
// // Registries
// getRegistryManager().addRegistry(IBlockBreakHandlerRegistry.class, BlockBreakHandlerRegistry.getInstance());
// getRegistryManager().addRegistry(IBlockPlaceHandlerRegistry.class, BlockBreakPlaceRegistry.getInstance());
//
// FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegistriesCreate);
// }
//
// public void onRegistriesCreate(RegistryEvent.NewRegistry event) {
// TunnelIngredientComponentCapabilities.load();
// TunnelAspects.load();
// PartTypes.load();
// BlockBreakHandlers.load();
// BlockPlaceHandlers.load();
// }
//
// @Override
// protected void setup(FMLCommonSetupEvent event) {
// super.setup(event);
//
// MinecraftForge.EVENT_BUS.register(new TunnelNetworkCapabilityConstructors());
//
// // Initialize info book
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.manual",
// "/data/" + Reference.MOD_ID + "/info/tunnels_info.xml");
// IntegratedDynamics._instance.getRegistryManager().getRegistry(IInfoBookRegistry.class)
// .registerSection(
// OnTheDynamicsOfIntegrationBook.getInstance(), "info_book.integrateddynamics.tutorials",
// "/data/" + Reference.MOD_ID + "/info/tunnels_tutorials.xml");
//
// // Register value list proxies
// TunnelValueTypeListProxyFactories.load();
//
// // Inject aspects into ID parts
// AspectRegistry.getInstance().register(org.cyclops.integrateddynamics.core.part.PartTypes.NETWORK_READER, Lists.newArrayList(
// TunnelAspects.Read.Item.LONG_COUNT,
// TunnelAspects.Read.Item.LONG_COUNTMAX,
// TunnelAspects.Read.Item.LIST_ITEMSTACKS,
// TunnelAspects.Read.Item.OPERATOR_GETITEMCOUNT,
// TunnelAspects.Read.Item.INTEGER_INTERFACES,
//
// TunnelAspects.Read.Fluid.LONG_COUNT,
// TunnelAspects.Read.Fluid.LONG_COUNTMAX,
// TunnelAspects.Read.Fluid.LIST_FLUIDSTACKS,
// TunnelAspects.Read.Fluid.OPERATOR_GETFLUIDCOUNT,
// TunnelAspects.Read.Fluid.INTEGER_INTERFACES
// ));
// }
//
// @Override
// public ItemGroup constructDefaultItemGroup() {
// return new ItemGroupMod(this, () -> RegistryEntries.ITEM_PART_INTERFACE);
// }
//
// @Override
// public void onConfigsRegister(ConfigHandler configHandler) {
// super.onConfigsRegister(configHandler);
//
// configHandler.addConfigurable(new GeneralConfig());
//
// configHandler.addConfigurable(new ItemNetworkConfig());
// configHandler.addConfigurable(new FluidNetworkConfig());
//
// configHandler.addConfigurable(new ItemDummyPickAxeConfig());
//
// configHandler.addConfigurable(new ContainerInterfaceSettingsConfig());
// }
//
// @Override
// @OnlyIn(Dist.CLIENT)
// protected IClientProxy constructClientProxy() {
// return new ClientProxy();
// }
//
// @Override
// protected ICommonProxy constructCommonProxy() {
// return new CommonProxy();
// }
//
// /**
// * Log a new info message for this mod.
// * @param message The message to show.
// */
// public static void clog(String message) {
// clog(Level.INFO, message);
// }
//
// /**
// * Log a new message of the given level for this mod.
// * @param level The level in which the message must be shown.
// * @param message The message to show.
// */
// public static void clog(Level level, String message) {
// IntegratedTunnels._instance.getLoggerHelper().log(level, message);
// }
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/proxy/ClientProxy.java
import org.cyclops.cyclopscore.init.ModBase;
import org.cyclops.cyclopscore.proxy.ClientProxyComponent;
import org.cyclops.integratedtunnels.IntegratedTunnels;
package org.cyclops.integratedtunnels.proxy;
/**
* Proxy for the client side.
*
* @author rubensworks
*
*/
public class ClientProxy extends ClientProxyComponent {
public ClientProxy() {
super(new CommonProxy());
}
@Override
public ModBase getMod() {
|
return IntegratedTunnels._instance;
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/FluidNetwork.java
// public class FluidNetwork extends PositionedAddonsNetworkIngredients<FluidStack, Integer> implements IFluidNetwork {
//
// public FluidNetwork(IngredientComponent<FluidStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return GeneralConfig.fluidRateLimit;
// }
// }
|
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.cyclops.commoncapabilities.CommonCapabilities;
import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityStorage;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.network.FluidNetwork;
|
package org.cyclops.integratedtunnels.capability.network;
/**
* Config for the item network capability.
* @author rubensworks
*
*/
public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
@CapabilityInject(IFluidNetwork.class)
public static Capability<IFluidNetwork> CAPABILITY = null;
public FluidNetworkConfig() {
super(
CommonCapabilities._instance,
"fluidNetwork",
IFluidNetwork.class,
new DefaultCapabilityStorage<IFluidNetwork>(),
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IFluidNetwork.java
// public interface IFluidNetwork extends IPositionedAddonsNetworkIngredients<FluidStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/network/FluidNetwork.java
// public class FluidNetwork extends PositionedAddonsNetworkIngredients<FluidStack, Integer> implements IFluidNetwork {
//
// public FluidNetwork(IngredientComponent<FluidStack, Integer> component) {
// super(component);
// }
//
// @Override
// public long getRateLimit() {
// return GeneralConfig.fluidRateLimit;
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import org.cyclops.commoncapabilities.CommonCapabilities;
import org.cyclops.cyclopscore.config.extendedconfig.CapabilityConfig;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityStorage;
import org.cyclops.integratedtunnels.api.network.IFluidNetwork;
import org.cyclops.integratedtunnels.core.network.FluidNetwork;
package org.cyclops.integratedtunnels.capability.network;
/**
* Config for the item network capability.
* @author rubensworks
*
*/
public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
@CapabilityInject(IFluidNetwork.class)
public static Capability<IFluidNetwork> CAPABILITY = null;
public FluidNetworkConfig() {
super(
CommonCapabilities._instance,
"fluidNetwork",
IFluidNetwork.class,
new DefaultCapabilityStorage<IFluidNetwork>(),
|
() -> new FluidNetwork(null)
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/capability/ingredient/TunnelIngredientComponentCapabilities.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
|
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherAdapter;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherManager;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.capability.ingredient.IngredientComponentCapabilities;
import org.cyclops.integrateddynamics.capability.network.PositionedAddonsNetworkIngredientsHandlerConfig;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
|
package org.cyclops.integratedtunnels.capability.ingredient;
/**
* Value handlers for ingredient components.
* @author rubensworks
*/
public class TunnelIngredientComponentCapabilities {
public static void load() {
IngredientComponentCapabilityAttacherManager attacherManager = new IngredientComponentCapabilityAttacherManager();
// Network handler
ResourceLocation networkHandler = new ResourceLocation(Reference.MOD_ID, "network_handler");
attacherManager.addAttacher(new IngredientComponentCapabilityAttacherAdapter<ItemStack, Integer>(IngredientComponentCapabilities.INGREDIENT_ITEMSTACK_NAME, networkHandler) {
@Override
public ICapabilityProvider createCapabilityProvider(IngredientComponent<ItemStack, Integer> ingredientComponent) {
return new DefaultCapabilityProvider<>(() -> PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY,
|
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/capability/ingredient/TunnelIngredientComponentCapabilities.java
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherAdapter;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherManager;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.capability.ingredient.IngredientComponentCapabilities;
import org.cyclops.integrateddynamics.capability.network.PositionedAddonsNetworkIngredientsHandlerConfig;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
package org.cyclops.integratedtunnels.capability.ingredient;
/**
* Value handlers for ingredient components.
* @author rubensworks
*/
public class TunnelIngredientComponentCapabilities {
public static void load() {
IngredientComponentCapabilityAttacherManager attacherManager = new IngredientComponentCapabilityAttacherManager();
// Network handler
ResourceLocation networkHandler = new ResourceLocation(Reference.MOD_ID, "network_handler");
attacherManager.addAttacher(new IngredientComponentCapabilityAttacherAdapter<ItemStack, Integer>(IngredientComponentCapabilities.INGREDIENT_ITEMSTACK_NAME, networkHandler) {
@Override
public ICapabilityProvider createCapabilityProvider(IngredientComponent<ItemStack, Integer> ingredientComponent) {
return new DefaultCapabilityProvider<>(() -> PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY,
|
(network) -> network.getCapability(ItemNetworkConfig.CAPABILITY));
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/capability/ingredient/TunnelIngredientComponentCapabilities.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
|
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherAdapter;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherManager;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.capability.ingredient.IngredientComponentCapabilities;
import org.cyclops.integrateddynamics.capability.network.PositionedAddonsNetworkIngredientsHandlerConfig;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
|
package org.cyclops.integratedtunnels.capability.ingredient;
/**
* Value handlers for ingredient components.
* @author rubensworks
*/
public class TunnelIngredientComponentCapabilities {
public static void load() {
IngredientComponentCapabilityAttacherManager attacherManager = new IngredientComponentCapabilityAttacherManager();
// Network handler
ResourceLocation networkHandler = new ResourceLocation(Reference.MOD_ID, "network_handler");
attacherManager.addAttacher(new IngredientComponentCapabilityAttacherAdapter<ItemStack, Integer>(IngredientComponentCapabilities.INGREDIENT_ITEMSTACK_NAME, networkHandler) {
@Override
public ICapabilityProvider createCapabilityProvider(IngredientComponent<ItemStack, Integer> ingredientComponent) {
return new DefaultCapabilityProvider<>(() -> PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY,
(network) -> network.getCapability(ItemNetworkConfig.CAPABILITY));
}
});
attacherManager.addAttacher(new IngredientComponentCapabilityAttacherAdapter<FluidStack, Integer>(IngredientComponentCapabilities.INGREDIENT_FLUIDSTACK_NAME, networkHandler) {
@Override
public ICapabilityProvider createCapabilityProvider(IngredientComponent<FluidStack, Integer> ingredientComponent) {
return new DefaultCapabilityProvider<>(() -> PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY,
|
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/FluidNetworkConfig.java
// public class FluidNetworkConfig extends CapabilityConfig<IFluidNetwork> {
//
// @CapabilityInject(IFluidNetwork.class)
// public static Capability<IFluidNetwork> CAPABILITY = null;
//
// public FluidNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "fluidNetwork",
// IFluidNetwork.class,
// new DefaultCapabilityStorage<IFluidNetwork>(),
// () -> new FluidNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
// Path: src/main/java/org/cyclops/integratedtunnels/capability/ingredient/TunnelIngredientComponentCapabilities.java
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import net.minecraftforge.fluids.FluidStack;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherAdapter;
import org.cyclops.commoncapabilities.api.ingredient.capability.IngredientComponentCapabilityAttacherManager;
import org.cyclops.cyclopscore.modcompat.capabilities.DefaultCapabilityProvider;
import org.cyclops.integrateddynamics.Reference;
import org.cyclops.integrateddynamics.capability.ingredient.IngredientComponentCapabilities;
import org.cyclops.integrateddynamics.capability.network.PositionedAddonsNetworkIngredientsHandlerConfig;
import org.cyclops.integratedtunnels.capability.network.FluidNetworkConfig;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
package org.cyclops.integratedtunnels.capability.ingredient;
/**
* Value handlers for ingredient components.
* @author rubensworks
*/
public class TunnelIngredientComponentCapabilities {
public static void load() {
IngredientComponentCapabilityAttacherManager attacherManager = new IngredientComponentCapabilityAttacherManager();
// Network handler
ResourceLocation networkHandler = new ResourceLocation(Reference.MOD_ID, "network_handler");
attacherManager.addAttacher(new IngredientComponentCapabilityAttacherAdapter<ItemStack, Integer>(IngredientComponentCapabilities.INGREDIENT_ITEMSTACK_NAME, networkHandler) {
@Override
public ICapabilityProvider createCapabilityProvider(IngredientComponent<ItemStack, Integer> ingredientComponent) {
return new DefaultCapabilityProvider<>(() -> PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY,
(network) -> network.getCapability(ItemNetworkConfig.CAPABILITY));
}
});
attacherManager.addAttacher(new IngredientComponentCapabilityAttacherAdapter<FluidStack, Integer>(IngredientComponentCapabilities.INGREDIENT_FLUIDSTACK_NAME, networkHandler) {
@Override
public ICapabilityProvider createCapabilityProvider(IngredientComponent<FluidStack, Integer> ingredientComponent) {
return new DefaultCapabilityProvider<>(() -> PositionedAddonsNetworkIngredientsHandlerConfig.CAPABILITY,
|
(network) -> network.getCapability(FluidNetworkConfig.CAPABILITY));
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetCapabilityProvider.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IItemNetwork, ItemStack, Integer>
implements IItemTarget {
private final ITunnelConnection connection;
private final int slot;
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetCapabilityProvider.java
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IItemNetwork, ItemStack, Integer>
implements IItemTarget {
private final ITunnelConnection connection;
private final int slot;
|
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
|
CyclopsMC/IntegratedTunnels
|
src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetCapabilityProvider.java
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
|
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
|
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IItemNetwork, ItemStack, Integer>
implements IItemTarget {
private final ITunnelConnection connection;
private final int slot;
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public ItemTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network, @Nullable ICapabilityProvider capabilityProvider,
Direction side, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
|
// Path: src/main/java/org/cyclops/integratedtunnels/api/network/IItemNetwork.java
// public interface IItemNetwork extends IPositionedAddonsNetworkIngredients<ItemStack, Integer> {
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/capability/network/ItemNetworkConfig.java
// public class ItemNetworkConfig extends CapabilityConfig<IItemNetwork> {
//
// @CapabilityInject(IItemNetwork.class)
// public static Capability<IItemNetwork> CAPABILITY = null;
//
// public ItemNetworkConfig() {
// super(
// CommonCapabilities._instance,
// "itemNetwork",
// IItemNetwork.class,
// new DefaultCapabilityStorage<IItemNetwork>(),
// () -> new ItemNetwork(null)
// );
// }
//
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/part/PartStateRoundRobin.java
// public class PartStateRoundRobin<P extends IPartTypeWriter> extends PartStateWriterBase<P> {
//
// private IPartPosIteratorHandler partPosIteratorHandler = null;
//
// public PartStateRoundRobin(int inventorySize) {
// super(inventorySize);
// }
//
// public void setPartPosIteratorHandler(IPartPosIteratorHandler partPosIteratorHandler) {
// this.partPosIteratorHandler = partPosIteratorHandler;
// }
//
// public IPartPosIteratorHandler getPartPosIteratorHandler() {
// return partPosIteratorHandler;
// }
// }
//
// Path: src/main/java/org/cyclops/integratedtunnels/core/predicate/IngredientPredicate.java
// public abstract class IngredientPredicate<T, M> implements Predicate<T>, ITunnelTransfer {
//
// private final IngredientComponent<T, M> ingredientComponent;
// private final T instance;
// private final M matchFlags;
// private final boolean blacklist;
// private final boolean empty;
// private final int maxQuantity;
// private final boolean exactQuantity;
//
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// T instance, M matchFlags, boolean blacklist, boolean empty,
// int maxQuantity, boolean exactQuantity) {
// this.ingredientComponent = ingredientComponent;
// this.instance = instance;
// this.matchFlags = matchFlags;
// this.blacklist = blacklist;
// this.empty = empty;
// this.maxQuantity = maxQuantity;
// this.exactQuantity = exactQuantity;
// }
//
// // Note: implementors of this method *should* override equals and hashcode.
// public IngredientPredicate(IngredientComponent<T, M> ingredientComponent,
// boolean blacklist, boolean empty, int maxQuantity, boolean exactQuantity) {
// this(ingredientComponent, ingredientComponent.getMatcher().getEmptyInstance(), null,
// blacklist, empty, maxQuantity, exactQuantity);
// }
//
// public IngredientComponent<T, M> getIngredientComponent() {
// return ingredientComponent;
// }
//
// @Nonnull
// public T getInstance() {
// return instance;
// }
//
// public M getMatchFlags() {
// return matchFlags;
// }
//
// public boolean hasMatchFlags() {
// return matchFlags != null && !blacklist;
// }
//
// public boolean isBlacklist() {
// return blacklist;
// }
//
// public boolean isEmpty() {
// return empty;
// }
//
// public int getMaxQuantity() {
// return maxQuantity;
// }
//
// public boolean isExactQuantity() {
// return exactQuantity;
// }
//
// @Override
// public boolean equals(Object obj) {
// if (!(obj instanceof IngredientPredicate)) {
// return false;
// }
// IngredientPredicate that = (IngredientPredicate) obj;
// return this.ingredientComponent == that.ingredientComponent
// && this.ingredientComponent.getMatcher().matchesExactly(this.instance, (T) that.instance)
// && Objects.equals(this.matchFlags, that.matchFlags)
// && this.blacklist == that.blacklist
// && this.empty == that.empty
// && this.maxQuantity == that.maxQuantity
// && this.exactQuantity == that.exactQuantity;
// }
//
// @Override
// public int hashCode() {
// return ingredientComponent.hashCode()
// ^ ingredientComponent.getMatcher().hash(instance)
// ^ Objects.hashCode(matchFlags)
// ^ (blacklist ? 1 : 0)
// ^ (empty ? 2 : 4)
// ^ maxQuantity
// ^ (exactQuantity ? 8 : 16);
// }
//
// public static enum EmptyBehaviour {
// ANY,
// NONE;
//
// public static EmptyBehaviour fromBoolean(boolean emptyIsAny) {
// return emptyIsAny ? ANY : NONE;
// }
// }
// }
// Path: src/main/java/org/cyclops/integratedtunnels/part/aspect/ItemTargetCapabilityProvider.java
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.commoncapabilities.api.ingredient.storage.IIngredientComponentStorage;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integrateddynamics.api.part.PartTarget;
import org.cyclops.integrateddynamics.api.part.aspect.property.IAspectProperties;
import org.cyclops.integratedtunnels.api.network.IItemNetwork;
import org.cyclops.integratedtunnels.capability.network.ItemNetworkConfig;
import org.cyclops.integratedtunnels.core.part.PartStateRoundRobin;
import org.cyclops.integratedtunnels.core.predicate.IngredientPredicate;
import javax.annotation.Nullable;
package org.cyclops.integratedtunnels.part.aspect;
/**
* @author rubensworks
*/
public class ItemTargetCapabilityProvider extends ChanneledTargetCapabilityProvider<IItemNetwork, ItemStack, Integer>
implements IItemTarget {
private final ITunnelConnection connection;
private final int slot;
private final IngredientPredicate<ItemStack, Integer> itemStackMatcher;
private final PartTarget partTarget;
private final IAspectProperties properties;
public ItemTargetCapabilityProvider(ITunnelTransfer transfer, INetwork network, @Nullable ICapabilityProvider capabilityProvider,
Direction side, int slot,
IngredientPredicate<ItemStack, Integer> itemStackMatcher, PartTarget partTarget,
|
IAspectProperties properties, @Nullable PartStateRoundRobin<?> partState) {
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.